mac8390.c 23 KB

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