20 #include <linux/kernel.h>
21 #include <linux/module.h>
24 #include <linux/sched.h>
25 #include <linux/ptrace.h>
26 #include <linux/slab.h>
27 #include <linux/string.h>
32 #include <asm/bitops.h>
34 #include <linux/netdevice.h>
37 #include <linux/if_arp.h>
39 #include <linux/wait.h>
43 #include <linux/ethtool.h>
50 #define DEBUG(n, args...) printk(KERN_DEBUG args);
52 #define DEBUG(n, args...)
58 static const struct firmware *fw_entry;
62 .function = ft1000_hbchk
65 static u16 cmdbuffer[1024];
66 static u8 tempbuffer[1600];
67 static u8 ft1000_card_present = 0;
68 static u8 flarion_ft1000_cnt = 0;
72 static void ft1000_disable_interrupts(
struct net_device *
dev);
77 (
"Support for Flarion Flash OFDM NIC Device. Support for PCMCIA when used with ft1000_cs.");
81 #define MAX_RCV_LOOP 100
128 spin_unlock_irqrestore(&info->
dpram_lock, flags);
146 static inline void ft1000_write_dpram(
struct net_device *
dev,
156 spin_unlock_irqrestore(&info->
dpram_lock, flags);
186 spin_unlock_irqrestore(&info->
dpram_lock, flags);
204 static inline void ft1000_write_dpram_mag_16(
struct net_device *
dev,
218 spin_unlock_irqrestore(&info->
dpram_lock, flags);
243 spin_unlock_irqrestore(&info->
dpram_lock, flags);
270 spin_unlock_irqrestore(&info->
dpram_lock, flags);
283 static void ft1000_enable_interrupts(
struct net_device *dev)
287 DEBUG(1,
"ft1000_hw:ft1000_enable_interrupts()\n");
291 "ft1000_hw:ft1000_enable_interrupts:current interrupt enable mask = 0x%x\n",
305 static void ft1000_disable_interrupts(
struct net_device *dev)
309 DEBUG(1,
"ft1000_hw: ft1000_disable_interrupts()\n");
313 "ft1000_hw:ft1000_disable_interrupts:current interrupt enable mask = 0x%x\n",
328 static void ft1000_reset_asic(
struct net_device *dev)
333 DEBUG(1,
"ft1000_hw:ft1000_reset_asic called\n");
353 DEBUG(1,
"ft1000_hw: interrupt status register = 0x%x\n", tempword);
356 DEBUG(1,
"ft1000_hw: interrupt status register = 0x%x\n", tempword);
371 static int ft1000_reset_card(
struct net_device *dev)
379 DEBUG(1,
"ft1000_hw:ft1000_reset_card called.....\n");
384 ft1000_disable_interrupts(dev);
389 while (list_empty(&info->
prov_list) == 0) {
391 "ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
399 DEBUG(1,
"ft1000_hw:ft1000_reset_card:resetting DSP\n");
403 "ft1000_hw:ft1000_reset_card:resetting ASIC and DSP\n");
409 if (ft1000_card_present == 1) {
427 spin_unlock_irqrestore(&info->
dpram_lock, flags);
430 DEBUG(1,
"ft1000_hw:ft1000_reset_card:resetting ASIC\n");
433 ft1000_reset_asic(dev);
435 DEBUG(1,
"ft1000_hw:ft1000_reset_card:downloading dsp image\n");
440 "ft1000_hw:ft1000_reset_card:Put DSP in reset and take ASIC out of reset\n");
452 DEBUG(0,
"ft1000_hw:ft1000_reset_card:Take DSP out of reset\n");
455 for (i = 0; i < 50; i++) {
459 if (tempword == 0xfefe) {
467 "ft1000_hw:ft1000_reset_card:No FEFE detected from DSP\n");
478 DEBUG(1,
"card download unsuccessful\n");
481 DEBUG(1,
"card download successful\n");
494 DEBUG(1,
"ft1000_hw:ft1000_reset_asic:hi_ho value = 0x%x\n",
503 DEBUG(1,
"ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n",
508 ft1000_enable_interrupts(dev);
531 static int ft1000_chkcard(
struct net_device *dev)
540 "ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
546 if (tempword == 0xffff) {
548 "ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
573 info = netdev_priv(dev);
585 DEBUG(1,
"ft1000_hw:ft1000_hbchk:hi_ho value = 0x%x\n",
588 if (tempword !=
ho) {
596 if (tempword !=
ho) {
598 "ft1000: heartbeat failed - no ho detected\n");
627 if (ft1000_reset_card(dev) == 0) {
629 "ft1000: Hardware Failure Detected - PC Card disabled\n");
645 if (tempword & FT1000_DB_HB) {
647 "ft1000: heartbeat doorbell not clear by firmware\n");
676 if (ft1000_reset_card(dev) == 0) {
678 "ft1000: Hardware Failure Detected - PC Card disabled\n");
706 if (tempword != hi) {
723 if (tempword != hi) {
725 "ft1000: heartbeat failed - cannot write hi into DPRAM\n");
754 if (ft1000_reset_card(dev) == 0) {
756 "ft1000: Hardware Failure Detected - PC Card disabled\n");
793 if ((size & 0x0001)) {
796 DEBUG(1,
"FT1000:ft1000_send_cmd:total length = %d\n", size);
797 DEBUG(1,
"FT1000:ft1000_send_cmd:length = %d\n",
ntohs(*ptempbuffer));
809 spin_unlock_irqrestore(&info->
dpram_lock, flags);
821 for (i = 0; i < (size >> 1); i++) {
822 DEBUG(1,
"FT1000:ft1000_send_cmd:data %d = 0x%x\n", i,
824 tempword =
htons(*ptempbuffer++);
835 for (i = 0; i < (size >> 2); i++) {
836 DEBUG(1,
"FT1000:ft1000_send_cmd:data = 0x%x\n",
840 DEBUG(1,
"FT1000:ft1000_send_cmd:data = 0x%x\n",
845 DEBUG(1,
"FT1000:ft1000_send_cmd:data = 0x%x\n", *ptempbuffer);
847 DEBUG(1,
"FT1000:ft1000_send_cmd:data = 0x%x\n", *ptempbuffer);
850 spin_unlock_irqrestore(&info->
dpram_lock, flags);
869 static bool ft1000_receive_cmd(
struct net_device *dev,
u16 *pbuffer,
870 int maxsz,
u16 *pnxtph)
889 "FT1000:ft1000_receive_cmd:Invalid command length = %d\n",
893 ppseudohdr = (
u16 *) pbuffer;
898 for (i = 0; i <= (size >> 1); i++) {
901 *pbuffer++ =
ntohs(tempword);
907 DEBUG(1,
"ft1000_hw:received data = 0x%x\n", *pbuffer);
911 for (i = 0; i <= (size >> 2); i++) {
923 DEBUG(1,
"ft1000_hw:received data = 0x%x\n", *pbuffer);
926 DEBUG(1,
"ft1000_hw:received data = 0x%x\n", *pbuffer);
932 *pbuffer =
ntohs(tempword);
934 spin_unlock_irqrestore(&info->
dpram_lock, flags);
938 tempword = *ppseudohdr++;
939 for (i = 1; i < 7; i++) {
940 tempword ^= *ppseudohdr++;
942 if ((tempword != *ppseudohdr)) {
944 "FT1000:ft1000_receive_cmd:Pseudo header checksum mismatch\n");
963 static void ft1000_proc_drvmsg(
struct net_device *dev)
988 if ( ft1000_receive_cmd(dev, &cmdbuffer[0],
MAX_CMD_SQSIZE, &tempword) ) {
991 pdrvmsg = (
struct drv_msg *) & cmdbuffer[0];
993 DEBUG(1,
"Command message type = 0x%x\n", msgtype);
997 "Got a provisioning request message from DSP\n");
999 while (list_empty(&info->
prov_list) == 0) {
1000 DEBUG(0,
"Sending a provisioning message\n");
1005 while (tempword & FT1000_DB_DPRAM_TX) {
1025 DEBUG(1,
"checksum = 0x%x\n",
1027 for (i = 1; i < 7; i++) {
1029 DEBUG(1,
"checksum = 0x%x\n",
1043 pmediamsg = (
struct media_msg *) & cmdbuffer[0];
1045 if (pmediamsg->
state) {
1046 DEBUG(1,
"Media is up\n");
1049 netif_wake_queue(dev);
1052 info->
ConTm = tv.tv_sec;
1055 DEBUG(1,
"Media is down\n");
1059 netif_stop_queue(dev);
1065 DEBUG(1,
"Media is down\n");
1069 netif_stop_queue(dev);
1077 DEBUG(1,
"DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n",
1099 DEBUG(1,
"RFCalVer = 0x%2x 0x%2x\n",
1105 DEBUG(1,
"FT1000:drivermsg:Got DSP_STORE_INFO\n");
1109 pmsg = (
u16 *) & pdrvmsg->
data[0];
1110 for (i = 0; i < ((tempword + 1) / 2); i++) {
1112 "FT1000:drivermsg:dsp info data = 0x%x\n",
1119 DEBUG(1,
"FT1000:drivermsg:Got DSP_GET_INFO\n");
1124 if (tempword & FT1000_DB_DPRAM_TX) {
1128 if (tempword & FT1000_DB_DPRAM_TX) {
1133 if ((tempword & FT1000_DB_DPRAM_TX) == 0) {
1140 ppseudo_hdr->
source = 0x10;
1146 ppseudo_hdr->
rsvd1 = 0;
1147 ppseudo_hdr->
rsvd2 = 0;
1155 for (i = 1; i < 7; i++) {
1166 DEBUG(1,
"FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
1171 if (tempword & FT1000_DB_DPRAM_TX) {
1175 if (tempword & FT1000_DB_DPRAM_TX) {
1180 if ((tempword & FT1000_DB_DPRAM_TX) == 0) {
1183 pmsg = (
u16 *) & tempbuffer[0];
1186 ppseudo_hdr->
source = 0x10;
1192 ppseudo_hdr->
rsvd1 = 0;
1193 ppseudo_hdr->
rsvd2 = 0;
1201 for (i=1; i<7; i++) {
1204 pmsg = (
u16 *) & tempbuffer[16];
1206 *pmsg++ =
htons(0x000e);
1219 ft1000_send_cmd (dev, (
u16 *)&tempbuffer[0], (
u16)(0x0012), 0);
1242 static int ft1000_parse_dpram_msg(
struct net_device *dev)
1251 unsigned long flags;
1254 DEBUG(1,
"Doorbell = 0x%x\n", doorbell);
1274 spin_unlock_irqrestore(&info->
dpram_lock, flags);
1278 FT1000_ASIC_RESET_REQ);
1279 DEBUG(1,
"Got an ASIC RESET Request\n");
1292 "FT1000:ft1000_parse_dpram_msg: Got a dsp ASIC reset message\n");
1294 FT1000_DSP_ASIC_RESET);
1301 "FT1000:ft1000_parse_dpram_msg: Got a slow queue message\n");
1312 DEBUG(1,
"FT1000:ft1000_parse_dpram_msg:total length = %d\n",
1331 DEBUG(1,
"DSP_QID = 0x%x\n", portid);
1335 ft1000_proc_drvmsg(dev);
1367 DEBUG(1,
"ft1000_hw:DSP conditional reset requested\n");
1368 ft1000_reset_card(dev);
1370 FT1000_DB_COND_RESET);
1374 doorbell & ~(FT1000_DB_DPRAM_RX | FT1000_ASIC_RESET_REQ |
1375 FT1000_DB_COND_RESET | 0xff00);
1377 DEBUG(1,
"Clearing unexpected doorbell = 0x%x\n", doorbell);
1404 DEBUG(1,
"ft1000:ft1000_hw:ft1000_flush_fifo called\n");
1430 ft1000_reset_card(dev);
1450 if ((i > 2048) || (tempword == 0)) {
1482 if (tempword == 0) {
1488 if (tempword == 0) {
1503 }
while ((tempword & 0x03) != 0x03);
1506 DEBUG(0,
"Flushing FIFO complete = %x\n", tempword);
1511 DEBUG(0,
"Flush Data byte count to dsp = %d\n", i);
1516 DEBUG(0,
"Flushing FIFO complete = %x\n", tempword);
1520 DEBUG(0,
"FT1000_REG_SUP_STAT = 0x%x\n", tempword);
1522 DEBUG(0,
"FT1000_REG_MAG_DFSR = 0x%x\n", tempword);
1543 static int ft1000_copy_up_pkt(
struct net_device *dev)
1556 DEBUG(1,
"ft1000_copy_up_pkt\n");
1563 len =
ntohs(tempword);
1566 DEBUG(1,
"Number of Bytes in FIFO = %d\n", len);
1569 DEBUG(0,
"size of ethernet packet invalid\n");
1575 info->
stats.rx_errors++;
1579 skb = dev_alloc_skb(len + 12 + 2);
1582 DEBUG(0,
"No Network buffers available\n");
1587 ft1000_flush_fifo(dev, 0);
1588 info->
stats.rx_errors++;
1591 pbuffer = (
u8 *)
skb_put(skb, len + 12);
1595 for (i = 1; i < 7; i++) {
1603 DEBUG(1,
"Pseudo = 0x%x\n", tempword);
1607 DEBUG(1,
"Pseudo = 0x%x\n", tempword);
1611 DEBUG(1,
"Pseudo = 0x%x\n", tempword);
1615 DEBUG(1,
"Pseudo = 0x%x\n", tempword);
1619 DEBUG(1,
"Pseudo = 0x%x\n", tempword);
1623 DEBUG(1,
"Pseudo = 0x%x\n", tempword);
1628 DEBUG(1,
"Pseudo = 0x%x\n", tempword);
1631 if (chksum != tempword) {
1632 DEBUG(0,
"Packet checksum mismatch 0x%x 0x%x\n", chksum,
1635 info->
stats.rx_errors++;
1657 for (i = 0; i < len / 2; i++) {
1659 *pbuffer++ = (
u8) (tempword >> 8);
1660 *pbuffer++ = (
u8) tempword;
1661 if (ft1000_chkcard(dev) ==
false) {
1670 *pbuffer++ = (
u8) (tempword >> 8);
1673 ptemplong = (
u32 *) pbuffer;
1674 for (i = 0; i < len / 4; i++) {
1676 DEBUG(1,
"Data = 0x%8x\n", templong);
1677 *ptemplong++ = templong;
1683 DEBUG(1,
"Data = 0x%8x\n", templong);
1684 *ptemplong++ = templong;
1689 DEBUG(1,
"Data passed to Protocol layer:\n");
1690 for (i = 0; i < len + 12; i++) {
1691 DEBUG(1,
"Protocol Data: 0x%x\n ", *ptemp++);
1699 info->
stats.rx_packets++;
1701 info->
stats.rx_bytes += (len + 12);
1705 tempword = len + 16;
1706 if (tempword & 0x01)
1742 DEBUG(1,
"ft1000_hw: copy_down_pkt()\n");
1745 if (len > ft1000_read_fifo_len(dev)) {
1747 if (len > ft1000_read_fifo_len(dev)) {
1750 if (len > ft1000_read_fifo_len(dev)) {
1753 if (len > ft1000_read_fifo_len(dev)) {
1756 if (len > ft1000_read_fifo_len(dev)) {
1759 if (len > ft1000_read_fifo_len(dev)) {
1762 if (len > ft1000_read_fifo_len(dev)) {
1764 "ft1000_hw:ft1000_copy_down_pkt:Transmit FIFO is fulli - pkt drop\n");
1765 info->
stats.tx_errors++;
1771 pseudo.blk.length = len;
1773 pseudo.blk.length =
ntohs(len);
1775 pseudo.blk.source =
DSPID;
1776 pseudo.blk.destination =
HOSTID;
1779 pseudo.blk.sh_str_id = 0;
1780 pseudo.blk.control = 0;
1781 pseudo.blk.rsvd1 = 0;
1782 pseudo.blk.seq_num = 0;
1784 pseudo.blk.qos_class = 0;
1786 pseudo.blk.checksum = pseudo.buff[0];
1787 for (i = 1; i < 7; i++) {
1788 pseudo.blk.checksum ^= pseudo.buff[
i];
1795 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:data 0 BEG = 0x%04x\n",
1800 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:data 1 MID = 0x%04x\n",
1803 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:data 2 MID = 0x%04x\n",
1806 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:data 3 MID = 0x%04x\n",
1809 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:data 4 MID = 0x%04x\n",
1812 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:data 5 MID = 0x%04x\n",
1815 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:data 6 MID = 0x%04x\n",
1818 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:data 7 MID = 0x%04x\n",
1822 for (i = 0; i < (len >> 1) - 1; i++) {
1826 "ft1000_hw:ft1000_copy_down_pkt:data %d MID = 0x%04x\n",
1827 i + 8,
htons(*packet));
1836 "ft1000_hw:ft1000_copy_down_pkt:data MID = 0x%04x\n",
1842 "ft1000_hw:ft1000_copy_down_pkt:data %d MID = 0x%04x\n",
1843 i + 8,
htons(*packet));
1848 "ft1000_hw:ft1000_copy_down_pkt:data %d MID = 0x%04x\n",
1849 i + 8,
htons(*packet));
1852 outl(*(
u32 *) & pseudo.buff[0],
1854 DEBUG(1,
"ft1000_copy_down_pkt: Pseudo = 0x%8x\n",
1855 *(
u32 *) & pseudo.buff[0]);
1856 outl(*(
u32 *) & pseudo.buff[2],
1858 DEBUG(1,
"ft1000_copy_down_pkt: Pseudo = 0x%8x\n",
1859 *(
u32 *) & pseudo.buff[2]);
1860 outl(*(
u32 *) & pseudo.buff[4],
1862 DEBUG(1,
"ft1000_copy_down_pkt: Pseudo = 0x%8x\n",
1863 *(
u32 *) & pseudo.buff[4]);
1864 outl(*(
u32 *) & pseudo.buff[6],
1866 DEBUG(1,
"ft1000_copy_down_pkt: Pseudo = 0x%8x\n",
1867 *(
u32 *) & pseudo.buff[6]);
1869 plong = (
u32 *) packet;
1871 for (i = 0; i < (len >> 2); i++) {
1878 "ft1000_hw:ft1000_copy_down_pkt:data = 0x%8x\n",
1885 info->
stats.tx_packets++;
1887 info->
stats.tx_bytes += (len + 14);
1894 return (&info->
stats);
1897 static int ft1000_open(
struct net_device *dev)
1900 DEBUG(0,
"ft1000_hw: ft1000_open is called\n");
1902 ft1000_reset_card(dev);
1903 DEBUG(0,
"ft1000_hw: ft1000_open is ended\n");
1911 DEBUG(0,
"ft1000_hw: ft1000_open is ended2\n");
1915 static int ft1000_close(
struct net_device *dev)
1919 DEBUG(0,
"ft1000_hw: ft1000_close()\n");
1924 if (ft1000_card_present == 1) {
1925 DEBUG(0,
"Media is down\n");
1926 netif_stop_queue(dev);
1928 ft1000_disable_interrupts(dev);
1932 ft1000_reset_asic(dev);
1942 DEBUG(1,
"ft1000_hw: ft1000_start_xmit()\n");
1944 DEBUG(1,
"ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n");
1948 DEBUG(1,
"ft1000_hw: ft1000_start_xmit:length of packet = %d\n",
1951 pdata = (
u8 *) skb->
data;
1955 DEBUG(1,
"ft1000_hw:ft1000_copy_down_pkt:mediastate is down\n");
1962 "ft1000_hw:ft1000_copy_down_pkt:invalid ethernet length\n");
1981 DEBUG(1,
"ft1000_hw: ft1000_interrupt()\n");
1984 ft1000_disable_interrupts(dev);
1988 if (ft1000_chkcard(dev) ==
false) {
1989 ft1000_disable_interrupts(dev);
1993 ft1000_disable_interrupts(dev);
2001 ft1000_parse_dpram_msg(dev);
2004 DEBUG(1,
"Data in FIFO\n");
2011 ft1000_read_reg(dev,
2015 ft1000_read_reg(dev,
2018 if (tempword & 0x1f) {
2019 ft1000_copy_up_pkt(dev);
2029 DEBUG(1,
"ft1000_hw: interrupt status register = 0x%x\n", tempword);
2034 DEBUG(1,
"ft1000_hw: interrupt status register after clear = 0x%x\n",inttype);
2036 ft1000_enable_interrupts(dev);
2046 DEBUG(0,
"ft1000_hw: stop_ft1000_card()\n");
2049 ft1000_card_present = 0;
2050 netif_stop_queue(dev);
2051 ft1000_disable_interrupts(dev);
2054 while (list_empty(&info->
prov_list) == 0) {
2069 flarion_ft1000_cnt--;
2074 static void ft1000_get_drvinfo(
struct net_device *dev,
2078 ft_info = netdev_priv(dev);
2090 info = netdev_priv(dev);
2095 .get_drvinfo = ft1000_get_drvinfo,
2096 .get_link = ft1000_get_link
2108 .ndo_stop = &ft1000_close,
2109 .ndo_start_xmit = &ft1000_start_xmit,
2110 .ndo_get_stats = &ft1000_stats,
2113 DEBUG(1,
"ft1000_hw: init_ft1000_card()\n");
2114 DEBUG(1,
"ft1000_hw: irq = %d\n", link->irq);
2115 DEBUG(1,
"ft1000_hw: port = 0x%04x\n", link->resource[0]->start);
2117 flarion_ft1000_cnt++;
2119 if (flarion_ft1000_cnt > 1) {
2120 flarion_ft1000_cnt--;
2123 "ft1000: This driver can not support more than one instance\n");
2134 info = netdev_priv(dev);
2138 DEBUG(1,
"address of dev = 0x%8x\n", (
u32) dev);
2139 DEBUG(1,
"address of dev info = 0x%8x\n", (
u32) info);
2140 DEBUG(0,
"device name = %s\n", dev->name);
2145 info->DrvErrNum = 0;
2146 info->registered = 1;
2148 info->ft1000_reset = ft1000_reset;
2149 info->mediastate = 0;
2151 info->CardReady = 0;
2152 info->DSP_TIME[0] = 0;
2153 info->DSP_TIME[1] = 0;
2154 info->DSP_TIME[2] = 0;
2155 info->DSP_TIME[3] = 0;
2156 flarion_ft1000_cnt = 0;
2158 INIT_LIST_HEAD(&info->prov_list);
2160 info->squeseqnum = 0;
2167 dev->netdev_ops = &ft1000ops;
2169 DEBUG(0,
"device name = %s\n", dev->name);
2171 dev->irq = link->irq;
2172 dev->base_addr = link->resource[0]->start;
2173 if (pcmcia_get_mac_from_cis(link, dev)) {
2189 DEBUG(0,
"ft1000: Could not register netdev");
2195 DEBUG(0,
"ft1000_hw: ELECTRABUZZ ASIC\n");
2201 DEBUG(0,
"ft1000_hw: MAGNEMITE ASIC\n");
2208 ft1000_enable_interrupts(dev);
2211 ft1000_card_present = 1;
2214 dev->name, dev->base_addr, dev->irq, dev->dev_addr);