mac8390.c 23 KB

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