mac8390.c 23 KB

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