daynaport.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:25k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* daynaport.c: A Macintosh 8390 based ethernet driver for linux. */
  2. /*
  3. Derived from code:
  4. Written 1993-94 by Donald Becker.
  5. Copyright 1993 United States Government as represented by the
  6. Director, National Security Agency.
  7. This software may be used and distributed according to the terms
  8. of the GNU General Public License, incorporated herein by reference.
  9.     TODO:
  10.     The block output routines may be wrong for non Dayna
  11.     cards
  12. Fix this driver so that it will attempt to use the info
  13. (i.e. iobase, iosize) given to it by the new and improved
  14. NuBus code.
  15. Despite its misleading filename, this driver is not Dayna-specific
  16. anymore. */
  17. /* Cabletron E6100 card support added by Tony Mantler (eek@escape.ca) April 1999 */
  18. static const char *version =
  19. "daynaport.c: v0.02 1999-05-17 Alan Cox (Alan.Cox@linux.org) and othersn";
  20. static int version_printed;
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/kernel.h>
  24. #include <linux/sched.h>
  25. #include <linux/errno.h>
  26. #include <linux/string.h>
  27. #include <linux/nubus.h>
  28. #include <asm/io.h>
  29. #include <asm/system.h>
  30. #include <asm/hwtest.h>
  31. #include <asm/macints.h>
  32. #include <linux/delay.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/etherdevice.h>
  35. #include "8390.h"
  36. static int ns8390_probe1(struct net_device *dev, int word16, char *name, int id,
  37.   int prom, struct nubus_dev *ndev);
  38. static int ns8390_open(struct net_device *dev);
  39. static void ns8390_no_reset(struct net_device *dev);
  40. static int ns8390_close_card(struct net_device *dev);
  41. /* Interlan */
  42. static void interlan_reset(struct net_device *dev);
  43. /* Dayna */
  44. static void dayna_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  45. int ring_page);
  46. static void dayna_block_input(struct net_device *dev, int count,
  47.   struct sk_buff *skb, int ring_offset);
  48. static void dayna_block_output(struct net_device *dev, int count,
  49.    const unsigned char *buf, const int start_page);
  50. /* Sane (32-bit chunk memory read/write) */
  51. static void sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  52. int ring_page);
  53. static void sane_block_input(struct net_device *dev, int count,
  54.   struct sk_buff *skb, int ring_offset);
  55. static void sane_block_output(struct net_device *dev, int count,
  56.    const unsigned char *buf, const int start_page);
  57. /* Slow Sane (16-bit chunk memory read/write) */
  58. static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  59. int ring_page);
  60. static void slow_sane_block_input(struct net_device *dev, int count,
  61.   struct sk_buff *skb, int ring_offset);
  62. static void slow_sane_block_output(struct net_device *dev, int count,
  63.    const unsigned char *buf, const int start_page);
  64. #define WD_START_PG 0x00 /* First page of TX buffer */
  65. #define WD03_STOP_PG 0x20 /* Last page +1 of RX ring */
  66. #define WD13_STOP_PG 0x40 /* Last page +1 of RX ring */
  67. #define CABLETRON_RX_START_PG          0x00    /* First page of RX buffer */
  68. #define CABLETRON_RX_STOP_PG           0x30    /* Last page +1 of RX ring */
  69. #define CABLETRON_TX_START_PG          CABLETRON_RX_STOP_PG  /* First page of TX buffer */
  70. #define DAYNA_MAC_BASE 0xf0007
  71. #define DAYNA_8390_BASE 0x80000 /* 3 */
  72. #define DAYNA_8390_MEM 0x00000
  73. #define DAYNA_MEMSIZE 0x04000 /* First word of each long ! */
  74. #define APPLE_8390_BASE 0xE0000
  75. #define APPLE_8390_MEM 0xD0000
  76. #define APPLE_MEMSIZE 8192    /* FIXME: need to dynamically check */
  77. #define KINETICS_MAC_BASE 0xf0004 /* first byte of each long */
  78. #define KINETICS_8390_BASE 0x80000
  79. #define KINETICS_8390_MEM 0x00000 /* first word of each long */
  80. #define KINETICS_MEMSIZE 8192    /* FIXME: need to dynamically check */
  81. /*#define KINETICS_MEMSIZE (0x10000/2) * CSA: on the board I have, at least */
  82. #define CABLETRON_8390_BASE 0x90000
  83. #define CABLETRON_8390_MEM 0x00000
  84. static int test_8390(volatile char *ptr, int scale)
  85. {
  86. int regd;
  87. int v;
  88. if(hwreg_present(&ptr[0x00])==0)
  89. return -EIO;
  90. if(hwreg_present(&ptr[0x0D<<scale])==0)
  91. return -EIO;
  92. if(hwreg_present(&ptr[0x0D<<scale])==0)
  93. return -EIO;
  94. ptr[0x00]=E8390_NODMA+E8390_PAGE1+E8390_STOP;
  95. regd=ptr[0x0D<<scale];
  96. ptr[0x0D<<scale]=0xFF;
  97. ptr[0x00]=E8390_NODMA+E8390_PAGE0;
  98. v=ptr[0x0D<<scale];
  99. if(ptr[0x0D<<scale]!=0)
  100. {
  101. ptr[0x0D<<scale]=regd;
  102. return -ENODEV;
  103. }
  104. /* printk("NS8390 found at %p scaled %dn", ptr,scale);*/
  105. return 0;
  106. }
  107. /*
  108.  *    Identify the species of NS8390 card/driver we need
  109.  */
  110. enum mac8390_type {
  111. NS8390_DAYNA,
  112. NS8390_INTERLAN,
  113. NS8390_KINETICS,
  114. NS8390_APPLE,
  115. NS8390_FARALLON,
  116. NS8390_ASANTE,
  117. NS8390_CABLETRON
  118. };
  119. static int __init ns8390_ident(struct nubus_dev* ndev)
  120. {
  121. /* This really needs to be tested and tested hard.  */
  122. /* Summary of what we know so far --
  123.  * SW: 0x0104 -- asante,    16 bit, back4_offsets
  124.  * SW: 0x010b -- daynaport, 16 bit, fwrd4_offsets
  125.  * SW: 0x010c -- farallon,  16 bit, back4_offsets, no long word access
  126.  * SW: 0x011a -- focus,     [no details yet]
  127.  * SW: ?????? -- interlan,  16 bit, back4_offsets, funny reset
  128.  * SW: ?????? -- kinetics,   8 bit, back4_offsets
  129.  * -- so i've this hypothesis going that says DrSW&1 says whether the
  130.  *    map is forward or backwards -- and maybe DrSW&256 says what the
  131.  *    register spacing is -- for all cards that report a DrSW in some
  132.  *    range.
  133.  *    This would allow the "apple compatible" driver to drive many
  134.  *    seemingly different types of cards.  More DrSW info is needed
  135.  *    to investigate this properly. [CSA, 21-May-1999]
  136.  */
  137. /* Dayna ex Kinetics board */
  138. if(ndev->dr_sw == NUBUS_DRSW_DAYNA)
  139. return NS8390_DAYNA;
  140. if(ndev->dr_sw == NUBUS_DRSW_ASANTE)
  141. return NS8390_ASANTE;
  142. if(ndev->dr_sw == NUBUS_DRSW_FARALLON) /* farallon or sonic systems */
  143. return NS8390_FARALLON;
  144. if(ndev->dr_sw == NUBUS_DRSW_KINETICS)
  145. return NS8390_KINETICS;
  146. /* My ATI Engineering card with this combination crashes the */
  147. /* driver trying to xmit packets. Best not touch it for now. */
  148. /*     - 1999-05-20 (funaho@jurai.org)                       */
  149. if(ndev->dr_sw == NUBUS_DRSW_FOCUS)
  150. return -1;
  151. /* Check the HW on this one, because it shares the same DrSW as
  152.    the on-board SONIC chips */
  153. if(ndev->dr_hw == NUBUS_DRHW_CABLETRON)
  154. return NS8390_CABLETRON;
  155. /* does anyone have one of these? */
  156. if(ndev->dr_hw == NUBUS_DRHW_INTERLAN)
  157. return NS8390_INTERLAN;
  158. /* FIXME: what do genuine Apple boards look like? */
  159. return -1;
  160. }
  161. /*
  162.  * Memory probe for 8390 cards
  163.  */
  164.  
  165. static int __init apple_8390_mem_probe(volatile unsigned short *p)
  166. {
  167. int i, j;
  168. /*
  169.  * Algorithm.
  170.  * 1. Check each block size of memory doesn't fault
  171.  * 2. Write a value to it
  172.  * 3. Check all previous blocks are unaffected
  173.  */
  174. for(i=0;i<2;i++)
  175. {
  176. volatile unsigned short *m=p+4096*i;
  177. /* Unwriteable - we have a fully decoded card and the
  178.    RAM end located */
  179.    
  180. if(hwreg_present(m)==0)
  181. return 8192*i;
  182. *m=0xA5A0|i;
  183. for(j=0;j<i;j++)
  184. {
  185. /* Partial decode and wrap ? */
  186. if(p[4096*j]!=(0xA5A0|j))
  187. {
  188. /* This is the first misdecode, so it had
  189.    one less page than we tried */
  190. return 8192*i;
  191. }
  192.   j++;
  193.   }
  194.   /* Ok it still decodes.. move on 8K */
  195.   }
  196.   /* 
  197.    * We don't look past 16K. That should cover most cards
  198.    * and above 16K there isnt really any gain.
  199.    */
  200.   return 16384;
  201.  }
  202.  
  203. /*
  204.  *    Probe for 8390 cards.  
  205.  *    The ns8390_probe1() routine initializes the card and fills the
  206.  *    station address field.
  207.  *
  208.  *    The NuBus interface has changed!  We now scan for these somewhat
  209.  *    like how the PCI and Zorro drivers do.  It's not clear whether
  210.  *    this is actually better, but it makes things more consistent.
  211.  *
  212.  *    dev->mem_start points
  213.  *    at the memory ring, dev->mem_end gives the end of it.
  214.  */
  215. int __init mac8390_probe(struct net_device *dev)
  216. {
  217. static int slots;
  218. volatile unsigned short *i;
  219. volatile unsigned char *p;
  220. int plen;
  221. int id;
  222. static struct nubus_dev* ndev;
  223. /* Find the first card that hasn't already been seen */
  224. while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK,
  225.    NUBUS_TYPE_ETHERNET, ndev)) != NULL) {
  226. /* Have we seen it already? */
  227. if (slots & (1<<ndev->board->slot))
  228. continue;
  229. slots |= 1<<ndev->board->slot;
  230. /* Is it one of ours? */
  231. if ((id = ns8390_ident(ndev)) != -1)
  232. break;
  233. }
  234. /* Hm.  No more cards, then */
  235. if (ndev == NULL)
  236. return -ENODEV;
  237. dev = init_etherdev(dev, 0);
  238. if (!dev)
  239. return -ENOMEM;
  240. SET_MODULE_OWNER(dev);
  241. if (!version_printed) {
  242. printk(KERN_INFO "%s", version);
  243. version_printed = 1;
  244. }
  245. /*
  246.  * Dayna specific init
  247.  */
  248. if(id==NS8390_DAYNA)
  249. {
  250. dev->base_addr = (int)(ndev->board->slot_addr+DAYNA_8390_BASE);
  251. dev->mem_start = (int)(ndev->board->slot_addr+DAYNA_8390_MEM);
  252. dev->mem_end = dev->mem_start+DAYNA_MEMSIZE; /* 8K it seems */
  253. printk(KERN_INFO "%s: daynaport. testing board: ", dev->name);
  254. printk("memory - ");
  255. i = (void *)dev->mem_start;
  256. memset((void *)i,0xAA, DAYNA_MEMSIZE);
  257. while(i<(volatile unsigned short *)dev->mem_end)
  258. {
  259. if(*i!=0xAAAA)
  260. goto membad;
  261. *i=0x5678; /* make sure we catch byte smearing */
  262. if(*i!=0x5678)
  263. goto membad;
  264. i+=2; /* Skip a word */
  265. }
  266. printk("controller - ");
  267. p=(void *)dev->base_addr;
  268. plen=0;
  269. while(plen<0x3FF00)
  270. {
  271. if(test_8390(p,0)==0)
  272. break;
  273. if(test_8390(p,1)==0)
  274. break;
  275. if(test_8390(p,2)==0)
  276. break;
  277. if(test_8390(p,3)==0)
  278. break;
  279. plen++;
  280. p++;
  281. }
  282. if(plen==0x3FF00)
  283. goto membad;
  284. printk("OKn");
  285. dev->irq = SLOT2IRQ(ndev->board->slot);
  286. if(ns8390_probe1(dev, 0, "dayna", id, -1, ndev)==0)
  287. return 0;
  288. }
  289. /* Cabletron */
  290. if (id==NS8390_CABLETRON) {
  291. int memsize = 16<<10; /* fix this */
  292.   
  293. dev->base_addr=(int)(ndev->board->slot_addr+CABLETRON_8390_BASE);
  294. dev->mem_start=(int)(ndev->board->slot_addr+CABLETRON_8390_MEM);
  295. dev->mem_end=dev->mem_start+memsize;
  296. dev->irq = SLOT2IRQ(ndev->board->slot);
  297.   
  298. /* The base address is unreadable if 0x00 has been written to the command register */
  299. /* Reset the chip by writing E8390_NODMA+E8390_PAGE0+E8390_STOP just to be sure */
  300. i = (void *)dev->base_addr;
  301. *i = 0x21;
  302.   
  303. printk(KERN_INFO "%s: cabletron: testing board: ", dev->name);
  304. printk("%dK memory - ", memsize>>10);
  305. i=(void *)dev->mem_start;
  306. while(i<(volatile unsigned short *)(dev->mem_start+memsize))
  307. {
  308. *i=0xAAAA;
  309. if(*i!=0xAAAA)
  310. goto membad;
  311. *i=0x5555;
  312. if(*i!=0x5555)
  313. goto membad;
  314. i+=2; /* Skip a word */
  315. }
  316. printk("OKn");
  317.   
  318. if(ns8390_probe1(dev, 1, "cabletron", id, -1, ndev)==0)
  319. return 0;
  320. }
  321. /* Apple, Farallon, Asante */
  322. if(id==NS8390_APPLE || id==NS8390_FARALLON || id==NS8390_ASANTE)
  323. {
  324. int memsize;
  325. dev->base_addr=(int)(ndev->board->slot_addr+APPLE_8390_BASE);
  326. dev->mem_start=(int)(ndev->board->slot_addr+APPLE_8390_MEM);
  327. memsize = apple_8390_mem_probe((void *)dev->mem_start);
  328. dev->mem_end=dev->mem_start+memsize;
  329. dev->irq = SLOT2IRQ(ndev->board->slot);
  330. switch(id)
  331. {
  332. case NS8390_FARALLON:
  333. printk(KERN_INFO "%s: farallon: testing board: ", dev->name);
  334. break;
  335. case NS8390_ASANTE:
  336. printk(KERN_INFO "%s: asante: testing board: ", dev->name);
  337. break;
  338. case NS8390_APPLE:
  339. default:
  340. printk(KERN_INFO "%s: apple/clone: testing board: ", dev->name);
  341. break;
  342. }
  343. printk("%dK memory - ", memsize>>10);
  344. i=(void *)dev->mem_start;
  345. memset((void *)i,0xAA, memsize);
  346. while(i<(volatile unsigned short *)dev->mem_end)
  347. {
  348. if(*i!=0xAAAA)
  349. goto membad;
  350. *i=0x5555;
  351. if(*i!=0x5555)
  352. goto membad;
  353. i+=2; /* Skip a word */
  354. }
  355. printk("OKn");
  356. switch (id)
  357. {
  358. case NS8390_FARALLON:
  359. if(ns8390_probe1(dev, 1, "farallon", id, -1, ndev)==0)
  360. return 0;
  361. break;
  362. case NS8390_ASANTE:
  363. if(ns8390_probe1(dev, 1, "asante", id, -1, ndev)==0)
  364. return 0;
  365. break;
  366. case NS8390_APPLE:
  367. default:
  368. if(ns8390_probe1(dev, 1, "apple/clone", id, -1, ndev)==0)
  369. return 0;
  370. break;
  371. }
  372. }
  373. /* Interlan */
  374. if(id==NS8390_INTERLAN)
  375. {
  376. /* As apple and asante */
  377. dev->base_addr=(int)(ndev->board->slot_addr+APPLE_8390_BASE);
  378. dev->mem_start=(int)(ndev->board->slot_addr+APPLE_8390_MEM);
  379. dev->mem_end=dev->mem_start+APPLE_MEMSIZE; /* 8K it seems */
  380. dev->irq = SLOT2IRQ(ndev->board->slot);
  381. if(ns8390_probe1(dev, 1, "interlan", id, -1, ndev)==0)
  382. return 0;
  383. }
  384. /* Kinetics (Shiva Etherport) */
  385. if(id==NS8390_KINETICS)
  386. {
  387. dev->base_addr=(int)(ndev->board->slot_addr+KINETICS_8390_BASE);
  388. dev->mem_start=(int)(ndev->board->slot_addr+KINETICS_8390_MEM);
  389. dev->mem_end=dev->mem_start+KINETICS_MEMSIZE; /* 8K it seems */
  390. dev->irq = SLOT2IRQ(ndev->board->slot);
  391. if(ns8390_probe1(dev, 0, "kinetics", id, -1, ndev)==0)
  392. return 0;
  393. }
  394. /* We should hopefully not get here */
  395. printk(KERN_ERR "Probe unsuccessful.n");
  396. return -ENODEV;
  397.  membad:
  398. printk(KERN_ERR "failed at %p in %p - %p.n", i,
  399.    (void *)dev->mem_start, (void *)dev->mem_end);
  400. return -ENODEV;
  401. }
  402. static int __init mac8390_ethernet_addr(struct nubus_dev* ndev, unsigned char addr[6])
  403. {
  404. struct nubus_dir dir;
  405. struct nubus_dirent ent;
  406. /* Get the functional resource for this device */
  407. if (nubus_get_func_dir(ndev, &dir) == -1)
  408. return -1;
  409. if (nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent) == -1)
  410. return -1;
  411. nubus_get_rsrc_mem(addr, &ent, 6);
  412. return 0;
  413. }
  414. static int __init ns8390_probe1(struct net_device *dev, int word16, char *model_name,
  415.   int type, int promoff, struct nubus_dev *ndev)
  416. {
  417. static u32 fwrd4_offsets[16]={
  418. 0,      4,      8,      12,
  419. 16,     20,     24,     28,
  420. 32,     36,     40,     44,
  421. 48,     52,     56,     60
  422. };
  423. static u32 back4_offsets[16]={
  424. 60,     56,     52,     48,
  425. 44,     40,     36,     32,
  426. 28,     24,     20,     16,
  427. 12,     8,      4,      0
  428. };
  429. static u32 fwrd2_offsets[16]={
  430. 0,      2,      4,      6,
  431. 8,     10,     12,     14,
  432. 16,    18,     20,     22,
  433. 24,    26,     28,     30
  434. };
  435. unsigned char *prom = (unsigned char*) ndev->board->slot_addr + promoff;
  436. /* Allocate dev->priv and fill in 8390 specific dev fields. */
  437. if (ethdev_init(dev)) 
  438. {
  439. printk ("%s: unable to get memory for dev->priv.n", dev->name);
  440. return -ENOMEM;
  441. }
  442. /* OK, we are certain this is going to work.  Setup the device. */
  443. ei_status.name = model_name;
  444. ei_status.word16 = word16;
  445.        if (type==NS8390_CABLETRON) {
  446.                /* Cabletron card puts the RX buffer before the TX buffer */
  447.                ei_status.tx_start_page = CABLETRON_TX_START_PG;
  448.                ei_status.rx_start_page = CABLETRON_RX_START_PG;
  449.                ei_status.stop_page = CABLETRON_RX_STOP_PG;
  450.                dev->rmem_start = dev->mem_start;
  451.                dev->rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256;
  452.        } else {
  453.                ei_status.tx_start_page = WD_START_PG;
  454.                ei_status.rx_start_page = WD_START_PG + TX_PAGES;
  455.                ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
  456.                dev->rmem_start = dev->mem_start + TX_PAGES*256;
  457.                dev->rmem_end = dev->mem_end;
  458.        }
  459. if(promoff==-1) /* Use nubus resources ? */
  460. {
  461. if(mac8390_ethernet_addr(ndev, dev->dev_addr))
  462. {
  463.   printk("mac_ns8390: MAC address not in resources!n");
  464.   return -ENODEV;
  465. }
  466. }
  467. else /* Pull it off the card */
  468. {
  469. int i=0;
  470. int x=1;
  471. /* These should go in the end I hope */
  472. if(type==NS8390_DAYNA)
  473. x=2;
  474. if(type==NS8390_INTERLAN || type==NS8390_KINETICS)
  475. x=4;
  476. while(i<6)
  477. {
  478. dev->dev_addr[i]=*prom;
  479. prom+=x;
  480. if(i)
  481. printk(":");
  482. printk("%02X",dev->dev_addr[i++]);
  483. }
  484. }
  485. printk(KERN_INFO "%s: %s in slot %X (type %s)n",
  486.    dev->name, ndev->board->name, ndev->board->slot, model_name);
  487. printk(KERN_INFO "MAC ");
  488. {
  489. int i;
  490. for (i = 0; i < 6; i++) {
  491. printk("%2.2x", dev->dev_addr[i]);
  492. if (i < 5)
  493. printk(":");
  494. }
  495. }
  496. printk(" IRQ %d, shared memory at %#lx-%#lx.n",
  497.    dev->irq, dev->mem_start, dev->mem_end-1);
  498. switch(type)
  499. {
  500. case NS8390_DAYNA:      /* Dayna card */
  501. case NS8390_KINETICS:   /* Kinetics --  8 bit config, but 16 bit mem */
  502. /* 16 bit, 4 word offsets */
  503. ei_status.reset_8390 = &ns8390_no_reset;
  504. ei_status.block_input = &dayna_block_input;
  505. ei_status.block_output = &dayna_block_output;
  506. ei_status.get_8390_hdr = &dayna_get_8390_hdr;
  507. ei_status.reg_offset = fwrd4_offsets;
  508. break;
  509. case NS8390_CABLETRON: /* Cabletron */
  510. /* 16 bit card, register map is short forward */
  511. ei_status.reset_8390 = &ns8390_no_reset;
  512. /* Ctron card won't accept 32bit values read or written to it */
  513. ei_status.block_input = &slow_sane_block_input;
  514. ei_status.block_output = &slow_sane_block_output;
  515. ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
  516. ei_status.reg_offset = fwrd2_offsets;
  517. break;
  518. case NS8390_FARALLON:
  519. case NS8390_APPLE: /* Apple/Asante/Farallon */
  520. /*      16 bit card, register map is reversed */
  521. ei_status.reset_8390 = &ns8390_no_reset;
  522. ei_status.block_input = &slow_sane_block_input;
  523. ei_status.block_output = &slow_sane_block_output;
  524. ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
  525. ei_status.reg_offset = back4_offsets;
  526. break;
  527. case NS8390_ASANTE:
  528. /*      16 bit card, register map is reversed */
  529. ei_status.reset_8390 = &ns8390_no_reset;
  530. ei_status.block_input = &sane_block_input;
  531. ei_status.block_output = &sane_block_output;
  532. ei_status.get_8390_hdr = &sane_get_8390_hdr;
  533. ei_status.reg_offset = back4_offsets;
  534. break;
  535. case NS8390_INTERLAN:   /* Interlan */
  536. /*      16 bit card, map is forward */
  537. ei_status.reset_8390 = &interlan_reset;
  538. ei_status.block_input = &sane_block_input;
  539. ei_status.block_output = &sane_block_output;
  540. ei_status.get_8390_hdr = &sane_get_8390_hdr;
  541. ei_status.reg_offset = back4_offsets;
  542. break;
  543. #if 0 /* i think this suffered code rot.  my kinetics card has much
  544.    * different settings.  -- CSA [22-May-1999] */
  545. case NS8390_KINETICS:   /* Kinetics */
  546. /*      8bit card, map is forward */
  547. ei_status.reset_8390 = &ns8390_no_reset;
  548. ei_status.block_input = &sane_block_input;
  549. ei_status.block_output = &sane_block_output;
  550. ei_status.get_8390_hdr = &sane_get_8390_hdr;
  551. ei_status.reg_offset = back4_offsets;
  552. break;
  553. #endif
  554. default:
  555. panic("Detected a card I can't drive - whoopsn");
  556. }
  557. dev->open = &ns8390_open;
  558. dev->stop = &ns8390_close_card;
  559. NS8390_init(dev, 0);
  560. return 0;
  561. }
  562. static int ns8390_open(struct net_device *dev)
  563. {
  564. int ret;
  565. ei_open(dev);
  566. /* At least on my card (a Focus Enhancements PDS card) I start */
  567. /* getting interrupts right away, so the driver needs to be    */
  568. /* completely initialized before enabling the interrupt.        */
  569. /*                             - funaho@jurai.org (1999-05-17) */
  570. /* Non-slow interrupt, works around issues with the SONIC driver */
  571. ret = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev); 
  572. if (ret) {
  573. printk ("%s: unable to get IRQ %d.n", dev->name, dev->irq);
  574. return ret;
  575. }
  576. return 0;
  577. }
  578. static void ns8390_no_reset(struct net_device *dev)
  579. {
  580. if (ei_debug > 1) 
  581. printk("Need to reset the NS8390 t=%lu...", jiffies);
  582. ei_status.txing = 0;
  583. if (ei_debug > 1) printk("reset not supportedn");
  584. }
  585. static int ns8390_close_card(struct net_device *dev)
  586. {
  587. if (ei_debug > 1)
  588. printk("%s: Shutting down ethercard.n", dev->name);
  589. free_irq(dev->irq, dev);
  590. ei_close(dev);
  591. return 0;
  592. }
  593. /*
  594.  *    Interlan Specific Code Starts Here
  595.  */
  596. static void interlan_reset(struct net_device *dev)
  597. {
  598. unsigned char *target=nubus_slot_addr(IRQ2SLOT(dev->irq));
  599. if (ei_debug > 1) 
  600. printk("Need to reset the NS8390 t=%lu...", jiffies);
  601. ei_status.txing = 0;
  602. /* This write resets the card */
  603. target[0xC0000]=0;
  604. if (ei_debug > 1) printk("reset completen");
  605. return;
  606. }
  607. /*
  608.  *    Daynaport code (some is used by other drivers)
  609.  */
  610. /* Grab the 8390 specific header. Similar to the block_input routine, but
  611.    we don't need to be concerned with ring wrap as the header will be at
  612.    the start of a page, so we optimize accordingly. */
  613. /* Block input and output are easy on shared memory ethercards, and trivial
  614.    on the Daynaport card where there is no choice of how to do it.
  615.    The only complications are that the ring buffer wraps.
  616. */
  617. static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count)
  618. {
  619. volatile unsigned short *ptr;
  620. unsigned short *target=to;
  621. from<<=1; /* word, skip overhead */
  622. ptr=(unsigned short *)(dev->mem_start+from);
  623. /*
  624.  * Leading byte?
  625.  */
  626. if (from&2) {
  627. *((char *)target)++ = *(((char *)ptr++)-1);
  628. count--;
  629. }
  630. while(count>=2)
  631. {
  632. *target++=*ptr++; /* Copy and */
  633. ptr++; /* skip cruft */
  634. count-=2;
  635. }
  636. /*
  637.  * Trailing byte ?
  638.  */
  639. if(count)
  640. {
  641. /* Big endian */
  642. unsigned short v=*ptr;
  643. *((char *)target)=v>>8;
  644. }
  645. }
  646. static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count)
  647. {
  648. volatile unsigned short *ptr;
  649. const unsigned short *src=from;
  650. to<<=1; /* word, skip overhead */
  651. ptr=(unsigned short *)(dev->mem_start+to);
  652. /*
  653.  * Leading byte?
  654.  */
  655. if (to&2) { /* avoid a byte write (stomps on other data) */
  656. ptr[-1] = (ptr[-1]&0xFF00)|*((unsigned char *)src)++;
  657. ptr++;
  658. count--;
  659. }
  660. while(count>=2)
  661. {
  662. *ptr++=*src++; /* Copy and */
  663. ptr++; /* skip cruft */
  664. count-=2;
  665. }
  666. /*
  667.  * Trailing byte ?
  668.  */
  669. if(count)
  670. {
  671. /* Big endian */
  672. unsigned short v=*src;
  673. /* card doesn't like byte writes */
  674. *ptr=(*ptr&0x00FF)|(v&0xFF00);
  675. }
  676. }
  677. static void dayna_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  678. {
  679. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  680. dayna_memcpy_fromcard(dev, (void *)hdr, hdr_start, 4);
  681. /* Register endianism - fix here rather than 8390.c */
  682. hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
  683. }
  684. static void dayna_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  685. {
  686. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  687. unsigned long xfer_start = xfer_base+dev->mem_start;
  688. /*
  689.  * Note the offset maths is done in card memory space which
  690.  * is word per long onto our space.
  691.  */
  692.  
  693. if (xfer_start + count > dev->rmem_end) 
  694. {
  695. /* We must wrap the input move. */
  696. int semi_count = dev->rmem_end - xfer_start;
  697. dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count);
  698. count -= semi_count;
  699. dayna_memcpy_fromcard(dev, skb->data + semi_count, 
  700. dev->rmem_start - dev->mem_start, count);
  701. }
  702. else
  703. {
  704. dayna_memcpy_fromcard(dev, skb->data, xfer_base, count);
  705. }
  706. }
  707. static void dayna_block_output(struct net_device *dev, int count, const unsigned char *buf,
  708. int start_page)
  709. {
  710. long shmem = (start_page - WD_START_PG)<<8;
  711. dayna_memcpy_tocard(dev, shmem, buf, count);
  712. }
  713. /*
  714.  * Cards with full width memory
  715.  */
  716. static void sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  717. {
  718. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  719. memcpy((void *)hdr, (char *)dev->mem_start+hdr_start, 4);
  720. /* Register endianism - fix here rather than 8390.c */
  721. hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
  722. }
  723. static void sane_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  724. {
  725. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  726. unsigned long xfer_start = xfer_base+dev->mem_start;
  727. if (xfer_start + count > dev->rmem_end) 
  728. {
  729. /* We must wrap the input move. */
  730. int semi_count = dev->rmem_end - xfer_start;
  731. memcpy(skb->data, (char *)dev->mem_start+xfer_base, semi_count);
  732. count -= semi_count;
  733. memcpy(skb->data + semi_count, 
  734. (char *)dev->rmem_start, count);
  735. }
  736. else
  737. {
  738. memcpy(skb->data, (char *)dev->mem_start+xfer_base, count);
  739. }
  740. }
  741. static void sane_block_output(struct net_device *dev, int count, const unsigned char *buf,
  742. int start_page)
  743. {
  744. long shmem = (start_page - WD_START_PG)<<8;
  745. memcpy((char *)dev->mem_start+shmem, buf, count);
  746. }
  747. static void word_memcpy_tocard(void *tp, const void *fp, int count)
  748. {
  749. volatile unsigned short *to = tp;
  750. const unsigned short *from = fp;
  751. count++;
  752. count/=2;
  753. while(count--)
  754. *to++=*from++;
  755. }
  756. static void word_memcpy_fromcard(void *tp, const void *fp, int count)
  757. {
  758. unsigned short *to = tp;
  759. const volatile unsigned short *from = fp;
  760. count++;
  761. count/=2;
  762. while(count--)
  763. *to++=*from++;
  764. }
  765. static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  766. {
  767. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  768. word_memcpy_fromcard((void *)hdr, (char *)dev->mem_start+hdr_start, 4);
  769. /* Register endianism - fix here rather than 8390.c */
  770. hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
  771. }
  772. static void slow_sane_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  773. {
  774. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  775. unsigned long xfer_start = xfer_base+dev->mem_start;
  776. if (xfer_start + count > dev->rmem_end) 
  777. {
  778. /* We must wrap the input move. */
  779. int semi_count = dev->rmem_end - xfer_start;
  780. word_memcpy_fromcard(skb->data, (char *)dev->mem_start+xfer_base, semi_count);
  781. count -= semi_count;
  782. word_memcpy_fromcard(skb->data + semi_count, 
  783. (char *)dev->rmem_start, count);
  784. }
  785. else
  786. {
  787. word_memcpy_fromcard(skb->data, (char *)dev->mem_start+xfer_base, count);
  788. }
  789. }
  790. static void slow_sane_block_output(struct net_device *dev, int count, const unsigned char *buf,
  791. int start_page)
  792. {
  793. long shmem = (start_page - WD_START_PG)<<8;
  794. word_memcpy_tocard((char *)dev->mem_start+shmem, buf, count);
  795. #if 0
  796. long shmem = (start_page - WD_START_PG)<<8;
  797. volatile unsigned short *to=(unsigned short *)(dev->mem_start+shmem);
  798. volatile int p;
  799. unsigned short *bp=(unsigned short *)buf;
  800. count=(count+1)/2;
  801. while(count--)
  802. {
  803. *to++=*bp++;
  804. for(p=0;p<10;p++)
  805. p++;
  806. }
  807. #endif
  808. }
  809. MODULE_LICENSE("GPL");