mac8390.c 23 KB

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