mac8390.c 23 KB

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