30 #define IOC3_NAME "ioc3-eth"
31 #define IOC3_VERSION "2.6.3-4"
35 #include <linux/kernel.h>
37 #include <linux/errno.h>
38 #include <linux/module.h>
39 #include <linux/pci.h>
41 #include <linux/mii.h>
44 #include <linux/tcp.h>
45 #include <linux/udp.h>
49 #ifdef CONFIG_SERIAL_8250
50 #include <linux/serial_core.h>
55 #include <linux/netdevice.h>
57 #include <linux/ethtool.h>
61 #include <asm/byteorder.h>
63 #include <asm/pgtable.h>
64 #include <asm/uaccess.h>
65 #include <asm/sn/types.h>
66 #include <asm/sn/ioc3.h>
75 #define ETCSR_FD ((17<<ETCSR_IPGR2_SHIFT) | (11<<ETCSR_IPGR1_SHIFT) | 21)
76 #define ETCSR_HD ((21<<ETCSR_IPGR2_SHIFT) | (21<<ETCSR_IPGR1_SHIFT) | 21)
102 return (
void *)dev - ((
sizeof(
struct net_device) + 31) & ~31);
106 static void ioc3_set_multicast_list(
struct net_device *dev);
108 static void ioc3_timeout(
struct net_device *dev);
109 static inline unsigned int ioc3_hash(
const unsigned char *
addr);
111 static void ioc3_init(
struct net_device *dev);
113 static const char ioc3_str[] =
"IOC3 Ethernet";
118 #define IOC3_CACHELINE 128UL
120 static inline unsigned long aligned_rx_skb_addr(
unsigned long addr)
125 static inline struct sk_buff * ioc3_alloc_skb(
unsigned long length,
132 int offset = aligned_rx_skb_addr((
unsigned long) skb->
data);
134 skb_reserve(skb, offset);
140 static inline unsigned long ioc3_map(
void *
ptr,
unsigned long vdev)
142 #ifdef CONFIG_SGI_IP27
155 #define RX_BUF_ALLOC_SIZE (1664 + RX_OFFSET + IOC3_CACHELINE)
159 __asm__("sync" ::: "memory")
162 #define IOC3_SIZE 0x100000
171 #define ioc3_r_mcr() be32_to_cpu(ioc3->mcr)
172 #define ioc3_w_mcr(v) do { ioc3->mcr = cpu_to_be32(v); } while (0)
173 #define ioc3_w_gpcr_s(v) do { ioc3->gpcr_s = cpu_to_be32(v); } while (0)
174 #define ioc3_r_emcr() be32_to_cpu(ioc3->emcr)
175 #define ioc3_w_emcr(v) do { ioc3->emcr = cpu_to_be32(v); } while (0)
176 #define ioc3_r_eisr() be32_to_cpu(ioc3->eisr)
177 #define ioc3_w_eisr(v) do { ioc3->eisr = cpu_to_be32(v); } while (0)
178 #define ioc3_r_eier() be32_to_cpu(ioc3->eier)
179 #define ioc3_w_eier(v) do { ioc3->eier = cpu_to_be32(v); } while (0)
180 #define ioc3_r_ercsr() be32_to_cpu(ioc3->ercsr)
181 #define ioc3_w_ercsr(v) do { ioc3->ercsr = cpu_to_be32(v); } while (0)
182 #define ioc3_r_erbr_h() be32_to_cpu(ioc3->erbr_h)
183 #define ioc3_w_erbr_h(v) do { ioc3->erbr_h = cpu_to_be32(v); } while (0)
184 #define ioc3_r_erbr_l() be32_to_cpu(ioc3->erbr_l)
185 #define ioc3_w_erbr_l(v) do { ioc3->erbr_l = cpu_to_be32(v); } while (0)
186 #define ioc3_r_erbar() be32_to_cpu(ioc3->erbar)
187 #define ioc3_w_erbar(v) do { ioc3->erbar = cpu_to_be32(v); } while (0)
188 #define ioc3_r_ercir() be32_to_cpu(ioc3->ercir)
189 #define ioc3_w_ercir(v) do { ioc3->ercir = cpu_to_be32(v); } while (0)
190 #define ioc3_r_erpir() be32_to_cpu(ioc3->erpir)
191 #define ioc3_w_erpir(v) do { ioc3->erpir = cpu_to_be32(v); } while (0)
192 #define ioc3_r_ertr() be32_to_cpu(ioc3->ertr)
193 #define ioc3_w_ertr(v) do { ioc3->ertr = cpu_to_be32(v); } while (0)
194 #define ioc3_r_etcsr() be32_to_cpu(ioc3->etcsr)
195 #define ioc3_w_etcsr(v) do { ioc3->etcsr = cpu_to_be32(v); } while (0)
196 #define ioc3_r_ersr() be32_to_cpu(ioc3->ersr)
197 #define ioc3_w_ersr(v) do { ioc3->ersr = cpu_to_be32(v); } while (0)
198 #define ioc3_r_etcdc() be32_to_cpu(ioc3->etcdc)
199 #define ioc3_w_etcdc(v) do { ioc3->etcdc = cpu_to_be32(v); } while (0)
200 #define ioc3_r_ebir() be32_to_cpu(ioc3->ebir)
201 #define ioc3_w_ebir(v) do { ioc3->ebir = cpu_to_be32(v); } while (0)
202 #define ioc3_r_etbr_h() be32_to_cpu(ioc3->etbr_h)
203 #define ioc3_w_etbr_h(v) do { ioc3->etbr_h = cpu_to_be32(v); } while (0)
204 #define ioc3_r_etbr_l() be32_to_cpu(ioc3->etbr_l)
205 #define ioc3_w_etbr_l(v) do { ioc3->etbr_l = cpu_to_be32(v); } while (0)
206 #define ioc3_r_etcir() be32_to_cpu(ioc3->etcir)
207 #define ioc3_w_etcir(v) do { ioc3->etcir = cpu_to_be32(v); } while (0)
208 #define ioc3_r_etpir() be32_to_cpu(ioc3->etpir)
209 #define ioc3_w_etpir(v) do { ioc3->etpir = cpu_to_be32(v); } while (0)
210 #define ioc3_r_emar_h() be32_to_cpu(ioc3->emar_h)
211 #define ioc3_w_emar_h(v) do { ioc3->emar_h = cpu_to_be32(v); } while (0)
212 #define ioc3_r_emar_l() be32_to_cpu(ioc3->emar_l)
213 #define ioc3_w_emar_l(v) do { ioc3->emar_l = cpu_to_be32(v); } while (0)
214 #define ioc3_r_ehar_h() be32_to_cpu(ioc3->ehar_h)
215 #define ioc3_w_ehar_h(v) do { ioc3->ehar_h = cpu_to_be32(v); } while (0)
216 #define ioc3_r_ehar_l() be32_to_cpu(ioc3->ehar_l)
217 #define ioc3_w_ehar_l(v) do { ioc3->ehar_l = cpu_to_be32(v); } while (0)
218 #define ioc3_r_micr() be32_to_cpu(ioc3->micr)
219 #define ioc3_w_micr(v) do { ioc3->micr = cpu_to_be32(v); } while (0)
220 #define ioc3_r_midr_r() be32_to_cpu(ioc3->midr_r)
221 #define ioc3_w_midr_r(v) do { ioc3->midr_r = cpu_to_be32(v); } while (0)
222 #define ioc3_r_midr_w() be32_to_cpu(ioc3->midr_w)
223 #define ioc3_w_midr_w(v) do { ioc3->midr_w = cpu_to_be32(v); } while (0)
227 return (pulse << 10) | (sample << 2);
230 static int nic_wait(
struct ioc3 *
ioc3)
236 }
while (!(mcr & 2));
241 static int nic_reset(
struct ioc3 *ioc3)
246 presence = nic_wait(ioc3);
254 static inline int nic_read_bit(
struct ioc3 *ioc3)
259 result = nic_wait(ioc3);
266 static inline void nic_write_bit(
struct ioc3 *ioc3,
int bit)
279 static u32 nic_read_byte(
struct ioc3 *ioc3)
284 for (i = 0; i < 8; i++)
285 result = (result >> 1) | (nic_read_bit(ioc3) << 7);
293 static void nic_write_byte(
struct ioc3 *ioc3,
int byte)
297 for (i = 8;
i; i--) {
301 nic_write_bit(ioc3, bit);
305 static u64 nic_find(
struct ioc3 *ioc3,
int *last)
312 nic_write_byte(ioc3, 0xf0);
315 for (index = 0, disc = 0; index < 64; index++) {
316 a = nic_read_bit(ioc3);
317 b = nic_read_bit(ioc3);
320 printk(
"NIC search failed (not fatal).\n");
326 if (index == *last) {
328 }
else if (index > *last) {
331 }
else if ((address & (1
UL << index)) == 0)
333 nic_write_bit(ioc3, address & (1
UL << index));
340 nic_write_bit(ioc3, a);
350 static int nic_init(
struct ioc3 *ioc3)
352 const char *
unknown =
"unknown";
360 reg = nic_find(ioc3, &save);
362 switch (reg & 0xff) {
377 nic_write_byte(ioc3, 0x55);
378 for (i = 0; i < 8; i++)
379 nic_write_byte(ioc3, (reg >> (i << 3)) & 0xff);
382 for (i = 0; i < 6; i++) {
383 serial[
i] = reg & 0xff;
390 printk(
"Found %s NIC", type);
392 printk (
" registration number %pM, CRC %02x", serial, crc);
404 struct ioc3 *ioc3 = ip->
regs;
418 printk(
"Failed to read MAC address\n");
423 nic_write_byte(ioc3, 0xf0);
424 nic_write_byte(ioc3, 0x00);
425 nic_write_byte(ioc3, 0x00);
427 for (i = 13; i >= 0; i--)
428 nic[i] = nic_read_byte(ioc3);
430 for (i = 2; i < 8; i++)
431 priv_netdev(ip)->dev_addr[i - 2] = nic[
i];
441 ioc3_get_eaddr_nic(ip);
443 printk(
"Ethernet address is %pM.\n", priv_netdev(ip)->dev_addr);
446 static void __ioc3_set_mac_address(
struct net_device *dev)
449 struct ioc3 *ioc3 = ip->
regs;
456 static int ioc3_set_mac_address(
struct net_device *dev,
void *
addr)
464 __ioc3_set_mac_address(dev);
474 static int ioc3_mdio_read(
struct net_device *dev,
int phy,
int reg)
477 struct ioc3 *ioc3 = ip->
regs;
486 static void ioc3_mdio_write(
struct net_device *dev,
int phy,
int reg,
int data)
489 struct ioc3 *ioc3 = ip->
regs;
502 struct ioc3 *ioc3 = ip->
regs;
508 static void ioc3_tcpudp_checksum(
struct sk_buff *skb,
uint32_t hwsum,
int len)
510 struct ethhdr *eh = eth_hdr(skb);
535 if (ip_is_fragment(ih))
544 (ih->
tot_len - (ih->ihl << 2)) +
551 ehsum = ew[0] + ew[1] + ew[2] + ew[3] + ew[4] + ew[5] + ew[6];
553 ehsum = (ehsum & 0xffff) + (ehsum >> 16);
554 ehsum = (ehsum & 0xffff) + (ehsum >> 16);
556 csum += 0xffff ^ ehsum;
560 cp = (
char *)eh + len;
562 csum += 0xffff ^ (
uint16_t) ((cp[1] << 8) | cp[0]);
563 csum += 0xffff ^ (
uint16_t) ((cp[3] << 8) | cp[2]);
565 csum += 0xffff ^ (
uint16_t) ((cp[0] << 8) | cp[1]);
566 csum += 0xffff ^ (
uint16_t) ((cp[2] << 8) | cp[3]);
569 csum = (csum & 0xffff) + (csum >> 16);
570 csum = (csum & 0xffff) + (csum >> 16);
576 static inline void ioc3_rx(
struct net_device *dev)
580 struct ioc3 *ioc3 = ip->
regs;
581 int rx_entry, n_entry, len;
587 rx_entry = ip->
rx_ci;
605 dev->
stats.rx_dropped++;
611 ioc3_tcpudp_checksum(skb,
623 dev->
stats.rx_packets++;
624 dev->
stats.rx_bytes += len;
630 dev->
stats.rx_errors++;
633 dev->
stats.rx_crc_errors++;
635 dev->
stats.rx_frame_errors++;
637 ip->
rx_skbs[n_entry] = new_skb;
640 n_entry = (n_entry + 1) & 511;
643 rx_entry = (rx_entry + 1) & 511;
650 ip->
rx_ci = rx_entry;
653 static inline void ioc3_tx(
struct net_device *dev)
657 struct ioc3 *ioc3 = ip->
regs;
658 int tx_entry, o_entry;
665 tx_entry = (etcir >> 7) & 127;
670 while (o_entry != tx_entry) {
677 o_entry = (o_entry + 1) & 127;
680 tx_entry = (etcir >> 7) & 127;
688 netif_wake_queue(dev);
704 unsigned char *iface = dev->
name;
725 netif_wake_queue(dev);
732 static irqreturn_t ioc3_interrupt(
int irq,
void *_dev)
736 struct ioc3 *ioc3 = ip->
regs;
738 EISR_RXMEMERR | EISR_RXPARERR | EISR_TXBUFUFLO |
747 if (eisr & (EISR_RXOFLO | EISR_RXBUFOFLO | EISR_RXMEMERR |
749 ioc3_error(dev, eisr);
758 static inline void ioc3_setup_duplex(
struct ioc3_private *ip)
760 struct ioc3 *ioc3 = ip->
regs;
762 if (ip->
mii.full_duplex) {
772 static void ioc3_timer(
unsigned long data)
778 ioc3_setup_duplex(ip);
795 int i, found = 0,
res = 0;
796 int ioc3_phy_workaround = 1;
799 for (i = 0; i < 32; i++) {
802 if (word != 0xffff && word != 0x0000) {
809 if (ioc3_phy_workaround)
832 static inline void ioc3_clean_rx_ring(
struct ioc3_private *ip)
837 for (i = ip->
rx_ci; i & 15; i++) {
844 for (i = ip->
rx_ci; i != ip->
rx_pi; i = (i+1) & 511) {
852 static inline void ioc3_clean_tx_ring(
struct ioc3_private *ip)
857 for (i=0; i < 128; i++) {
872 int rx_entry, n_entry;
875 ioc3_clean_tx_ring(ip);
882 rx_entry = ip->
rx_pi;
884 while (n_entry != rx_entry) {
889 n_entry = (n_entry + 1) & 511;
896 static void ioc3_alloc_rings(
struct net_device *dev)
908 printk(
"ioc3_alloc_rings(): get_zeroed_page() failed!\n");
938 printk(
"ioc3_alloc_rings(): __get_free_pages() failed!\n");
944 static void ioc3_init_rings(
struct net_device *dev)
947 struct ioc3 *ioc3 = ip->
regs;
951 ioc3_alloc_rings(dev);
953 ioc3_clean_rx_ring(ip);
954 ioc3_clean_tx_ring(ip);
957 ring = ioc3_map(ip->
rxr, 0);
963 ring = ioc3_map(ip->
txr, 0);
975 static inline void ioc3_ssram_disc(
struct ioc3_private *ip)
977 struct ioc3 *ioc3 = ip->
regs;
978 volatile u32 *ssram0 = &ioc3->
ssram[0x0000];
979 volatile u32 *ssram1 = &ioc3->
ssram[0x4000];
988 if ((*ssram0 & IOC3_SSRAM_DM) != pattern ||
989 (*ssram1 & IOC3_SSRAM_DM) != (~pattern & IOC3_SSRAM_DM)) {
1000 struct ioc3 *ioc3 = ip->
regs;
1011 #ifdef CONFIG_SGI_IP27
1019 __ioc3_set_mac_address(dev);
1024 ioc3_init_rings(dev);
1029 ioc3_w_eier(EISR_RXTIMERINT | EISR_RXOFLO | EISR_RXBUFOFLO |
1030 EISR_RXMEMERR | EISR_RXPARERR | EISR_TXBUFUFLO |
1037 struct ioc3 *ioc3 = ip->
regs;
1059 netif_start_queue(dev);
1063 static int ioc3_close(
struct net_device *dev)
1069 netif_stop_queue(dev);
1074 ioc3_free_rings(ip);
1104 static int ioc3_is_menet(
struct pci_dev *pdev)
1106 return pdev->
bus->parent ==
NULL &&
1107 ioc3_adjacent_is_ioc3(pdev, 0) &&
1108 ioc3_adjacent_is_ioc3(pdev, 1) &&
1109 ioc3_adjacent_is_ioc3(pdev, 2);
1112 #ifdef CONFIG_SERIAL_8250
1148 #define COSMISC_CONSTANT 6
1156 .uartclk = (22000000 << 1) / COSMISC_CONSTANT,
1159 .mapbase = (
unsigned long) uart,
1166 uart->iu_scr = COSMISC_CONSTANT,
1172 static void __devinit ioc3_serial_probe(
struct pci_dev *pdev,
struct ioc3 *ioc3)
1214 ioc3_8250_register(&ioc3->
sregs.uarta);
1215 ioc3_8250_register(&ioc3->
sregs.uartb);
1220 .ndo_open = ioc3_open,
1221 .ndo_stop = ioc3_close,
1222 .ndo_start_xmit = ioc3_start_xmit,
1223 .ndo_tx_timeout = ioc3_timeout,
1224 .ndo_get_stats = ioc3_get_stats,
1225 .ndo_set_rx_mode = ioc3_set_multicast_list,
1226 .ndo_do_ioctl = ioc3_ioctl,
1228 .ndo_set_mac_address = ioc3_set_mac_address,
1235 unsigned int sw_physid1, sw_physid2;
1239 unsigned long ioc3_base, ioc3_size;
1241 int err, pci_using_dac;
1247 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64));
1250 "for consistent allocations\n", pci_name(pdev));
1257 "aborting.\n", pci_name(pdev));
1281 ip = netdev_priv(dev);
1287 ioc3 = (
struct ioc3 *)
ioremap(ioc3_base, ioc3_size);
1296 #ifdef CONFIG_SERIAL_8250
1297 ioc3_serial_probe(pdev, ioc3);
1308 ip->
mii.phy_id_mask = 0x1f;
1309 ip->
mii.reg_num_mask = 0x1f;
1311 ip->
mii.mdio_read = ioc3_mdio_read;
1312 ip->
mii.mdio_write = ioc3_mdio_write;
1316 if (ip->
mii.phy_id == -1) {
1324 ioc3_ssram_disc(ip);
1342 ioc3_setup_duplex(ip);
1344 vendor = (sw_physid1 << 12) | (sw_physid2 >> 4);
1345 model = (sw_physid2 >> 4) & 0x3f;
1346 rev = sw_physid2 & 0xf;
1348 "rev %d.\n", dev->
name, ip->
mii.phy_id, vendor, model, rev);
1357 ioc3_free_rings(ip);
1373 struct net_device *dev = pci_get_drvdata(pdev);
1375 struct ioc3 *ioc3 = ip->
regs;
1397 .id_table = ioc3_pci_tbl,
1398 .probe = ioc3_probe,
1402 static int __init ioc3_init_module(
void)
1404 return pci_register_driver(&ioc3_driver);
1407 static void __exit ioc3_cleanup_module(
void)
1416 struct ioc3 *ioc3 = ip->
regs;
1431 const struct iphdr *ih = ip_hdr(skb);
1442 ehsum = eh[0] + eh[1] + eh[2] + eh[3] + eh[4] + eh[5] + eh[6];
1445 ehsum = (ehsum & 0xffff) + (ehsum >> 16);
1446 ehsum = (ehsum & 0xffff) + (ehsum >> 16);
1452 proto, 0xffff ^ ehsum);
1454 csum = (csum & 0xffff) + (csum >> 16);
1455 csum = (csum & 0xffff) + (csum >> 16);
1460 udp_hdr(skb)->check =
csum;
1464 tcp_hdr(skb)->check =
csum;
1475 produce = ip->
tx_pi;
1476 desc = &ip->
txr[produce];
1480 skb_copy_from_linear_data(skb, desc->
data, skb->
len);
1488 }
else if ((data ^ (data + len - 1)) & 0x4000) {
1489 unsigned long b2 = (data | 0x3fff
UL) + 1
UL;
1490 unsigned long s1 = b2 -
data;
1491 unsigned long s2 = data + len - b2;
1509 produce = (produce + 1) & 127;
1510 ip->
tx_pi = produce;
1516 netif_stop_queue(dev);
1523 static void ioc3_timeout(
struct net_device *dev)
1538 netif_wake_queue(dev);
1546 static inline unsigned int ioc3_hash(
const unsigned char *
addr)
1548 unsigned int temp = 0;
1555 for (bits = 6; --bits >= 0; ) {
1557 temp |= (crc & 0x1);
1564 static void ioc3_get_drvinfo (
struct net_device *dev,
1598 static int ioc3_nway_reset(
struct net_device *dev)
1622 static const struct ethtool_ops ioc3_ethtool_ops = {
1623 .get_drvinfo = ioc3_get_drvinfo,
1624 .get_settings = ioc3_get_settings,
1625 .set_settings = ioc3_set_settings,
1626 .nway_reset = ioc3_nway_reset,
1627 .get_link = ioc3_get_link,
1642 static void ioc3_set_multicast_list(
struct net_device *dev)
1646 struct ioc3 *ioc3 = ip->
regs;
1649 netif_stop_queue(dev);
1669 ehar |= (1
UL << ioc3_hash(ha->
addr));
1672 ip->
ehar_l = ehar & 0xffffffff;
1678 netif_wake_queue(dev);