mac8390.c 23 KB

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