mac8390.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  1. /* mac8390.c: New driver for 8390-based Nubus (or Nubus-alike)
  2. Ethernet cards on Linux */
  3. /* Based on the former daynaport.c driver, by Alan Cox. Some code
  4. taken from or inspired by skeleton.c by Donald Becker, acenic.c by
  5. Jes Sorensen, and ne2k-pci.c by Donald Becker and Paul Gortmaker.
  6. This software may be used and distributed according to the terms of
  7. the GNU Public License, incorporated herein by reference. */
  8. /* 2000-02-28: support added for Dayna and Kinetics cards by
  9. A.G.deWijn@phys.uu.nl */
  10. /* 2000-04-04: support added for Dayna2 by bart@etpmod.phys.tue.nl */
  11. /* 2001-04-18: support for DaynaPort E/LC-M by rayk@knightsmanor.org */
  12. /* 2001-05-15: support for Cabletron ported from old daynaport driver
  13. * and fixed access to Sonic Sys card which masquerades as a Farallon
  14. * by rayk@knightsmanor.org */
  15. /* 2002-12-30: Try to support more cards, some clues from NetBSD driver */
  16. /* 2003-12-26: Make sure Asante cards always work. */
  17. #include <linux/module.h>
  18. #include <linux/kernel.h>
  19. #include <linux/types.h>
  20. #include <linux/fcntl.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/ptrace.h>
  23. #include <linux/ioport.h>
  24. #include <linux/nubus.h>
  25. #include <linux/in.h>
  26. #include <linux/slab.h>
  27. #include <linux/string.h>
  28. #include <linux/errno.h>
  29. #include <linux/init.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/etherdevice.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/bitops.h>
  34. #include <asm/system.h>
  35. #include <asm/io.h>
  36. #include <asm/dma.h>
  37. #include <asm/hwtest.h>
  38. #include <asm/macints.h>
  39. static char version[] =
  40. "mac8390.c: v0.4 2001-05-15 David Huggins-Daines <dhd@debian.org> and others\n";
  41. #define EI_SHIFT(x) (ei_local->reg_offset[x])
  42. #define ei_inb(port) in_8(port)
  43. #define ei_outb(val,port) out_8(port,val)
  44. #define ei_inb_p(port) in_8(port)
  45. #define ei_outb_p(val,port) out_8(port,val)
  46. #include "lib8390.c"
  47. #define WD_START_PG 0x00 /* First page of TX buffer */
  48. #define CABLETRON_RX_START_PG 0x00 /* First page of RX buffer */
  49. #define CABLETRON_RX_STOP_PG 0x30 /* Last page +1 of RX ring */
  50. #define CABLETRON_TX_START_PG CABLETRON_RX_STOP_PG /* First page of TX buffer */
  51. /* Unfortunately it seems we have to hardcode these for the moment */
  52. /* Shouldn't the card know about this? Does anyone know where to read it off the card? Do we trust the data provided by the card? */
  53. #define DAYNA_8390_BASE 0x80000
  54. #define DAYNA_8390_MEM 0x00000
  55. #define CABLETRON_8390_BASE 0x90000
  56. #define CABLETRON_8390_MEM 0x00000
  57. #define INTERLAN_8390_BASE 0xE0000
  58. #define INTERLAN_8390_MEM 0xD0000
  59. enum mac8390_type {
  60. MAC8390_NONE = -1,
  61. MAC8390_APPLE,
  62. MAC8390_ASANTE,
  63. MAC8390_FARALLON,
  64. MAC8390_CABLETRON,
  65. MAC8390_DAYNA,
  66. MAC8390_INTERLAN,
  67. MAC8390_KINETICS,
  68. };
  69. static const char * cardname[] = {
  70. "apple",
  71. "asante",
  72. "farallon",
  73. "cabletron",
  74. "dayna",
  75. "interlan",
  76. "kinetics",
  77. };
  78. static int word16[] = {
  79. 1, /* apple */
  80. 1, /* asante */
  81. 1, /* farallon */
  82. 1, /* cabletron */
  83. 0, /* dayna */
  84. 1, /* interlan */
  85. 0, /* kinetics */
  86. };
  87. /* on which cards do we use NuBus resources? */
  88. static int useresources[] = {
  89. 1, /* apple */
  90. 1, /* asante */
  91. 1, /* farallon */
  92. 0, /* cabletron */
  93. 0, /* dayna */
  94. 0, /* interlan */
  95. 0, /* kinetics */
  96. };
  97. enum mac8390_access {
  98. ACCESS_UNKNOWN = 0,
  99. ACCESS_32,
  100. ACCESS_16,
  101. };
  102. extern enum mac8390_type mac8390_ident(struct nubus_dev * dev);
  103. extern int mac8390_memsize(unsigned long membase);
  104. extern int mac8390_memtest(struct net_device * dev);
  105. static int mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
  106. enum mac8390_type type);
  107. static int mac8390_open(struct net_device * dev);
  108. static int mac8390_close(struct net_device * dev);
  109. static void mac8390_no_reset(struct net_device *dev);
  110. static void interlan_reset(struct net_device *dev);
  111. /* Sane (32-bit chunk memory read/write) - Some Farallon and Apple do this*/
  112. static void sane_get_8390_hdr(struct net_device *dev,
  113. struct e8390_pkt_hdr *hdr, int ring_page);
  114. static void sane_block_input(struct net_device * dev, int count,
  115. struct sk_buff * skb, int ring_offset);
  116. static void sane_block_output(struct net_device * dev, int count,
  117. const unsigned char * buf, const int start_page);
  118. /* dayna_memcpy to and from card */
  119. static void dayna_memcpy_fromcard(struct net_device *dev, void *to,
  120. int from, int count);
  121. static void dayna_memcpy_tocard(struct net_device *dev, int to,
  122. const void *from, int count);
  123. /* Dayna - Dayna/Kinetics use this */
  124. static void dayna_get_8390_hdr(struct net_device *dev,
  125. struct e8390_pkt_hdr *hdr, int ring_page);
  126. static void dayna_block_input(struct net_device *dev, int count,
  127. struct sk_buff *skb, int ring_offset);
  128. static void dayna_block_output(struct net_device *dev, int count,
  129. const unsigned char *buf, int start_page);
  130. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  131. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  132. /* Slow Sane (16-bit chunk memory read/write) Cabletron uses this */
  133. static void slow_sane_get_8390_hdr(struct net_device *dev,
  134. struct e8390_pkt_hdr *hdr, int ring_page);
  135. static void slow_sane_block_input(struct net_device *dev, int count,
  136. struct sk_buff *skb, int ring_offset);
  137. static void slow_sane_block_output(struct net_device *dev, int count,
  138. const unsigned char *buf, int start_page);
  139. static void word_memcpy_tocard(void *tp, const void *fp, int count);
  140. static void word_memcpy_fromcard(void *tp, const void *fp, int count);
  141. enum mac8390_type __init mac8390_ident(struct nubus_dev * dev)
  142. {
  143. switch (dev->dr_sw) {
  144. case NUBUS_DRSW_3COM:
  145. switch (dev->dr_hw) {
  146. case NUBUS_DRHW_APPLE_SONIC_NB:
  147. case NUBUS_DRHW_APPLE_SONIC_LC:
  148. case NUBUS_DRHW_SONNET:
  149. return MAC8390_NONE;
  150. break;
  151. default:
  152. return MAC8390_APPLE;
  153. break;
  154. }
  155. break;
  156. case NUBUS_DRSW_APPLE:
  157. switch (dev->dr_hw) {
  158. case NUBUS_DRHW_ASANTE_LC:
  159. return MAC8390_NONE;
  160. break;
  161. case NUBUS_DRHW_CABLETRON:
  162. return MAC8390_CABLETRON;
  163. break;
  164. default:
  165. return MAC8390_APPLE;
  166. break;
  167. }
  168. break;
  169. case NUBUS_DRSW_ASANTE:
  170. return MAC8390_ASANTE;
  171. break;
  172. case NUBUS_DRSW_TECHWORKS:
  173. case NUBUS_DRSW_DAYNA2:
  174. case NUBUS_DRSW_DAYNA_LC:
  175. if (dev->dr_hw == NUBUS_DRHW_CABLETRON)
  176. return MAC8390_CABLETRON;
  177. else
  178. return MAC8390_APPLE;
  179. break;
  180. case NUBUS_DRSW_FARALLON:
  181. return MAC8390_FARALLON;
  182. break;
  183. case NUBUS_DRSW_KINETICS:
  184. switch (dev->dr_hw) {
  185. case NUBUS_DRHW_INTERLAN:
  186. return MAC8390_INTERLAN;
  187. break;
  188. default:
  189. return MAC8390_KINETICS;
  190. break;
  191. }
  192. break;
  193. case NUBUS_DRSW_DAYNA:
  194. // These correspond to Dayna Sonic cards
  195. // which use the macsonic driver
  196. if (dev->dr_hw == NUBUS_DRHW_SMC9194 ||
  197. dev->dr_hw == NUBUS_DRHW_INTERLAN )
  198. return MAC8390_NONE;
  199. else
  200. return MAC8390_DAYNA;
  201. break;
  202. }
  203. return MAC8390_NONE;
  204. }
  205. enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
  206. {
  207. unsigned long outdata = 0xA5A0B5B0;
  208. unsigned long indata = 0x00000000;
  209. /* Try writing 32 bits */
  210. memcpy((char *)membase, (char *)&outdata, 4);
  211. /* Now compare them */
  212. if (memcmp((char *)&outdata, (char *)membase, 4) == 0)
  213. return ACCESS_32;
  214. /* Write 16 bit output */
  215. word_memcpy_tocard((char *)membase, (char *)&outdata, 4);
  216. /* Now read it back */
  217. word_memcpy_fromcard((char *)&indata, (char *)membase, 4);
  218. if (outdata == indata)
  219. return ACCESS_16;
  220. return ACCESS_UNKNOWN;
  221. }
  222. int __init mac8390_memsize(unsigned long membase)
  223. {
  224. unsigned long flags;
  225. int i, j;
  226. local_irq_save(flags);
  227. /* Check up to 32K in 4K increments */
  228. for (i = 0; i < 8; i++) {
  229. volatile unsigned short *m = (unsigned short *) (membase + (i * 0x1000));
  230. /* Unwriteable - we have a fully decoded card and the
  231. RAM end located */
  232. if (hwreg_present(m) == 0)
  233. break;
  234. /* write a distinctive byte */
  235. *m = 0xA5A0 | i;
  236. /* check that we read back what we wrote */
  237. if (*m != (0xA5A0 | i))
  238. break;
  239. /* check for partial decode and wrap */
  240. for (j = 0; j < i; j++) {
  241. volatile unsigned short *p = (unsigned short *) (membase + (j * 0x1000));
  242. if (*p != (0xA5A0 | j))
  243. break;
  244. }
  245. }
  246. local_irq_restore(flags);
  247. /* in any case, we stopped once we tried one block too many,
  248. or once we reached 32K */
  249. return i * 0x1000;
  250. }
  251. struct net_device * __init mac8390_probe(int unit)
  252. {
  253. struct net_device *dev;
  254. volatile unsigned short *i;
  255. int version_disp = 0;
  256. struct nubus_dev * ndev = NULL;
  257. int err = -ENODEV;
  258. struct nubus_dir dir;
  259. struct nubus_dirent ent;
  260. int offset;
  261. static unsigned int slots;
  262. enum mac8390_type cardtype;
  263. /* probably should check for Nubus instead */
  264. if (!MACH_IS_MAC)
  265. return ERR_PTR(-ENODEV);
  266. dev = ____alloc_ei_netdev(0);
  267. if (!dev)
  268. return ERR_PTR(-ENOMEM);
  269. if (unit >= 0)
  270. sprintf(dev->name, "eth%d", unit);
  271. SET_MODULE_OWNER(dev);
  272. while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET, ndev))) {
  273. /* Have we seen it already? */
  274. if (slots & (1<<ndev->board->slot))
  275. continue;
  276. slots |= 1<<ndev->board->slot;
  277. if ((cardtype = mac8390_ident(ndev)) == MAC8390_NONE)
  278. continue;
  279. if (version_disp == 0) {
  280. version_disp = 1;
  281. printk(version);
  282. }
  283. dev->irq = SLOT2IRQ(ndev->board->slot);
  284. /* This is getting to be a habit */
  285. dev->base_addr = ndev->board->slot_addr | ((ndev->board->slot&0xf) << 20);
  286. /* Get some Nubus info - we will trust the card's idea
  287. of where its memory and registers are. */
  288. if (nubus_get_func_dir(ndev, &dir) == -1) {
  289. printk(KERN_ERR "%s: Unable to get Nubus functional"
  290. " directory for slot %X!\n",
  291. dev->name, ndev->board->slot);
  292. continue;
  293. }
  294. /* Get the MAC address */
  295. if ((nubus_find_rsrc(&dir, NUBUS_RESID_MAC_ADDRESS, &ent)) == -1) {
  296. printk(KERN_INFO "%s: Couldn't get MAC address!\n",
  297. dev->name);
  298. continue;
  299. } else {
  300. nubus_get_rsrc_mem(dev->dev_addr, &ent, 6);
  301. }
  302. if (useresources[cardtype] == 1) {
  303. nubus_rewinddir(&dir);
  304. if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_BASEOS, &ent) == -1) {
  305. printk(KERN_ERR "%s: Memory offset resource"
  306. " for slot %X not found!\n",
  307. dev->name, ndev->board->slot);
  308. continue;
  309. }
  310. nubus_get_rsrc_mem(&offset, &ent, 4);
  311. dev->mem_start = dev->base_addr + offset;
  312. /* yes, this is how the Apple driver does it */
  313. dev->base_addr = dev->mem_start + 0x10000;
  314. nubus_rewinddir(&dir);
  315. if (nubus_find_rsrc(&dir, NUBUS_RESID_MINOR_LENGTH, &ent) == -1) {
  316. printk(KERN_INFO "%s: Memory length resource"
  317. " for slot %X not found"
  318. ", probing\n",
  319. dev->name, ndev->board->slot);
  320. offset = mac8390_memsize(dev->mem_start);
  321. } else {
  322. nubus_get_rsrc_mem(&offset, &ent, 4);
  323. }
  324. dev->mem_end = dev->mem_start + offset;
  325. } else {
  326. switch (cardtype) {
  327. case MAC8390_KINETICS:
  328. case MAC8390_DAYNA: /* it's the same */
  329. dev->base_addr =
  330. (int)(ndev->board->slot_addr +
  331. DAYNA_8390_BASE);
  332. dev->mem_start =
  333. (int)(ndev->board->slot_addr +
  334. DAYNA_8390_MEM);
  335. dev->mem_end =
  336. dev->mem_start +
  337. mac8390_memsize(dev->mem_start);
  338. break;
  339. case MAC8390_INTERLAN:
  340. dev->base_addr =
  341. (int)(ndev->board->slot_addr +
  342. INTERLAN_8390_BASE);
  343. dev->mem_start =
  344. (int)(ndev->board->slot_addr +
  345. INTERLAN_8390_MEM);
  346. dev->mem_end =
  347. dev->mem_start +
  348. mac8390_memsize(dev->mem_start);
  349. break;
  350. case MAC8390_CABLETRON:
  351. dev->base_addr =
  352. (int)(ndev->board->slot_addr +
  353. CABLETRON_8390_BASE);
  354. dev->mem_start =
  355. (int)(ndev->board->slot_addr +
  356. CABLETRON_8390_MEM);
  357. /* The base address is unreadable if 0x00
  358. * has been written to the command register
  359. * Reset the chip by writing E8390_NODMA +
  360. * E8390_PAGE0 + E8390_STOP just to be
  361. * sure
  362. */
  363. i = (void *)dev->base_addr;
  364. *i = 0x21;
  365. dev->mem_end =
  366. dev->mem_start +
  367. mac8390_memsize(dev->mem_start);
  368. break;
  369. default:
  370. printk(KERN_ERR "Card type %s is"
  371. " unsupported, sorry\n",
  372. ndev->board->name);
  373. continue;
  374. }
  375. }
  376. /* Do the nasty 8390 stuff */
  377. if (!mac8390_initdev(dev, ndev, cardtype))
  378. break;
  379. }
  380. if (!ndev)
  381. goto out;
  382. err = register_netdev(dev);
  383. if (err)
  384. goto out;
  385. return dev;
  386. out:
  387. free_netdev(dev);
  388. return ERR_PTR(err);
  389. }
  390. #ifdef MODULE
  391. MODULE_AUTHOR("David Huggins-Daines <dhd@debian.org> and others");
  392. MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
  393. MODULE_LICENSE("GPL");
  394. /* overkill, of course */
  395. static struct net_device *dev_mac8390[15];
  396. int init_module(void)
  397. {
  398. int i;
  399. for (i = 0; i < 15; i++) {
  400. struct net_device *dev = mac8390_probe(-1);
  401. if (IS_ERR(dev))
  402. break;
  403. dev_mac890[i] = dev;
  404. }
  405. if (!i) {
  406. printk(KERN_NOTICE "mac8390.c: No useable cards found, driver NOT installed.\n");
  407. return -ENODEV;
  408. }
  409. return 0;
  410. }
  411. void cleanup_module(void)
  412. {
  413. int i;
  414. for (i = 0; i < 15; i++) {
  415. struct net_device *dev = dev_mac890[i];
  416. if (dev) {
  417. unregister_netdev(dev);
  418. free_netdev(dev);
  419. }
  420. }
  421. }
  422. #endif /* MODULE */
  423. static int __init mac8390_initdev(struct net_device * dev, struct nubus_dev * ndev,
  424. enum mac8390_type type)
  425. {
  426. static u32 fwrd4_offsets[16]={
  427. 0, 4, 8, 12,
  428. 16, 20, 24, 28,
  429. 32, 36, 40, 44,
  430. 48, 52, 56, 60
  431. };
  432. static u32 back4_offsets[16]={
  433. 60, 56, 52, 48,
  434. 44, 40, 36, 32,
  435. 28, 24, 20, 16,
  436. 12, 8, 4, 0
  437. };
  438. static u32 fwrd2_offsets[16]={
  439. 0, 2, 4, 6,
  440. 8, 10, 12, 14,
  441. 16, 18, 20, 22,
  442. 24, 26, 28, 30
  443. };
  444. int access_bitmode = 0;
  445. /* Now fill in our stuff */
  446. dev->open = &mac8390_open;
  447. dev->stop = &mac8390_close;
  448. #ifdef CONFIG_NET_POLL_CONTROLLER
  449. dev->poll_controller = __ei_poll;
  450. #endif
  451. /* GAR, ei_status is actually a macro even though it looks global */
  452. ei_status.name = cardname[type];
  453. ei_status.word16 = word16[type];
  454. /* Cabletron's TX/RX buffers are backwards */
  455. if (type == MAC8390_CABLETRON) {
  456. ei_status.tx_start_page = CABLETRON_TX_START_PG;
  457. ei_status.rx_start_page = CABLETRON_RX_START_PG;
  458. ei_status.stop_page = CABLETRON_RX_STOP_PG;
  459. ei_status.rmem_start = dev->mem_start;
  460. ei_status.rmem_end = dev->mem_start + CABLETRON_RX_STOP_PG*256;
  461. } else {
  462. ei_status.tx_start_page = WD_START_PG;
  463. ei_status.rx_start_page = WD_START_PG + TX_PAGES;
  464. ei_status.stop_page = (dev->mem_end - dev->mem_start)/256;
  465. ei_status.rmem_start = dev->mem_start + TX_PAGES*256;
  466. ei_status.rmem_end = dev->mem_end;
  467. }
  468. /* Fill in model-specific information and functions */
  469. switch(type) {
  470. case MAC8390_FARALLON:
  471. case MAC8390_APPLE:
  472. switch(mac8390_testio(dev->mem_start)) {
  473. case ACCESS_UNKNOWN:
  474. printk("Don't know how to access card memory!\n");
  475. return -ENODEV;
  476. break;
  477. case ACCESS_16:
  478. /* 16 bit card, register map is reversed */
  479. ei_status.reset_8390 = &mac8390_no_reset;
  480. ei_status.block_input = &slow_sane_block_input;
  481. ei_status.block_output = &slow_sane_block_output;
  482. ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
  483. ei_status.reg_offset = back4_offsets;
  484. break;
  485. case ACCESS_32:
  486. /* 32 bit card, register map is reversed */
  487. ei_status.reset_8390 = &mac8390_no_reset;
  488. ei_status.block_input = &sane_block_input;
  489. ei_status.block_output = &sane_block_output;
  490. ei_status.get_8390_hdr = &sane_get_8390_hdr;
  491. ei_status.reg_offset = back4_offsets;
  492. access_bitmode = 1;
  493. break;
  494. }
  495. break;
  496. case MAC8390_ASANTE:
  497. /* Some Asante cards pass the 32 bit test
  498. * but overwrite system memory when run at 32 bit.
  499. * so we run them all at 16 bit.
  500. */
  501. ei_status.reset_8390 = &mac8390_no_reset;
  502. ei_status.block_input = &slow_sane_block_input;
  503. ei_status.block_output = &slow_sane_block_output;
  504. ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
  505. ei_status.reg_offset = back4_offsets;
  506. break;
  507. case MAC8390_CABLETRON:
  508. /* 16 bit card, register map is short forward */
  509. ei_status.reset_8390 = &mac8390_no_reset;
  510. ei_status.block_input = &slow_sane_block_input;
  511. ei_status.block_output = &slow_sane_block_output;
  512. ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
  513. ei_status.reg_offset = fwrd2_offsets;
  514. break;
  515. case MAC8390_DAYNA:
  516. case MAC8390_KINETICS:
  517. /* 16 bit memory, register map is forward */
  518. /* dayna and similar */
  519. ei_status.reset_8390 = &mac8390_no_reset;
  520. ei_status.block_input = &dayna_block_input;
  521. ei_status.block_output = &dayna_block_output;
  522. ei_status.get_8390_hdr = &dayna_get_8390_hdr;
  523. ei_status.reg_offset = fwrd4_offsets;
  524. break;
  525. case MAC8390_INTERLAN:
  526. /* 16 bit memory, register map is forward */
  527. ei_status.reset_8390 = &interlan_reset;
  528. ei_status.block_input = &slow_sane_block_input;
  529. ei_status.block_output = &slow_sane_block_output;
  530. ei_status.get_8390_hdr = &slow_sane_get_8390_hdr;
  531. ei_status.reg_offset = fwrd4_offsets;
  532. break;
  533. default:
  534. printk(KERN_ERR "Card type %s is unsupported, sorry\n", ndev->board->name);
  535. return -ENODEV;
  536. }
  537. __NS8390_init(dev, 0);
  538. /* Good, done, now spit out some messages */
  539. printk(KERN_INFO "%s: %s in slot %X (type %s)\n",
  540. dev->name, ndev->board->name, ndev->board->slot, cardname[type]);
  541. printk(KERN_INFO "MAC ");
  542. {
  543. int i;
  544. for (i = 0; i < 6; i++) {
  545. printk("%2.2x", dev->dev_addr[i]);
  546. if (i < 5)
  547. printk(":");
  548. }
  549. }
  550. printk(" IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
  551. dev->irq, (int)((dev->mem_end - dev->mem_start)/0x1000) * 4,
  552. dev->mem_start, access_bitmode?32:16);
  553. return 0;
  554. }
  555. static int mac8390_open(struct net_device *dev)
  556. {
  557. __ei_open(dev);
  558. if (request_irq(dev->irq, __ei_interrupt, 0, "8390 Ethernet", dev)) {
  559. printk ("%s: unable to get IRQ %d.\n", dev->name, dev->irq);
  560. return -EAGAIN;
  561. }
  562. return 0;
  563. }
  564. static int mac8390_close(struct net_device *dev)
  565. {
  566. free_irq(dev->irq, dev);
  567. __ei_close(dev);
  568. return 0;
  569. }
  570. static void mac8390_no_reset(struct net_device *dev)
  571. {
  572. ei_status.txing = 0;
  573. if (ei_debug > 1)
  574. printk("reset not supported\n");
  575. return;
  576. }
  577. static void interlan_reset(struct net_device *dev)
  578. {
  579. unsigned char *target=nubus_slot_addr(IRQ2SLOT(dev->irq));
  580. if (ei_debug > 1)
  581. printk("Need to reset the NS8390 t=%lu...", jiffies);
  582. ei_status.txing = 0;
  583. target[0xC0000] = 0;
  584. if (ei_debug > 1)
  585. printk("reset complete\n");
  586. return;
  587. }
  588. /* dayna_memcpy_fromio/dayna_memcpy_toio */
  589. /* directly from daynaport.c by Alan Cox */
  590. static void dayna_memcpy_fromcard(struct net_device *dev, void *to, int from, int count)
  591. {
  592. volatile unsigned char *ptr;
  593. unsigned char *target=to;
  594. from<<=1; /* word, skip overhead */
  595. ptr=(unsigned char *)(dev->mem_start+from);
  596. /* Leading byte? */
  597. if (from&2) {
  598. *target++ = ptr[-1];
  599. ptr += 2;
  600. count--;
  601. }
  602. while(count>=2)
  603. {
  604. *(unsigned short *)target = *(unsigned short volatile *)ptr;
  605. ptr += 4; /* skip cruft */
  606. target += 2;
  607. count-=2;
  608. }
  609. /* Trailing byte? */
  610. if(count)
  611. *target = *ptr;
  612. }
  613. static void dayna_memcpy_tocard(struct net_device *dev, int to, const void *from, int count)
  614. {
  615. volatile unsigned short *ptr;
  616. const unsigned char *src=from;
  617. to<<=1; /* word, skip overhead */
  618. ptr=(unsigned short *)(dev->mem_start+to);
  619. /* Leading byte? */
  620. if (to&2) { /* avoid a byte write (stomps on other data) */
  621. ptr[-1] = (ptr[-1]&0xFF00)|*src++;
  622. ptr++;
  623. count--;
  624. }
  625. while(count>=2)
  626. {
  627. *ptr++=*(unsigned short *)src; /* Copy and */
  628. ptr++; /* skip cruft */
  629. src += 2;
  630. count-=2;
  631. }
  632. /* Trailing byte? */
  633. if(count)
  634. {
  635. /* card doesn't like byte writes */
  636. *ptr=(*ptr&0x00FF)|(*src << 8);
  637. }
  638. }
  639. /* sane block input/output */
  640. static void sane_get_8390_hdr(struct net_device *dev,
  641. struct e8390_pkt_hdr *hdr, int ring_page)
  642. {
  643. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  644. memcpy_fromio((void *)hdr, (char *)dev->mem_start + hdr_start, 4);
  645. /* Fix endianness */
  646. hdr->count = swab16(hdr->count);
  647. }
  648. static void sane_block_input(struct net_device *dev, int count,
  649. struct sk_buff *skb, int ring_offset)
  650. {
  651. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  652. unsigned long xfer_start = xfer_base + dev->mem_start;
  653. if (xfer_start + count > ei_status.rmem_end) {
  654. /* We must wrap the input move. */
  655. int semi_count = ei_status.rmem_end - xfer_start;
  656. memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, semi_count);
  657. count -= semi_count;
  658. memcpy_toio(skb->data + semi_count, (char *)ei_status.rmem_start, count);
  659. } else {
  660. memcpy_fromio(skb->data, (char *)dev->mem_start + xfer_base, count);
  661. }
  662. }
  663. static void sane_block_output(struct net_device *dev, int count,
  664. const unsigned char *buf, int start_page)
  665. {
  666. long shmem = (start_page - WD_START_PG)<<8;
  667. memcpy_toio((char *)dev->mem_start + shmem, buf, count);
  668. }
  669. /* dayna block input/output */
  670. static void dayna_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
  671. {
  672. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  673. dayna_memcpy_fromcard(dev, (void *)hdr, hdr_start, 4);
  674. /* Fix endianness */
  675. hdr->count=(hdr->count&0xFF)<<8|(hdr->count>>8);
  676. }
  677. static void dayna_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
  678. {
  679. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  680. unsigned long xfer_start = xfer_base+dev->mem_start;
  681. /* Note the offset math is done in card memory space which is word
  682. per long onto our space. */
  683. if (xfer_start + count > ei_status.rmem_end)
  684. {
  685. /* We must wrap the input move. */
  686. int semi_count = ei_status.rmem_end - xfer_start;
  687. dayna_memcpy_fromcard(dev, skb->data, xfer_base, semi_count);
  688. count -= semi_count;
  689. dayna_memcpy_fromcard(dev, skb->data + semi_count,
  690. ei_status.rmem_start - dev->mem_start,
  691. count);
  692. }
  693. else
  694. {
  695. dayna_memcpy_fromcard(dev, skb->data, xfer_base, count);
  696. }
  697. }
  698. static void dayna_block_output(struct net_device *dev, int count, const unsigned char *buf,
  699. int start_page)
  700. {
  701. long shmem = (start_page - WD_START_PG)<<8;
  702. dayna_memcpy_tocard(dev, shmem, buf, count);
  703. }
  704. /* Cabletron block I/O */
  705. static void slow_sane_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
  706. int ring_page)
  707. {
  708. unsigned long hdr_start = (ring_page - WD_START_PG)<<8;
  709. word_memcpy_fromcard((void *)hdr, (char *)dev->mem_start+hdr_start, 4);
  710. /* Register endianism - fix here rather than 8390.c */
  711. hdr->count = (hdr->count&0xFF)<<8|(hdr->count>>8);
  712. }
  713. static void slow_sane_block_input(struct net_device *dev, int count, struct sk_buff *skb,
  714. int ring_offset)
  715. {
  716. unsigned long xfer_base = ring_offset - (WD_START_PG<<8);
  717. unsigned long xfer_start = xfer_base+dev->mem_start;
  718. if (xfer_start + count > ei_status.rmem_end)
  719. {
  720. /* We must wrap the input move. */
  721. int semi_count = ei_status.rmem_end - xfer_start;
  722. word_memcpy_fromcard(skb->data, (char *)dev->mem_start +
  723. xfer_base, semi_count);
  724. count -= semi_count;
  725. word_memcpy_fromcard(skb->data + semi_count,
  726. (char *)ei_status.rmem_start, count);
  727. }
  728. else
  729. {
  730. word_memcpy_fromcard(skb->data, (char *)dev->mem_start +
  731. xfer_base, count);
  732. }
  733. }
  734. static void slow_sane_block_output(struct net_device *dev, int count, const unsigned char *buf,
  735. int start_page)
  736. {
  737. long shmem = (start_page - WD_START_PG)<<8;
  738. word_memcpy_tocard((char *)dev->mem_start + shmem, buf, count);
  739. }
  740. static void word_memcpy_tocard(void *tp, const void *fp, int count)
  741. {
  742. volatile unsigned short *to = tp;
  743. const unsigned short *from = fp;
  744. count++;
  745. count/=2;
  746. while(count--)
  747. *to++=*from++;
  748. }
  749. static void word_memcpy_fromcard(void *tp, const void *fp, int count)
  750. {
  751. unsigned short *to = tp;
  752. const volatile unsigned short *from = fp;
  753. count++;
  754. count/=2;
  755. while(count--)
  756. *to++=*from++;
  757. }