82596.c 40 KB

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