82596.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549
  1. /* 82596.c: A generic 82596 ethernet driver for linux. */
  2. /*
  3. Based on Apricot.c
  4. Written 1994 by Mark Evans.
  5. This driver is for the Apricot 82596 bus-master interface
  6. Modularised 12/94 Mark Evans
  7. Modified to support the 82596 ethernet chips on 680x0 VME boards.
  8. by Richard Hirst <richard@sleepie.demon.co.uk>
  9. Renamed to be 82596.c
  10. 980825: Changed to receive directly in to sk_buffs which are
  11. allocated at open() time. Eliminates copy on incoming frames
  12. (small ones are still copied). Shared data now held in a
  13. non-cached page, so we can run on 68060 in copyback mode.
  14. TBD:
  15. * look at deferring rx frames rather than discarding (as per tulip)
  16. * handle tx ring full as per tulip
  17. * performance test to tune rx_copybreak
  18. Most of my modifications relate to the braindead big-endian
  19. implementation by Intel. When the i596 is operating in
  20. 'big-endian' mode, it thinks a 32 bit value of 0x12345678
  21. should be stored as 0x56781234. This is a real pain, when
  22. you have linked lists which are shared by the 680x0 and the
  23. i596.
  24. Driver skeleton
  25. Written 1993 by Donald Becker.
  26. Copyright 1993 United States Government as represented by the Director,
  27. National Security Agency. This software may only be used and distributed
  28. according to the terms of the GNU General Public License as modified by SRC,
  29. incorporated herein by reference.
  30. The author may be reached as becker@scyld.com, or C/O
  31. Scyld Computing Corporation, 410 Severn Ave., Suite 210, Annapolis MD 21403
  32. */
  33. #include <linux/module.h>
  34. #include <linux/kernel.h>
  35. #include <linux/string.h>
  36. #include <linux/errno.h>
  37. #include <linux/ioport.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/delay.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/etherdevice.h>
  42. #include <linux/skbuff.h>
  43. #include <linux/init.h>
  44. #include <linux/bitops.h>
  45. #include <linux/gfp.h>
  46. #include <asm/io.h>
  47. #include <asm/dma.h>
  48. #include <asm/pgtable.h>
  49. #include <asm/cacheflush.h>
  50. static char version[] __initdata =
  51. "82596.c $Revision: 1.5 $\n";
  52. #define DRV_NAME "82596"
  53. /* DEBUG flags
  54. */
  55. #define DEB_INIT 0x0001
  56. #define DEB_PROBE 0x0002
  57. #define DEB_SERIOUS 0x0004
  58. #define DEB_ERRORS 0x0008
  59. #define DEB_MULTI 0x0010
  60. #define DEB_TDR 0x0020
  61. #define DEB_OPEN 0x0040
  62. #define DEB_RESET 0x0080
  63. #define DEB_ADDCMD 0x0100
  64. #define DEB_STATUS 0x0200
  65. #define DEB_STARTTX 0x0400
  66. #define DEB_RXADDR 0x0800
  67. #define DEB_TXADDR 0x1000
  68. #define DEB_RXFRAME 0x2000
  69. #define DEB_INTS 0x4000
  70. #define DEB_STRUCT 0x8000
  71. #define DEB_ANY 0xffff
  72. #define DEB(x,y) if (i596_debug & (x)) y
  73. #if IS_ENABLED(CONFIG_MVME16x_NET)
  74. #define ENABLE_MVME16x_NET
  75. #endif
  76. #if IS_ENABLED(CONFIG_BVME6000_NET)
  77. #define ENABLE_BVME6000_NET
  78. #endif
  79. #ifdef ENABLE_MVME16x_NET
  80. #include <asm/mvme16xhw.h>
  81. #endif
  82. #ifdef ENABLE_BVME6000_NET
  83. #include <asm/bvme6000hw.h>
  84. #endif
  85. /*
  86. * Define various macros for Channel Attention, word swapping etc., dependent
  87. * on architecture. MVME and BVME are 680x0 based, otherwise it is Intel.
  88. */
  89. #ifdef __mc68000__
  90. #define WSWAPrfd(x) ((struct i596_rfd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
  91. #define WSWAPrbd(x) ((struct i596_rbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
  92. #define WSWAPiscp(x) ((struct i596_iscp *)(((u32)(x)<<16) | ((((u32)(x)))>>16)))
  93. #define WSWAPscb(x) ((struct i596_scb *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
  94. #define WSWAPcmd(x) ((struct i596_cmd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
  95. #define WSWAPtbd(x) ((struct i596_tbd *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
  96. #define WSWAPchar(x) ((char *) (((u32)(x)<<16) | ((((u32)(x)))>>16)))
  97. #define ISCP_BUSY 0x00010000
  98. #else
  99. #error 82596.c: unknown architecture
  100. #endif
  101. /*
  102. * These were the intel versions, left here for reference. There
  103. * are currently no x86 users of this legacy i82596 chip.
  104. */
  105. #if 0
  106. #define WSWAPrfd(x) ((struct i596_rfd *)((long)x))
  107. #define WSWAPrbd(x) ((struct i596_rbd *)((long)x))
  108. #define WSWAPiscp(x) ((struct i596_iscp *)((long)x))
  109. #define WSWAPscb(x) ((struct i596_scb *)((long)x))
  110. #define WSWAPcmd(x) ((struct i596_cmd *)((long)x))
  111. #define WSWAPtbd(x) ((struct i596_tbd *)((long)x))
  112. #define WSWAPchar(x) ((char *)((long)x))
  113. #define ISCP_BUSY 0x0001
  114. #endif
  115. /*
  116. * The MPU_PORT command allows direct access to the 82596. With PORT access
  117. * the following commands are available (p5-18). The 32-bit port command
  118. * must be word-swapped with the most significant word written first.
  119. * This only applies to VME boards.
  120. */
  121. #define PORT_RESET 0x00 /* reset 82596 */
  122. #define PORT_SELFTEST 0x01 /* selftest */
  123. #define PORT_ALTSCP 0x02 /* alternate SCB address */
  124. #define PORT_ALTDUMP 0x03 /* Alternate DUMP address */
  125. static int i596_debug = (DEB_SERIOUS|DEB_PROBE);
  126. MODULE_AUTHOR("Richard Hirst");
  127. MODULE_DESCRIPTION("i82596 driver");
  128. MODULE_LICENSE("GPL");
  129. module_param(i596_debug, int, 0);
  130. MODULE_PARM_DESC(i596_debug, "i82596 debug mask");
  131. /* Copy frames shorter than rx_copybreak, otherwise pass on up in
  132. * a full sized sk_buff. Value of 100 stolen from tulip.c (!alpha).
  133. */
  134. static int rx_copybreak = 100;
  135. #define PKT_BUF_SZ 1536
  136. #define MAX_MC_CNT 64
  137. #define I596_TOTAL_SIZE 17
  138. #define I596_NULL ((void *)0xffffffff)
  139. #define CMD_EOL 0x8000 /* The last command of the list, stop. */
  140. #define CMD_SUSP 0x4000 /* Suspend after doing cmd. */
  141. #define CMD_INTR 0x2000 /* Interrupt after doing cmd. */
  142. #define CMD_FLEX 0x0008 /* Enable flexible memory model */
  143. enum commands {
  144. CmdNOp = 0, CmdSASetup = 1, CmdConfigure = 2, CmdMulticastList = 3,
  145. CmdTx = 4, CmdTDR = 5, CmdDump = 6, CmdDiagnose = 7
  146. };
  147. #define STAT_C 0x8000 /* Set to 0 after execution */
  148. #define STAT_B 0x4000 /* Command being executed */
  149. #define STAT_OK 0x2000 /* Command executed ok */
  150. #define STAT_A 0x1000 /* Command aborted */
  151. #define CUC_START 0x0100
  152. #define CUC_RESUME 0x0200
  153. #define CUC_SUSPEND 0x0300
  154. #define CUC_ABORT 0x0400
  155. #define RX_START 0x0010
  156. #define RX_RESUME 0x0020
  157. #define RX_SUSPEND 0x0030
  158. #define RX_ABORT 0x0040
  159. #define TX_TIMEOUT (HZ/20)
  160. struct i596_reg {
  161. unsigned short porthi;
  162. unsigned short portlo;
  163. unsigned long ca;
  164. };
  165. #define EOF 0x8000
  166. #define SIZE_MASK 0x3fff
  167. struct i596_tbd {
  168. unsigned short size;
  169. unsigned short pad;
  170. struct i596_tbd *next;
  171. char *data;
  172. };
  173. /* The command structure has two 'next' pointers; v_next is the address of
  174. * the next command as seen by the CPU, b_next is the address of the next
  175. * command as seen by the 82596. The b_next pointer, as used by the 82596
  176. * always references the status field of the next command, rather than the
  177. * v_next field, because the 82596 is unaware of v_next. It may seem more
  178. * logical to put v_next at the end of the structure, but we cannot do that
  179. * because the 82596 expects other fields to be there, depending on command
  180. * type.
  181. */
  182. struct i596_cmd {
  183. struct i596_cmd *v_next; /* Address from CPUs viewpoint */
  184. unsigned short status;
  185. unsigned short command;
  186. struct i596_cmd *b_next; /* Address from i596 viewpoint */
  187. };
  188. struct tx_cmd {
  189. struct i596_cmd cmd;
  190. struct i596_tbd *tbd;
  191. unsigned short size;
  192. unsigned short pad;
  193. struct sk_buff *skb; /* So we can free it after tx */
  194. };
  195. struct tdr_cmd {
  196. struct i596_cmd cmd;
  197. unsigned short status;
  198. unsigned short pad;
  199. };
  200. struct mc_cmd {
  201. struct i596_cmd cmd;
  202. short mc_cnt;
  203. char mc_addrs[MAX_MC_CNT*6];
  204. };
  205. struct sa_cmd {
  206. struct i596_cmd cmd;
  207. char eth_addr[8];
  208. };
  209. struct cf_cmd {
  210. struct i596_cmd cmd;
  211. char i596_config[16];
  212. };
  213. struct i596_rfd {
  214. unsigned short stat;
  215. unsigned short cmd;
  216. struct i596_rfd *b_next; /* Address from i596 viewpoint */
  217. struct i596_rbd *rbd;
  218. unsigned short count;
  219. unsigned short size;
  220. struct i596_rfd *v_next; /* Address from CPUs viewpoint */
  221. struct i596_rfd *v_prev;
  222. };
  223. struct i596_rbd {
  224. unsigned short count;
  225. unsigned short zero1;
  226. struct i596_rbd *b_next;
  227. unsigned char *b_data; /* Address from i596 viewpoint */
  228. unsigned short size;
  229. unsigned short zero2;
  230. struct sk_buff *skb;
  231. struct i596_rbd *v_next;
  232. struct i596_rbd *b_addr; /* This rbd addr from i596 view */
  233. unsigned char *v_data; /* Address from CPUs viewpoint */
  234. };
  235. #define TX_RING_SIZE 64
  236. #define RX_RING_SIZE 16
  237. struct i596_scb {
  238. unsigned short status;
  239. unsigned short command;
  240. struct i596_cmd *cmd;
  241. struct i596_rfd *rfd;
  242. unsigned long crc_err;
  243. unsigned long align_err;
  244. unsigned long resource_err;
  245. unsigned long over_err;
  246. unsigned long rcvdt_err;
  247. unsigned long short_err;
  248. unsigned short t_on;
  249. unsigned short t_off;
  250. };
  251. struct i596_iscp {
  252. unsigned long stat;
  253. struct i596_scb *scb;
  254. };
  255. struct i596_scp {
  256. unsigned long sysbus;
  257. unsigned long pad;
  258. struct i596_iscp *iscp;
  259. };
  260. struct i596_private {
  261. volatile struct i596_scp scp;
  262. volatile struct i596_iscp iscp;
  263. volatile struct i596_scb scb;
  264. struct sa_cmd sa_cmd;
  265. struct cf_cmd cf_cmd;
  266. struct tdr_cmd tdr_cmd;
  267. struct mc_cmd mc_cmd;
  268. unsigned long stat;
  269. int last_restart __attribute__((aligned(4)));
  270. struct i596_rfd *rfd_head;
  271. struct i596_rbd *rbd_head;
  272. struct i596_cmd *cmd_tail;
  273. struct i596_cmd *cmd_head;
  274. int cmd_backlog;
  275. unsigned long last_cmd;
  276. struct i596_rfd rfds[RX_RING_SIZE];
  277. struct i596_rbd rbds[RX_RING_SIZE];
  278. struct tx_cmd tx_cmds[TX_RING_SIZE];
  279. struct i596_tbd tbds[TX_RING_SIZE];
  280. int next_tx_cmd;
  281. spinlock_t lock;
  282. };
  283. static char init_setup[] =
  284. {
  285. 0x8E, /* length, prefetch on */
  286. 0xC8, /* fifo to 8, monitor off */
  287. #ifdef CONFIG_VME
  288. 0xc0, /* don't save bad frames */
  289. #else
  290. 0x80, /* don't save bad frames */
  291. #endif
  292. 0x2E, /* No source address insertion, 8 byte preamble */
  293. 0x00, /* priority and backoff defaults */
  294. 0x60, /* interframe spacing */
  295. 0x00, /* slot time LSB */
  296. 0xf2, /* slot time and retries */
  297. 0x00, /* promiscuous mode */
  298. 0x00, /* collision detect */
  299. 0x40, /* minimum frame length */
  300. 0xff,
  301. 0x00,
  302. 0x7f /* *multi IA */ };
  303. static int i596_open(struct net_device *dev);
  304. static netdev_tx_t i596_start_xmit(struct sk_buff *skb, struct net_device *dev);
  305. static irqreturn_t i596_interrupt(int irq, void *dev_id);
  306. static int i596_close(struct net_device *dev);
  307. static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd);
  308. static void i596_tx_timeout (struct net_device *dev);
  309. static void print_eth(unsigned char *buf, char *str);
  310. static void set_multicast_list(struct net_device *dev);
  311. static int rx_ring_size = RX_RING_SIZE;
  312. static int ticks_limit = 25;
  313. static int max_cmd_backlog = TX_RING_SIZE-1;
  314. static inline void CA(struct net_device *dev)
  315. {
  316. #ifdef ENABLE_MVME16x_NET
  317. if (MACH_IS_MVME16x) {
  318. ((struct i596_reg *) dev->base_addr)->ca = 1;
  319. }
  320. #endif
  321. #ifdef ENABLE_BVME6000_NET
  322. if (MACH_IS_BVME6000) {
  323. volatile u32 i;
  324. i = *(volatile u32 *) (dev->base_addr);
  325. }
  326. #endif
  327. }
  328. static inline void MPU_PORT(struct net_device *dev, int c, volatile void *x)
  329. {
  330. #ifdef ENABLE_MVME16x_NET
  331. if (MACH_IS_MVME16x) {
  332. struct i596_reg *p = (struct i596_reg *) (dev->base_addr);
  333. p->porthi = ((c) | (u32) (x)) & 0xffff;
  334. p->portlo = ((c) | (u32) (x)) >> 16;
  335. }
  336. #endif
  337. #ifdef ENABLE_BVME6000_NET
  338. if (MACH_IS_BVME6000) {
  339. u32 v = (u32) (c) | (u32) (x);
  340. v = ((u32) (v) << 16) | ((u32) (v) >> 16);
  341. *(volatile u32 *) dev->base_addr = v;
  342. udelay(1);
  343. *(volatile u32 *) dev->base_addr = v;
  344. }
  345. #endif
  346. }
  347. static inline int wait_istat(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
  348. {
  349. while (--delcnt && lp->iscp.stat)
  350. udelay(10);
  351. if (!delcnt) {
  352. printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n",
  353. dev->name, str, lp->scb.status, lp->scb.command);
  354. return -1;
  355. }
  356. else
  357. return 0;
  358. }
  359. static inline int wait_cmd(struct net_device *dev, struct i596_private *lp, int delcnt, char *str)
  360. {
  361. while (--delcnt && lp->scb.command)
  362. udelay(10);
  363. if (!delcnt) {
  364. printk(KERN_ERR "%s: %s, status %4.4x, cmd %4.4x.\n",
  365. dev->name, str, lp->scb.status, lp->scb.command);
  366. return -1;
  367. }
  368. else
  369. return 0;
  370. }
  371. static inline int wait_cfg(struct net_device *dev, struct i596_cmd *cmd, int delcnt, char *str)
  372. {
  373. volatile struct i596_cmd *c = cmd;
  374. while (--delcnt && c->command)
  375. udelay(10);
  376. if (!delcnt) {
  377. printk(KERN_ERR "%s: %s.\n", dev->name, str);
  378. return -1;
  379. }
  380. else
  381. return 0;
  382. }
  383. static void i596_display_data(struct net_device *dev)
  384. {
  385. struct i596_private *lp = dev->ml_priv;
  386. struct i596_cmd *cmd;
  387. struct i596_rfd *rfd;
  388. struct i596_rbd *rbd;
  389. printk(KERN_ERR "lp and scp at %p, .sysbus = %08lx, .iscp = %p\n",
  390. &lp->scp, lp->scp.sysbus, lp->scp.iscp);
  391. printk(KERN_ERR "iscp at %p, iscp.stat = %08lx, .scb = %p\n",
  392. &lp->iscp, lp->iscp.stat, lp->iscp.scb);
  393. printk(KERN_ERR "scb at %p, scb.status = %04x, .command = %04x,"
  394. " .cmd = %p, .rfd = %p\n",
  395. &lp->scb, lp->scb.status, lp->scb.command,
  396. lp->scb.cmd, lp->scb.rfd);
  397. printk(KERN_ERR " errors: crc %lx, align %lx, resource %lx,"
  398. " over %lx, rcvdt %lx, short %lx\n",
  399. lp->scb.crc_err, lp->scb.align_err, lp->scb.resource_err,
  400. lp->scb.over_err, lp->scb.rcvdt_err, lp->scb.short_err);
  401. cmd = lp->cmd_head;
  402. while (cmd != I596_NULL) {
  403. printk(KERN_ERR "cmd at %p, .status = %04x, .command = %04x, .b_next = %p\n",
  404. cmd, cmd->status, cmd->command, cmd->b_next);
  405. cmd = cmd->v_next;
  406. }
  407. rfd = lp->rfd_head;
  408. printk(KERN_ERR "rfd_head = %p\n", rfd);
  409. do {
  410. printk(KERN_ERR " %p .stat %04x, .cmd %04x, b_next %p, rbd %p,"
  411. " count %04x\n",
  412. rfd, rfd->stat, rfd->cmd, rfd->b_next, rfd->rbd,
  413. rfd->count);
  414. rfd = rfd->v_next;
  415. } while (rfd != lp->rfd_head);
  416. rbd = lp->rbd_head;
  417. printk(KERN_ERR "rbd_head = %p\n", rbd);
  418. do {
  419. printk(KERN_ERR " %p .count %04x, b_next %p, b_data %p, size %04x\n",
  420. rbd, rbd->count, rbd->b_next, rbd->b_data, rbd->size);
  421. rbd = rbd->v_next;
  422. } while (rbd != lp->rbd_head);
  423. }
  424. #if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
  425. static irqreturn_t i596_error(int irq, void *dev_id)
  426. {
  427. struct net_device *dev = dev_id;
  428. #ifdef ENABLE_MVME16x_NET
  429. if (MACH_IS_MVME16x) {
  430. volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
  431. pcc2[0x28] = 1;
  432. pcc2[0x2b] = 0x1d;
  433. }
  434. #endif
  435. #ifdef ENABLE_BVME6000_NET
  436. if (MACH_IS_BVME6000) {
  437. volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
  438. *ethirq = 1;
  439. *ethirq = 3;
  440. }
  441. #endif
  442. printk(KERN_ERR "%s: Error interrupt\n", dev->name);
  443. i596_display_data(dev);
  444. return IRQ_HANDLED;
  445. }
  446. #endif
  447. static inline void remove_rx_bufs(struct net_device *dev)
  448. {
  449. struct i596_private *lp = dev->ml_priv;
  450. struct i596_rbd *rbd;
  451. int i;
  452. for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
  453. if (rbd->skb == NULL)
  454. break;
  455. dev_kfree_skb(rbd->skb);
  456. rbd->skb = NULL;
  457. }
  458. }
  459. static inline int init_rx_bufs(struct net_device *dev)
  460. {
  461. struct i596_private *lp = dev->ml_priv;
  462. int i;
  463. struct i596_rfd *rfd;
  464. struct i596_rbd *rbd;
  465. /* First build the Receive Buffer Descriptor List */
  466. for (i = 0, rbd = lp->rbds; i < rx_ring_size; i++, rbd++) {
  467. struct sk_buff *skb = netdev_alloc_skb(dev, PKT_BUF_SZ);
  468. if (skb == NULL) {
  469. remove_rx_bufs(dev);
  470. return -ENOMEM;
  471. }
  472. rbd->v_next = rbd+1;
  473. rbd->b_next = WSWAPrbd(virt_to_bus(rbd+1));
  474. rbd->b_addr = WSWAPrbd(virt_to_bus(rbd));
  475. rbd->skb = skb;
  476. rbd->v_data = skb->data;
  477. rbd->b_data = WSWAPchar(virt_to_bus(skb->data));
  478. rbd->size = PKT_BUF_SZ;
  479. #ifdef __mc68000__
  480. cache_clear(virt_to_phys(skb->data), PKT_BUF_SZ);
  481. #endif
  482. }
  483. lp->rbd_head = lp->rbds;
  484. rbd = lp->rbds + rx_ring_size - 1;
  485. rbd->v_next = lp->rbds;
  486. rbd->b_next = WSWAPrbd(virt_to_bus(lp->rbds));
  487. /* Now build the Receive Frame Descriptor List */
  488. for (i = 0, rfd = lp->rfds; i < rx_ring_size; i++, rfd++) {
  489. rfd->rbd = I596_NULL;
  490. rfd->v_next = rfd+1;
  491. rfd->v_prev = rfd-1;
  492. rfd->b_next = WSWAPrfd(virt_to_bus(rfd+1));
  493. rfd->cmd = CMD_FLEX;
  494. }
  495. lp->rfd_head = lp->rfds;
  496. lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds));
  497. rfd = lp->rfds;
  498. rfd->rbd = lp->rbd_head;
  499. rfd->v_prev = lp->rfds + rx_ring_size - 1;
  500. rfd = lp->rfds + rx_ring_size - 1;
  501. rfd->v_next = lp->rfds;
  502. rfd->b_next = WSWAPrfd(virt_to_bus(lp->rfds));
  503. rfd->cmd = CMD_EOL|CMD_FLEX;
  504. return 0;
  505. }
  506. static void rebuild_rx_bufs(struct net_device *dev)
  507. {
  508. struct i596_private *lp = dev->ml_priv;
  509. int i;
  510. /* Ensure rx frame/buffer descriptors are tidy */
  511. for (i = 0; i < rx_ring_size; i++) {
  512. lp->rfds[i].rbd = I596_NULL;
  513. lp->rfds[i].cmd = CMD_FLEX;
  514. }
  515. lp->rfds[rx_ring_size-1].cmd = CMD_EOL|CMD_FLEX;
  516. lp->rfd_head = lp->rfds;
  517. lp->scb.rfd = WSWAPrfd(virt_to_bus(lp->rfds));
  518. lp->rbd_head = lp->rbds;
  519. lp->rfds[0].rbd = WSWAPrbd(virt_to_bus(lp->rbds));
  520. }
  521. static int init_i596_mem(struct net_device *dev)
  522. {
  523. struct i596_private *lp = dev->ml_priv;
  524. unsigned long flags;
  525. MPU_PORT(dev, PORT_RESET, NULL);
  526. udelay(100); /* Wait 100us - seems to help */
  527. #if defined(ENABLE_MVME16x_NET) || defined(ENABLE_BVME6000_NET)
  528. #ifdef ENABLE_MVME16x_NET
  529. if (MACH_IS_MVME16x) {
  530. volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
  531. /* Disable all ints for now */
  532. pcc2[0x28] = 1;
  533. pcc2[0x2a] = 0x48;
  534. /* Following disables snooping. Snooping is not required
  535. * as we make appropriate use of non-cached pages for
  536. * shared data, and cache_push/cache_clear.
  537. */
  538. pcc2[0x2b] = 0x08;
  539. }
  540. #endif
  541. #ifdef ENABLE_BVME6000_NET
  542. if (MACH_IS_BVME6000) {
  543. volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
  544. *ethirq = 1;
  545. }
  546. #endif
  547. /* change the scp address */
  548. MPU_PORT(dev, PORT_ALTSCP, (void *)virt_to_bus((void *)&lp->scp));
  549. #endif
  550. lp->last_cmd = jiffies;
  551. #ifdef ENABLE_MVME16x_NET
  552. if (MACH_IS_MVME16x)
  553. lp->scp.sysbus = 0x00000054;
  554. #endif
  555. #ifdef ENABLE_BVME6000_NET
  556. if (MACH_IS_BVME6000)
  557. lp->scp.sysbus = 0x0000004c;
  558. #endif
  559. lp->scp.iscp = WSWAPiscp(virt_to_bus((void *)&lp->iscp));
  560. lp->iscp.scb = WSWAPscb(virt_to_bus((void *)&lp->scb));
  561. lp->iscp.stat = ISCP_BUSY;
  562. lp->cmd_backlog = 0;
  563. lp->cmd_head = lp->scb.cmd = I596_NULL;
  564. #ifdef ENABLE_BVME6000_NET
  565. if (MACH_IS_BVME6000) {
  566. lp->scb.t_on = 7 * 25;
  567. lp->scb.t_off = 1 * 25;
  568. }
  569. #endif
  570. DEB(DEB_INIT,printk(KERN_DEBUG "%s: starting i82596.\n", dev->name));
  571. CA(dev);
  572. if (wait_istat(dev,lp,1000,"initialization timed out"))
  573. goto failed;
  574. DEB(DEB_INIT,printk(KERN_DEBUG "%s: i82596 initialization successful\n", dev->name));
  575. /* Ensure rx frame/buffer descriptors are tidy */
  576. rebuild_rx_bufs(dev);
  577. lp->scb.command = 0;
  578. #ifdef ENABLE_MVME16x_NET
  579. if (MACH_IS_MVME16x) {
  580. volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
  581. /* Enable ints, etc. now */
  582. pcc2[0x2a] = 0x55; /* Edge sensitive */
  583. pcc2[0x2b] = 0x15;
  584. }
  585. #endif
  586. #ifdef ENABLE_BVME6000_NET
  587. if (MACH_IS_BVME6000) {
  588. volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
  589. *ethirq = 3;
  590. }
  591. #endif
  592. DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdConfigure\n", dev->name));
  593. memcpy(lp->cf_cmd.i596_config, init_setup, 14);
  594. lp->cf_cmd.cmd.command = CmdConfigure;
  595. i596_add_cmd(dev, &lp->cf_cmd.cmd);
  596. DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdSASetup\n", dev->name));
  597. memcpy(lp->sa_cmd.eth_addr, dev->dev_addr, ETH_ALEN);
  598. lp->sa_cmd.cmd.command = CmdSASetup;
  599. i596_add_cmd(dev, &lp->sa_cmd.cmd);
  600. DEB(DEB_INIT,printk(KERN_DEBUG "%s: queuing CmdTDR\n", dev->name));
  601. lp->tdr_cmd.cmd.command = CmdTDR;
  602. i596_add_cmd(dev, &lp->tdr_cmd.cmd);
  603. spin_lock_irqsave (&lp->lock, flags);
  604. if (wait_cmd(dev,lp,1000,"timed out waiting to issue RX_START")) {
  605. spin_unlock_irqrestore (&lp->lock, flags);
  606. goto failed;
  607. }
  608. DEB(DEB_INIT,printk(KERN_DEBUG "%s: Issuing RX_START\n", dev->name));
  609. lp->scb.command = RX_START;
  610. CA(dev);
  611. spin_unlock_irqrestore (&lp->lock, flags);
  612. if (wait_cmd(dev,lp,1000,"RX_START not processed"))
  613. goto failed;
  614. DEB(DEB_INIT,printk(KERN_DEBUG "%s: Receive unit started OK\n", dev->name));
  615. return 0;
  616. failed:
  617. printk(KERN_CRIT "%s: Failed to initialise 82596\n", dev->name);
  618. MPU_PORT(dev, PORT_RESET, NULL);
  619. return -1;
  620. }
  621. static inline int i596_rx(struct net_device *dev)
  622. {
  623. struct i596_private *lp = dev->ml_priv;
  624. struct i596_rfd *rfd;
  625. struct i596_rbd *rbd;
  626. int frames = 0;
  627. DEB(DEB_RXFRAME,printk(KERN_DEBUG "i596_rx(), rfd_head %p, rbd_head %p\n",
  628. lp->rfd_head, lp->rbd_head));
  629. rfd = lp->rfd_head; /* Ref next frame to check */
  630. while ((rfd->stat) & STAT_C) { /* Loop while complete frames */
  631. if (rfd->rbd == I596_NULL)
  632. rbd = I596_NULL;
  633. else if (rfd->rbd == lp->rbd_head->b_addr)
  634. rbd = lp->rbd_head;
  635. else {
  636. printk(KERN_CRIT "%s: rbd chain broken!\n", dev->name);
  637. /* XXX Now what? */
  638. rbd = I596_NULL;
  639. }
  640. DEB(DEB_RXFRAME, printk(KERN_DEBUG " rfd %p, rfd.rbd %p, rfd.stat %04x\n",
  641. rfd, rfd->rbd, rfd->stat));
  642. if (rbd != I596_NULL && ((rfd->stat) & STAT_OK)) {
  643. /* a good frame */
  644. int pkt_len = rbd->count & 0x3fff;
  645. struct sk_buff *skb = rbd->skb;
  646. int rx_in_place = 0;
  647. DEB(DEB_RXADDR,print_eth(rbd->v_data, "received"));
  648. frames++;
  649. /* Check if the packet is long enough to just accept
  650. * without copying to a properly sized skbuff.
  651. */
  652. if (pkt_len > rx_copybreak) {
  653. struct sk_buff *newskb;
  654. /* Get fresh skbuff to replace filled one. */
  655. newskb = netdev_alloc_skb(dev, PKT_BUF_SZ);
  656. if (newskb == NULL) {
  657. skb = NULL; /* drop pkt */
  658. goto memory_squeeze;
  659. }
  660. /* Pass up the skb already on the Rx ring. */
  661. skb_put(skb, pkt_len);
  662. rx_in_place = 1;
  663. rbd->skb = newskb;
  664. rbd->v_data = newskb->data;
  665. rbd->b_data = WSWAPchar(virt_to_bus(newskb->data));
  666. #ifdef __mc68000__
  667. cache_clear(virt_to_phys(newskb->data), PKT_BUF_SZ);
  668. #endif
  669. } else {
  670. skb = netdev_alloc_skb(dev, pkt_len + 2);
  671. }
  672. memory_squeeze:
  673. if (skb == NULL) {
  674. /* XXX tulip.c can defer packets here!! */
  675. dev->stats.rx_dropped++;
  676. } else {
  677. if (!rx_in_place) {
  678. /* 16 byte align the data fields */
  679. skb_reserve(skb, 2);
  680. skb_put_data(skb, rbd->v_data,
  681. pkt_len);
  682. }
  683. skb->protocol=eth_type_trans(skb,dev);
  684. skb->len = pkt_len;
  685. #ifdef __mc68000__
  686. cache_clear(virt_to_phys(rbd->skb->data),
  687. pkt_len);
  688. #endif
  689. netif_rx(skb);
  690. dev->stats.rx_packets++;
  691. dev->stats.rx_bytes+=pkt_len;
  692. }
  693. }
  694. else {
  695. DEB(DEB_ERRORS, printk(KERN_DEBUG "%s: Error, rfd.stat = 0x%04x\n",
  696. dev->name, rfd->stat));
  697. dev->stats.rx_errors++;
  698. if ((rfd->stat) & 0x0001)
  699. dev->stats.collisions++;
  700. if ((rfd->stat) & 0x0080)
  701. dev->stats.rx_length_errors++;
  702. if ((rfd->stat) & 0x0100)
  703. dev->stats.rx_over_errors++;
  704. if ((rfd->stat) & 0x0200)
  705. dev->stats.rx_fifo_errors++;
  706. if ((rfd->stat) & 0x0400)
  707. dev->stats.rx_frame_errors++;
  708. if ((rfd->stat) & 0x0800)
  709. dev->stats.rx_crc_errors++;
  710. if ((rfd->stat) & 0x1000)
  711. dev->stats.rx_length_errors++;
  712. }
  713. /* Clear the buffer descriptor count and EOF + F flags */
  714. if (rbd != I596_NULL && (rbd->count & 0x4000)) {
  715. rbd->count = 0;
  716. lp->rbd_head = rbd->v_next;
  717. }
  718. /* Tidy the frame descriptor, marking it as end of list */
  719. rfd->rbd = I596_NULL;
  720. rfd->stat = 0;
  721. rfd->cmd = CMD_EOL|CMD_FLEX;
  722. rfd->count = 0;
  723. /* Remove end-of-list from old end descriptor */
  724. rfd->v_prev->cmd = CMD_FLEX;
  725. /* Update record of next frame descriptor to process */
  726. lp->scb.rfd = rfd->b_next;
  727. lp->rfd_head = rfd->v_next;
  728. rfd = lp->rfd_head;
  729. }
  730. DEB(DEB_RXFRAME,printk(KERN_DEBUG "frames %d\n", frames));
  731. return 0;
  732. }
  733. static void i596_cleanup_cmd(struct net_device *dev, struct i596_private *lp)
  734. {
  735. struct i596_cmd *ptr;
  736. while (lp->cmd_head != I596_NULL) {
  737. ptr = lp->cmd_head;
  738. lp->cmd_head = ptr->v_next;
  739. lp->cmd_backlog--;
  740. switch ((ptr->command) & 0x7) {
  741. case CmdTx:
  742. {
  743. struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
  744. struct sk_buff *skb = tx_cmd->skb;
  745. dev_kfree_skb(skb);
  746. dev->stats.tx_errors++;
  747. dev->stats.tx_aborted_errors++;
  748. ptr->v_next = ptr->b_next = I596_NULL;
  749. tx_cmd->cmd.command = 0; /* Mark as free */
  750. break;
  751. }
  752. default:
  753. ptr->v_next = ptr->b_next = I596_NULL;
  754. }
  755. }
  756. wait_cmd(dev,lp,100,"i596_cleanup_cmd timed out");
  757. lp->scb.cmd = I596_NULL;
  758. }
  759. static void i596_reset(struct net_device *dev, struct i596_private *lp,
  760. int ioaddr)
  761. {
  762. unsigned long flags;
  763. DEB(DEB_RESET,printk(KERN_DEBUG "i596_reset\n"));
  764. spin_lock_irqsave (&lp->lock, flags);
  765. wait_cmd(dev,lp,100,"i596_reset timed out");
  766. netif_stop_queue(dev);
  767. lp->scb.command = CUC_ABORT | RX_ABORT;
  768. CA(dev);
  769. /* wait for shutdown */
  770. wait_cmd(dev,lp,1000,"i596_reset 2 timed out");
  771. spin_unlock_irqrestore (&lp->lock, flags);
  772. i596_cleanup_cmd(dev,lp);
  773. i596_rx(dev);
  774. netif_start_queue(dev);
  775. init_i596_mem(dev);
  776. }
  777. static void i596_add_cmd(struct net_device *dev, struct i596_cmd *cmd)
  778. {
  779. struct i596_private *lp = dev->ml_priv;
  780. int ioaddr = dev->base_addr;
  781. unsigned long flags;
  782. DEB(DEB_ADDCMD,printk(KERN_DEBUG "i596_add_cmd\n"));
  783. cmd->status = 0;
  784. cmd->command |= (CMD_EOL | CMD_INTR);
  785. cmd->v_next = cmd->b_next = I596_NULL;
  786. spin_lock_irqsave (&lp->lock, flags);
  787. if (lp->cmd_head != I596_NULL) {
  788. lp->cmd_tail->v_next = cmd;
  789. lp->cmd_tail->b_next = WSWAPcmd(virt_to_bus(&cmd->status));
  790. } else {
  791. lp->cmd_head = cmd;
  792. wait_cmd(dev,lp,100,"i596_add_cmd timed out");
  793. lp->scb.cmd = WSWAPcmd(virt_to_bus(&cmd->status));
  794. lp->scb.command = CUC_START;
  795. CA(dev);
  796. }
  797. lp->cmd_tail = cmd;
  798. lp->cmd_backlog++;
  799. spin_unlock_irqrestore (&lp->lock, flags);
  800. if (lp->cmd_backlog > max_cmd_backlog) {
  801. unsigned long tickssofar = jiffies - lp->last_cmd;
  802. if (tickssofar < ticks_limit)
  803. return;
  804. printk(KERN_NOTICE "%s: command unit timed out, status resetting.\n", dev->name);
  805. i596_reset(dev, lp, ioaddr);
  806. }
  807. }
  808. static int i596_open(struct net_device *dev)
  809. {
  810. int res = 0;
  811. DEB(DEB_OPEN,printk(KERN_DEBUG "%s: i596_open() irq %d.\n", dev->name, dev->irq));
  812. if (request_irq(dev->irq, i596_interrupt, 0, "i82596", dev)) {
  813. printk(KERN_ERR "%s: IRQ %d not free\n", dev->name, dev->irq);
  814. return -EAGAIN;
  815. }
  816. #ifdef ENABLE_MVME16x_NET
  817. if (MACH_IS_MVME16x) {
  818. if (request_irq(0x56, i596_error, 0, "i82596_error", dev)) {
  819. res = -EAGAIN;
  820. goto err_irq_dev;
  821. }
  822. }
  823. #endif
  824. res = init_rx_bufs(dev);
  825. if (res)
  826. goto err_irq_56;
  827. netif_start_queue(dev);
  828. if (init_i596_mem(dev)) {
  829. res = -EAGAIN;
  830. goto err_queue;
  831. }
  832. return 0;
  833. err_queue:
  834. netif_stop_queue(dev);
  835. remove_rx_bufs(dev);
  836. err_irq_56:
  837. #ifdef ENABLE_MVME16x_NET
  838. free_irq(0x56, dev);
  839. err_irq_dev:
  840. #endif
  841. free_irq(dev->irq, dev);
  842. return res;
  843. }
  844. static void i596_tx_timeout (struct net_device *dev)
  845. {
  846. struct i596_private *lp = dev->ml_priv;
  847. int ioaddr = dev->base_addr;
  848. /* Transmitter timeout, serious problems. */
  849. DEB(DEB_ERRORS,printk(KERN_ERR "%s: transmit timed out, status resetting.\n",
  850. dev->name));
  851. dev->stats.tx_errors++;
  852. /* Try to restart the adaptor */
  853. if (lp->last_restart == dev->stats.tx_packets) {
  854. DEB(DEB_ERRORS,printk(KERN_ERR "Resetting board.\n"));
  855. /* Shutdown and restart */
  856. i596_reset (dev, lp, ioaddr);
  857. } else {
  858. /* Issue a channel attention signal */
  859. DEB(DEB_ERRORS,printk(KERN_ERR "Kicking board.\n"));
  860. lp->scb.command = CUC_START | RX_START;
  861. CA (dev);
  862. lp->last_restart = dev->stats.tx_packets;
  863. }
  864. netif_trans_update(dev); /* prevent tx timeout */
  865. netif_wake_queue (dev);
  866. }
  867. static netdev_tx_t i596_start_xmit(struct sk_buff *skb, struct net_device *dev)
  868. {
  869. struct i596_private *lp = dev->ml_priv;
  870. struct tx_cmd *tx_cmd;
  871. struct i596_tbd *tbd;
  872. short length = skb->len;
  873. DEB(DEB_STARTTX,printk(KERN_DEBUG "%s: i596_start_xmit(%x,%p) called\n",
  874. dev->name, skb->len, skb->data));
  875. if (skb->len < ETH_ZLEN) {
  876. if (skb_padto(skb, ETH_ZLEN))
  877. return NETDEV_TX_OK;
  878. length = ETH_ZLEN;
  879. }
  880. netif_stop_queue(dev);
  881. tx_cmd = lp->tx_cmds + lp->next_tx_cmd;
  882. tbd = lp->tbds + lp->next_tx_cmd;
  883. if (tx_cmd->cmd.command) {
  884. printk(KERN_NOTICE "%s: xmit ring full, dropping packet.\n",
  885. dev->name);
  886. dev->stats.tx_dropped++;
  887. dev_kfree_skb(skb);
  888. } else {
  889. if (++lp->next_tx_cmd == TX_RING_SIZE)
  890. lp->next_tx_cmd = 0;
  891. tx_cmd->tbd = WSWAPtbd(virt_to_bus(tbd));
  892. tbd->next = I596_NULL;
  893. tx_cmd->cmd.command = CMD_FLEX | CmdTx;
  894. tx_cmd->skb = skb;
  895. tx_cmd->pad = 0;
  896. tx_cmd->size = 0;
  897. tbd->pad = 0;
  898. tbd->size = EOF | length;
  899. tbd->data = WSWAPchar(virt_to_bus(skb->data));
  900. #ifdef __mc68000__
  901. cache_push(virt_to_phys(skb->data), length);
  902. #endif
  903. DEB(DEB_TXADDR,print_eth(skb->data, "tx-queued"));
  904. i596_add_cmd(dev, &tx_cmd->cmd);
  905. dev->stats.tx_packets++;
  906. dev->stats.tx_bytes += length;
  907. }
  908. netif_start_queue(dev);
  909. return NETDEV_TX_OK;
  910. }
  911. static void print_eth(unsigned char *add, char *str)
  912. {
  913. printk(KERN_DEBUG "i596 0x%p, %pM --> %pM %02X%02X, %s\n",
  914. add, add + 6, add, add[12], add[13], str);
  915. }
  916. static int io = 0x300;
  917. static int irq = 10;
  918. static const struct net_device_ops i596_netdev_ops = {
  919. .ndo_open = i596_open,
  920. .ndo_stop = i596_close,
  921. .ndo_start_xmit = i596_start_xmit,
  922. .ndo_set_rx_mode = set_multicast_list,
  923. .ndo_tx_timeout = i596_tx_timeout,
  924. .ndo_set_mac_address = eth_mac_addr,
  925. .ndo_validate_addr = eth_validate_addr,
  926. };
  927. struct net_device * __init i82596_probe(int unit)
  928. {
  929. struct net_device *dev;
  930. int i;
  931. struct i596_private *lp;
  932. char eth_addr[8];
  933. static int probed;
  934. int err;
  935. if (probed)
  936. return ERR_PTR(-ENODEV);
  937. probed++;
  938. dev = alloc_etherdev(0);
  939. if (!dev)
  940. return ERR_PTR(-ENOMEM);
  941. if (unit >= 0) {
  942. sprintf(dev->name, "eth%d", unit);
  943. netdev_boot_setup_check(dev);
  944. } else {
  945. dev->base_addr = io;
  946. dev->irq = irq;
  947. }
  948. #ifdef ENABLE_MVME16x_NET
  949. if (MACH_IS_MVME16x) {
  950. if (mvme16x_config & MVME16x_CONFIG_NO_ETHERNET) {
  951. printk(KERN_NOTICE "Ethernet probe disabled - chip not present\n");
  952. err = -ENODEV;
  953. goto out;
  954. }
  955. memcpy(eth_addr, absolute_pointer(0xfffc1f2c), ETH_ALEN); /* YUCK! Get addr from NOVRAM */
  956. dev->base_addr = MVME_I596_BASE;
  957. dev->irq = (unsigned) MVME16x_IRQ_I596;
  958. goto found;
  959. }
  960. #endif
  961. #ifdef ENABLE_BVME6000_NET
  962. if (MACH_IS_BVME6000) {
  963. volatile unsigned char *rtc = (unsigned char *) BVME_RTC_BASE;
  964. unsigned char msr = rtc[3];
  965. int i;
  966. rtc[3] |= 0x80;
  967. for (i = 0; i < 6; i++)
  968. eth_addr[i] = rtc[i * 4 + 7]; /* Stored in RTC RAM at offset 1 */
  969. rtc[3] = msr;
  970. dev->base_addr = BVME_I596_BASE;
  971. dev->irq = (unsigned) BVME_IRQ_I596;
  972. goto found;
  973. }
  974. #endif
  975. err = -ENODEV;
  976. goto out;
  977. found:
  978. dev->mem_start = (int)__get_free_pages(GFP_ATOMIC, 0);
  979. if (!dev->mem_start) {
  980. err = -ENOMEM;
  981. goto out1;
  982. }
  983. DEB(DEB_PROBE,printk(KERN_INFO "%s: 82596 at %#3lx,", dev->name, dev->base_addr));
  984. for (i = 0; i < 6; i++)
  985. DEB(DEB_PROBE,printk(" %2.2X", dev->dev_addr[i] = eth_addr[i]));
  986. DEB(DEB_PROBE,printk(" IRQ %d.\n", dev->irq));
  987. DEB(DEB_PROBE,printk(KERN_INFO "%s", version));
  988. /* The 82596-specific entries in the device structure. */
  989. dev->netdev_ops = &i596_netdev_ops;
  990. dev->watchdog_timeo = TX_TIMEOUT;
  991. dev->ml_priv = (void *)(dev->mem_start);
  992. lp = dev->ml_priv;
  993. DEB(DEB_INIT,printk(KERN_DEBUG "%s: lp at 0x%08lx (%zd bytes), "
  994. "lp->scb at 0x%08lx\n",
  995. dev->name, (unsigned long)lp,
  996. sizeof(struct i596_private), (unsigned long)&lp->scb));
  997. memset((void *) lp, 0, sizeof(struct i596_private));
  998. #ifdef __mc68000__
  999. cache_push(virt_to_phys((void *)(dev->mem_start)), 4096);
  1000. cache_clear(virt_to_phys((void *)(dev->mem_start)), 4096);
  1001. kernel_set_cachemode((void *)(dev->mem_start), 4096, IOMAP_NOCACHE_SER);
  1002. #endif
  1003. lp->scb.command = 0;
  1004. lp->scb.cmd = I596_NULL;
  1005. lp->scb.rfd = I596_NULL;
  1006. spin_lock_init(&lp->lock);
  1007. err = register_netdev(dev);
  1008. if (err)
  1009. goto out2;
  1010. return dev;
  1011. out2:
  1012. #ifdef __mc68000__
  1013. /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING,
  1014. * XXX which may be invalid (CONFIG_060_WRITETHROUGH)
  1015. */
  1016. kernel_set_cachemode((void *)(dev->mem_start), 4096,
  1017. IOMAP_FULL_CACHING);
  1018. #endif
  1019. free_page ((u32)(dev->mem_start));
  1020. out1:
  1021. out:
  1022. free_netdev(dev);
  1023. return ERR_PTR(err);
  1024. }
  1025. static irqreturn_t i596_interrupt(int irq, void *dev_id)
  1026. {
  1027. struct net_device *dev = dev_id;
  1028. struct i596_private *lp;
  1029. short ioaddr;
  1030. unsigned short status, ack_cmd = 0;
  1031. int handled = 0;
  1032. #ifdef ENABLE_BVME6000_NET
  1033. if (MACH_IS_BVME6000) {
  1034. if (*(char *) BVME_LOCAL_IRQ_STAT & BVME_ETHERR) {
  1035. i596_error(irq, dev_id);
  1036. return IRQ_HANDLED;
  1037. }
  1038. }
  1039. #endif
  1040. if (dev == NULL) {
  1041. printk(KERN_ERR "i596_interrupt(): irq %d for unknown device.\n", irq);
  1042. return IRQ_NONE;
  1043. }
  1044. ioaddr = dev->base_addr;
  1045. lp = dev->ml_priv;
  1046. spin_lock (&lp->lock);
  1047. wait_cmd(dev,lp,100,"i596 interrupt, timeout");
  1048. status = lp->scb.status;
  1049. DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt, IRQ %d, status %4.4x.\n",
  1050. dev->name, irq, status));
  1051. ack_cmd = status & 0xf000;
  1052. if ((status & 0x8000) || (status & 0x2000)) {
  1053. struct i596_cmd *ptr;
  1054. handled = 1;
  1055. if ((status & 0x8000))
  1056. DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt completed command.\n", dev->name));
  1057. if ((status & 0x2000))
  1058. DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt command unit inactive %x.\n", dev->name, status & 0x0700));
  1059. while ((lp->cmd_head != I596_NULL) && (lp->cmd_head->status & STAT_C)) {
  1060. ptr = lp->cmd_head;
  1061. DEB(DEB_STATUS,printk(KERN_DEBUG "cmd_head->status = %04x, ->command = %04x\n",
  1062. lp->cmd_head->status, lp->cmd_head->command));
  1063. lp->cmd_head = ptr->v_next;
  1064. lp->cmd_backlog--;
  1065. switch ((ptr->command) & 0x7) {
  1066. case CmdTx:
  1067. {
  1068. struct tx_cmd *tx_cmd = (struct tx_cmd *) ptr;
  1069. struct sk_buff *skb = tx_cmd->skb;
  1070. if ((ptr->status) & STAT_OK) {
  1071. DEB(DEB_TXADDR,print_eth(skb->data, "tx-done"));
  1072. } else {
  1073. dev->stats.tx_errors++;
  1074. if ((ptr->status) & 0x0020)
  1075. dev->stats.collisions++;
  1076. if (!((ptr->status) & 0x0040))
  1077. dev->stats.tx_heartbeat_errors++;
  1078. if ((ptr->status) & 0x0400)
  1079. dev->stats.tx_carrier_errors++;
  1080. if ((ptr->status) & 0x0800)
  1081. dev->stats.collisions++;
  1082. if ((ptr->status) & 0x1000)
  1083. dev->stats.tx_aborted_errors++;
  1084. }
  1085. dev_consume_skb_irq(skb);
  1086. tx_cmd->cmd.command = 0; /* Mark free */
  1087. break;
  1088. }
  1089. case CmdTDR:
  1090. {
  1091. unsigned short status = ((struct tdr_cmd *)ptr)->status;
  1092. if (status & 0x8000) {
  1093. DEB(DEB_TDR,printk(KERN_INFO "%s: link ok.\n", dev->name));
  1094. } else {
  1095. if (status & 0x4000)
  1096. printk(KERN_ERR "%s: Transceiver problem.\n", dev->name);
  1097. if (status & 0x2000)
  1098. printk(KERN_ERR "%s: Termination problem.\n", dev->name);
  1099. if (status & 0x1000)
  1100. printk(KERN_ERR "%s: Short circuit.\n", dev->name);
  1101. DEB(DEB_TDR,printk(KERN_INFO "%s: Time %d.\n", dev->name, status & 0x07ff));
  1102. }
  1103. break;
  1104. }
  1105. case CmdConfigure:
  1106. case CmdMulticastList:
  1107. /* Zap command so set_multicast_list() knows it is free */
  1108. ptr->command = 0;
  1109. break;
  1110. }
  1111. ptr->v_next = ptr->b_next = I596_NULL;
  1112. lp->last_cmd = jiffies;
  1113. }
  1114. ptr = lp->cmd_head;
  1115. while ((ptr != I596_NULL) && (ptr != lp->cmd_tail)) {
  1116. ptr->command &= 0x1fff;
  1117. ptr = ptr->v_next;
  1118. }
  1119. if ((lp->cmd_head != I596_NULL))
  1120. ack_cmd |= CUC_START;
  1121. lp->scb.cmd = WSWAPcmd(virt_to_bus(&lp->cmd_head->status));
  1122. }
  1123. if ((status & 0x1000) || (status & 0x4000)) {
  1124. if ((status & 0x4000))
  1125. DEB(DEB_INTS,printk(KERN_DEBUG "%s: i596 interrupt received a frame.\n", dev->name));
  1126. i596_rx(dev);
  1127. /* Only RX_START if stopped - RGH 07-07-96 */
  1128. if (status & 0x1000) {
  1129. if (netif_running(dev)) {
  1130. DEB(DEB_ERRORS,printk(KERN_ERR "%s: i596 interrupt receive unit inactive, status 0x%x\n", dev->name, status));
  1131. ack_cmd |= RX_START;
  1132. dev->stats.rx_errors++;
  1133. dev->stats.rx_fifo_errors++;
  1134. rebuild_rx_bufs(dev);
  1135. }
  1136. }
  1137. }
  1138. wait_cmd(dev,lp,100,"i596 interrupt, timeout");
  1139. lp->scb.command = ack_cmd;
  1140. #ifdef ENABLE_MVME16x_NET
  1141. if (MACH_IS_MVME16x) {
  1142. /* Ack the interrupt */
  1143. volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
  1144. pcc2[0x2a] |= 0x08;
  1145. }
  1146. #endif
  1147. #ifdef ENABLE_BVME6000_NET
  1148. if (MACH_IS_BVME6000) {
  1149. volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
  1150. *ethirq = 1;
  1151. *ethirq = 3;
  1152. }
  1153. #endif
  1154. CA(dev);
  1155. DEB(DEB_INTS,printk(KERN_DEBUG "%s: exiting interrupt.\n", dev->name));
  1156. spin_unlock (&lp->lock);
  1157. return IRQ_RETVAL(handled);
  1158. }
  1159. static int i596_close(struct net_device *dev)
  1160. {
  1161. struct i596_private *lp = dev->ml_priv;
  1162. unsigned long flags;
  1163. netif_stop_queue(dev);
  1164. DEB(DEB_INIT,printk(KERN_DEBUG "%s: Shutting down ethercard, status was %4.4x.\n",
  1165. dev->name, lp->scb.status));
  1166. spin_lock_irqsave(&lp->lock, flags);
  1167. wait_cmd(dev,lp,100,"close1 timed out");
  1168. lp->scb.command = CUC_ABORT | RX_ABORT;
  1169. CA(dev);
  1170. wait_cmd(dev,lp,100,"close2 timed out");
  1171. spin_unlock_irqrestore(&lp->lock, flags);
  1172. DEB(DEB_STRUCT,i596_display_data(dev));
  1173. i596_cleanup_cmd(dev,lp);
  1174. #ifdef ENABLE_MVME16x_NET
  1175. if (MACH_IS_MVME16x) {
  1176. volatile unsigned char *pcc2 = (unsigned char *) 0xfff42000;
  1177. /* Disable all ints */
  1178. pcc2[0x28] = 1;
  1179. pcc2[0x2a] = 0x40;
  1180. pcc2[0x2b] = 0x40; /* Set snooping bits now! */
  1181. }
  1182. #endif
  1183. #ifdef ENABLE_BVME6000_NET
  1184. if (MACH_IS_BVME6000) {
  1185. volatile unsigned char *ethirq = (unsigned char *) BVME_ETHIRQ_REG;
  1186. *ethirq = 1;
  1187. }
  1188. #endif
  1189. #ifdef ENABLE_MVME16x_NET
  1190. free_irq(0x56, dev);
  1191. #endif
  1192. free_irq(dev->irq, dev);
  1193. remove_rx_bufs(dev);
  1194. return 0;
  1195. }
  1196. /*
  1197. * Set or clear the multicast filter for this adaptor.
  1198. */
  1199. static void set_multicast_list(struct net_device *dev)
  1200. {
  1201. struct i596_private *lp = dev->ml_priv;
  1202. int config = 0, cnt;
  1203. DEB(DEB_MULTI,printk(KERN_DEBUG "%s: set multicast list, %d entries, promisc %s, allmulti %s\n",
  1204. dev->name, netdev_mc_count(dev),
  1205. dev->flags & IFF_PROMISC ? "ON" : "OFF",
  1206. dev->flags & IFF_ALLMULTI ? "ON" : "OFF"));
  1207. if (wait_cfg(dev, &lp->cf_cmd.cmd, 1000, "config change request timed out"))
  1208. return;
  1209. if ((dev->flags & IFF_PROMISC) && !(lp->cf_cmd.i596_config[8] & 0x01)) {
  1210. lp->cf_cmd.i596_config[8] |= 0x01;
  1211. config = 1;
  1212. }
  1213. if (!(dev->flags & IFF_PROMISC) && (lp->cf_cmd.i596_config[8] & 0x01)) {
  1214. lp->cf_cmd.i596_config[8] &= ~0x01;
  1215. config = 1;
  1216. }
  1217. if ((dev->flags & IFF_ALLMULTI) && (lp->cf_cmd.i596_config[11] & 0x20)) {
  1218. lp->cf_cmd.i596_config[11] &= ~0x20;
  1219. config = 1;
  1220. }
  1221. if (!(dev->flags & IFF_ALLMULTI) && !(lp->cf_cmd.i596_config[11] & 0x20)) {
  1222. lp->cf_cmd.i596_config[11] |= 0x20;
  1223. config = 1;
  1224. }
  1225. if (config) {
  1226. lp->cf_cmd.cmd.command = CmdConfigure;
  1227. i596_add_cmd(dev, &lp->cf_cmd.cmd);
  1228. }
  1229. cnt = netdev_mc_count(dev);
  1230. if (cnt > MAX_MC_CNT)
  1231. {
  1232. cnt = MAX_MC_CNT;
  1233. printk(KERN_ERR "%s: Only %d multicast addresses supported",
  1234. dev->name, cnt);
  1235. }
  1236. if (!netdev_mc_empty(dev)) {
  1237. struct netdev_hw_addr *ha;
  1238. unsigned char *cp;
  1239. struct mc_cmd *cmd;
  1240. if (wait_cfg(dev, &lp->mc_cmd.cmd, 1000, "multicast list change request timed out"))
  1241. return;
  1242. cmd = &lp->mc_cmd;
  1243. cmd->cmd.command = CmdMulticastList;
  1244. cmd->mc_cnt = cnt * ETH_ALEN;
  1245. cp = cmd->mc_addrs;
  1246. netdev_for_each_mc_addr(ha, dev) {
  1247. if (!cnt--)
  1248. break;
  1249. memcpy(cp, ha->addr, ETH_ALEN);
  1250. if (i596_debug > 1)
  1251. DEB(DEB_MULTI,printk(KERN_INFO "%s: Adding address %pM\n",
  1252. dev->name, cp));
  1253. cp += ETH_ALEN;
  1254. }
  1255. i596_add_cmd(dev, &cmd->cmd);
  1256. }
  1257. }
  1258. #ifdef MODULE
  1259. static struct net_device *dev_82596;
  1260. static int debug = -1;
  1261. module_param(debug, int, 0);
  1262. MODULE_PARM_DESC(debug, "i82596 debug mask");
  1263. int __init init_module(void)
  1264. {
  1265. if (debug >= 0)
  1266. i596_debug = debug;
  1267. dev_82596 = i82596_probe(-1);
  1268. return PTR_ERR_OR_ZERO(dev_82596);
  1269. }
  1270. void __exit cleanup_module(void)
  1271. {
  1272. unregister_netdev(dev_82596);
  1273. #ifdef __mc68000__
  1274. /* XXX This assumes default cache mode to be IOMAP_FULL_CACHING,
  1275. * XXX which may be invalid (CONFIG_060_WRITETHROUGH)
  1276. */
  1277. kernel_set_cachemode((void *)(dev_82596->mem_start), 4096,
  1278. IOMAP_FULL_CACHING);
  1279. #endif
  1280. free_page ((u32)(dev_82596->mem_start));
  1281. free_netdev(dev_82596);
  1282. }
  1283. #endif /* MODULE */