dgrs.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615
  1. /*
  2. * Digi RightSwitch SE-X loadable device driver for Linux
  3. *
  4. * The RightSwitch is a 4 (EISA) or 6 (PCI) port etherswitch and
  5. * a NIC on an internal board.
  6. *
  7. * Author: Rick Richardson, rick@remotepoint.com
  8. * Derived from the SVR4.2 (UnixWare) driver for the same card.
  9. *
  10. * Copyright 1995-1996 Digi International Inc.
  11. *
  12. * This software may be used and distributed according to the terms
  13. * of the GNU General Public License, incorporated herein by reference.
  14. *
  15. * For information on purchasing a RightSwitch SE-4 or SE-6
  16. * board, please contact Digi's sales department at 1-612-912-3444
  17. * or 1-800-DIGIBRD. Outside the U.S., please check our Web page
  18. * at http://www.dgii.com for sales offices worldwide.
  19. *
  20. * OPERATION:
  21. * When compiled as a loadable module, this driver can operate
  22. * the board as either a 4/6 port switch with a 5th or 7th port
  23. * that is a conventional NIC interface as far as the host is
  24. * concerned, OR as 4/6 independent NICs. To select multi-NIC
  25. * mode, add "nicmode=1" on the insmod load line for the driver.
  26. *
  27. * This driver uses the "dev" common ethernet device structure
  28. * and a private "priv" (dev->priv) structure that contains
  29. * mostly DGRS-specific information and statistics. To keep
  30. * the code for both the switch mode and the multi-NIC mode
  31. * as similar as possible, I have introduced the concept of
  32. * "dev0"/"priv0" and "devN"/"privN" pointer pairs in subroutines
  33. * where needed. The first pair of pointers points to the
  34. * "dev" and "priv" structures of the zeroth (0th) device
  35. * interface associated with a board. The second pair of
  36. * pointers points to the current (Nth) device interface
  37. * for the board: the one for which we are processing data.
  38. *
  39. * In switch mode, the pairs of pointers are always the same,
  40. * that is, dev0 == devN and priv0 == privN. This is just
  41. * like previous releases of this driver which did not support
  42. * NIC mode.
  43. *
  44. * In multi-NIC mode, the pairs of pointers may be different.
  45. * We use the devN and privN pointers to reference just the
  46. * name, port number, and statistics for the current interface.
  47. * We use the dev0 and priv0 pointers to access the variables
  48. * that control access to the board, such as board address
  49. * and simulated 82596 variables. This is because there is
  50. * only one "fake" 82596 that serves as the interface to
  51. * the board. We do not want to try to keep the variables
  52. * associated with this 82596 in sync across all devices.
  53. *
  54. * This scheme works well. As you will see, except for
  55. * initialization, there is very little difference between
  56. * the two modes as far as this driver is concerned. On the
  57. * receive side in NIC mode, the interrupt *always* comes in on
  58. * the 0th interface (dev0/priv0). We then figure out which
  59. * real 82596 port it came in on from looking at the "chan"
  60. * member that the board firmware adds at the end of each
  61. * RBD (a.k.a. TBD). We get the channel number like this:
  62. * int chan = ((I596_RBD *) S2H(cbp->xmit.tbdp))->chan;
  63. *
  64. * On the transmit side in multi-NIC mode, we specify the
  65. * output 82596 port by setting the new "dstchan" structure
  66. * member that is at the end of the RFD, like this:
  67. * priv0->rfdp->dstchan = privN->chan;
  68. *
  69. * TODO:
  70. * - Multi-NIC mode is not yet supported when the driver is linked
  71. * into the kernel.
  72. * - Better handling of multicast addresses.
  73. *
  74. * Fixes:
  75. * Arnaldo Carvalho de Melo <acme@conectiva.com.br> - 11/01/2001
  76. * - fix dgrs_found_device wrt checking kmalloc return and
  77. * rollbacking the partial steps of the whole process when
  78. * one of the devices can't be allocated. Fix SET_MODULE_OWNER
  79. * on the loop to use devN instead of repeated calls to dev.
  80. *
  81. * davej <davej@suse.de> - 9/2/2001
  82. * - Enable PCI device before reading ioaddr/irq
  83. *
  84. */
  85. #include <linux/module.h>
  86. #include <linux/eisa.h>
  87. #include <linux/kernel.h>
  88. #include <linux/string.h>
  89. #include <linux/delay.h>
  90. #include <linux/errno.h>
  91. #include <linux/ioport.h>
  92. #include <linux/slab.h>
  93. #include <linux/interrupt.h>
  94. #include <linux/pci.h>
  95. #include <linux/init.h>
  96. #include <linux/netdevice.h>
  97. #include <linux/etherdevice.h>
  98. #include <linux/skbuff.h>
  99. #include <linux/bitops.h>
  100. #include <asm/io.h>
  101. #include <asm/byteorder.h>
  102. #include <asm/uaccess.h>
  103. static char version[] __initdata =
  104. "$Id: dgrs.c,v 1.13 2000/06/06 04:07:00 rick Exp $";
  105. /*
  106. * DGRS include files
  107. */
  108. typedef unsigned char uchar;
  109. #define vol volatile
  110. #include "dgrs.h"
  111. #include "dgrs_es4h.h"
  112. #include "dgrs_plx9060.h"
  113. #include "dgrs_i82596.h"
  114. #include "dgrs_ether.h"
  115. #include "dgrs_asstruct.h"
  116. #include "dgrs_bcomm.h"
  117. #ifdef CONFIG_PCI
  118. static struct pci_device_id dgrs_pci_tbl[] = {
  119. { SE6_PCI_VENDOR_ID, SE6_PCI_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, },
  120. { } /* Terminating entry */
  121. };
  122. MODULE_DEVICE_TABLE(pci, dgrs_pci_tbl);
  123. #endif
  124. #ifdef CONFIG_EISA
  125. static struct eisa_device_id dgrs_eisa_tbl[] = {
  126. { "DBI0A01" },
  127. { }
  128. };
  129. MODULE_DEVICE_TABLE(eisa, dgrs_eisa_tbl);
  130. #endif
  131. MODULE_LICENSE("GPL");
  132. /*
  133. * Firmware. Compiled separately for local compilation,
  134. * but #included for Linux distribution.
  135. */
  136. #ifndef NOFW
  137. #include "dgrs_firmware.c"
  138. #else
  139. extern int dgrs_firmnum;
  140. extern char dgrs_firmver[];
  141. extern char dgrs_firmdate[];
  142. extern uchar dgrs_code[];
  143. extern int dgrs_ncode;
  144. #endif
  145. /*
  146. * Linux out*() is backwards from all other operating systems
  147. */
  148. #define OUTB(ADDR, VAL) outb(VAL, ADDR)
  149. #define OUTW(ADDR, VAL) outw(VAL, ADDR)
  150. #define OUTL(ADDR, VAL) outl(VAL, ADDR)
  151. /*
  152. * Macros to convert switch to host and host to switch addresses
  153. * (assumes a local variable priv points to board dependent struct)
  154. */
  155. #define S2H(A) ( ((unsigned long)(A)&0x00ffffff) + priv0->vmem )
  156. #define S2HN(A) ( ((unsigned long)(A)&0x00ffffff) + privN->vmem )
  157. #define H2S(A) ( ((char *) (A) - priv0->vmem) + 0xA3000000 )
  158. /*
  159. * Convert a switch address to a "safe" address for use with the
  160. * PLX 9060 DMA registers and the associated HW kludge that allows
  161. * for host access of the DMA registers.
  162. */
  163. #define S2DMA(A) ( (unsigned long)(A) & 0x00ffffff)
  164. /*
  165. * "Space.c" variables, now settable from module interface
  166. * Use the name below, minus the "dgrs_" prefix. See init_module().
  167. */
  168. static int dgrs_debug = 1;
  169. static int dgrs_dma = 1;
  170. static int dgrs_spantree = -1;
  171. static int dgrs_hashexpire = -1;
  172. static uchar dgrs_ipaddr[4] = { 0xff, 0xff, 0xff, 0xff};
  173. static uchar dgrs_iptrap[4] = { 0xff, 0xff, 0xff, 0xff};
  174. static __u32 dgrs_ipxnet = -1;
  175. static int dgrs_nicmode;
  176. /*
  177. * Private per-board data structure (dev->priv)
  178. */
  179. typedef struct
  180. {
  181. /*
  182. * Stuff for generic ethercard I/F
  183. */
  184. struct net_device_stats stats;
  185. /*
  186. * DGRS specific data
  187. */
  188. char *vmem;
  189. struct bios_comm *bcomm; /* Firmware BIOS comm structure */
  190. PORT *port; /* Ptr to PORT[0] struct in VM */
  191. I596_SCB *scbp; /* Ptr to SCB struct in VM */
  192. I596_RFD *rfdp; /* Current RFD list */
  193. I596_RBD *rbdp; /* Current RBD list */
  194. volatile int intrcnt; /* Count of interrupts */
  195. /*
  196. * SE-4 (EISA) board variables
  197. */
  198. uchar is_reg; /* EISA: Value for ES4H_IS reg */
  199. /*
  200. * SE-6 (PCI) board variables
  201. *
  202. * The PLX "expansion rom" space is used for DMA register
  203. * access from the host on the SE-6. These are the physical
  204. * and virtual addresses of that space.
  205. */
  206. ulong plxreg; /* Phys address of PLX chip */
  207. char *vplxreg; /* Virtual address of PLX chip */
  208. ulong plxdma; /* Phys addr of PLX "expansion rom" */
  209. ulong volatile *vplxdma; /* Virtual addr of "expansion rom" */
  210. int use_dma; /* Flag: use DMA */
  211. DMACHAIN *dmadesc_s; /* area for DMA chains (SW addr.) */
  212. DMACHAIN *dmadesc_h; /* area for DMA chains (Host Virtual) */
  213. /*
  214. * Multi-NIC mode variables
  215. *
  216. * All entries of the devtbl[] array are valid for the 0th
  217. * device (i.e. eth0, but not eth1...eth5). devtbl[0] is
  218. * valid for all devices (i.e. eth0, eth1, ..., eth5).
  219. */
  220. int nports; /* Number of physical ports (4 or 6) */
  221. int chan; /* Channel # (1-6) for this device */
  222. struct net_device *devtbl[6]; /* Ptrs to N device structs */
  223. } DGRS_PRIV;
  224. /*
  225. * reset or un-reset the IDT processor
  226. */
  227. static void
  228. proc_reset(struct net_device *dev0, int reset)
  229. {
  230. DGRS_PRIV *priv0 = (DGRS_PRIV *) dev0->priv;
  231. if (priv0->plxreg)
  232. {
  233. ulong val;
  234. val = inl(dev0->base_addr + PLX_MISC_CSR);
  235. if (reset)
  236. val |= SE6_RESET;
  237. else
  238. val &= ~SE6_RESET;
  239. OUTL(dev0->base_addr + PLX_MISC_CSR, val);
  240. }
  241. else
  242. {
  243. OUTB(dev0->base_addr + ES4H_PC, reset ? ES4H_PC_RESET : 0);
  244. }
  245. }
  246. /*
  247. * See if the board supports bus master DMA
  248. */
  249. static int
  250. check_board_dma(struct net_device *dev0)
  251. {
  252. DGRS_PRIV *priv0 = (DGRS_PRIV *) dev0->priv;
  253. ulong x;
  254. /*
  255. * If Space.c says not to use DMA, or if it's not a PLX based
  256. * PCI board, or if the expansion ROM space is not PCI
  257. * configured, then return false.
  258. */
  259. if (!dgrs_dma || !priv0->plxreg || !priv0->plxdma)
  260. return (0);
  261. /*
  262. * Set the local address remap register of the "expansion rom"
  263. * area to 0x80000000 so that we can use it to access the DMA
  264. * registers from the host side.
  265. */
  266. OUTL(dev0->base_addr + PLX_ROM_BASE_ADDR, 0x80000000);
  267. /*
  268. * Set the PCI region descriptor to:
  269. * Space 0:
  270. * disable read-prefetch
  271. * enable READY
  272. * enable BURST
  273. * 0 internal wait states
  274. * Expansion ROM: (used for host DMA register access)
  275. * disable read-prefetch
  276. * enable READY
  277. * disable BURST
  278. * 0 internal wait states
  279. */
  280. OUTL(dev0->base_addr + PLX_BUS_REGION, 0x49430343);
  281. /*
  282. * Now map the DMA registers into our virtual space
  283. */
  284. priv0->vplxdma = (ulong *) ioremap (priv0->plxdma, 256);
  285. if (!priv0->vplxdma)
  286. {
  287. printk("%s: can't *remap() the DMA regs\n", dev0->name);
  288. return (0);
  289. }
  290. /*
  291. * Now test to see if we can access the DMA registers
  292. * If we write -1 and get back 1FFF, then we accessed the
  293. * DMA register. Otherwise, we probably have an old board
  294. * and wrote into regular RAM.
  295. */
  296. priv0->vplxdma[PLX_DMA0_MODE/4] = 0xFFFFFFFF;
  297. x = priv0->vplxdma[PLX_DMA0_MODE/4];
  298. if (x != 0x00001FFF) {
  299. iounmap((void *)priv0->vplxdma);
  300. return (0);
  301. }
  302. return (1);
  303. }
  304. /*
  305. * Initiate DMA using PLX part on PCI board. Spin the
  306. * processor until completed. All addresses are physical!
  307. *
  308. * If pciaddr is NULL, then it's a chaining DMA, and lcladdr is
  309. * the address of the first DMA descriptor in the chain.
  310. *
  311. * If pciaddr is not NULL, then it's a single DMA.
  312. *
  313. * In either case, "lcladdr" must have been fixed up to make
  314. * sure the MSB isn't set using the S2DMA macro before passing
  315. * the address to this routine.
  316. */
  317. static int
  318. do_plx_dma(
  319. struct net_device *dev,
  320. ulong pciaddr,
  321. ulong lcladdr,
  322. int len,
  323. int to_host
  324. )
  325. {
  326. int i;
  327. ulong csr = 0;
  328. DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
  329. if (pciaddr)
  330. {
  331. /*
  332. * Do a single, non-chain DMA
  333. */
  334. priv->vplxdma[PLX_DMA0_PCI_ADDR/4] = pciaddr;
  335. priv->vplxdma[PLX_DMA0_LCL_ADDR/4] = lcladdr;
  336. priv->vplxdma[PLX_DMA0_SIZE/4] = len;
  337. priv->vplxdma[PLX_DMA0_DESCRIPTOR/4] = to_host
  338. ? PLX_DMA_DESC_TO_HOST
  339. : PLX_DMA_DESC_TO_BOARD;
  340. priv->vplxdma[PLX_DMA0_MODE/4] =
  341. PLX_DMA_MODE_WIDTH32
  342. | PLX_DMA_MODE_WAITSTATES(0)
  343. | PLX_DMA_MODE_READY
  344. | PLX_DMA_MODE_NOBTERM
  345. | PLX_DMA_MODE_BURST
  346. | PLX_DMA_MODE_NOCHAIN;
  347. }
  348. else
  349. {
  350. /*
  351. * Do a chaining DMA
  352. */
  353. priv->vplxdma[PLX_DMA0_MODE/4] =
  354. PLX_DMA_MODE_WIDTH32
  355. | PLX_DMA_MODE_WAITSTATES(0)
  356. | PLX_DMA_MODE_READY
  357. | PLX_DMA_MODE_NOBTERM
  358. | PLX_DMA_MODE_BURST
  359. | PLX_DMA_MODE_CHAIN;
  360. priv->vplxdma[PLX_DMA0_DESCRIPTOR/4] = lcladdr;
  361. }
  362. priv->vplxdma[PLX_DMA_CSR/4] =
  363. PLX_DMA_CSR_0_ENABLE | PLX_DMA_CSR_0_START;
  364. /*
  365. * Wait for DMA to complete
  366. */
  367. for (i = 0; i < 1000000; ++i)
  368. {
  369. /*
  370. * Spin the host CPU for 1 usec, so we don't thrash
  371. * the PCI bus while the PLX 9060 is doing DMA.
  372. */
  373. udelay(1);
  374. csr = (volatile unsigned long) priv->vplxdma[PLX_DMA_CSR/4];
  375. if (csr & PLX_DMA_CSR_0_DONE)
  376. break;
  377. }
  378. if ( ! (csr & PLX_DMA_CSR_0_DONE) )
  379. {
  380. printk("%s: DMA done never occurred. DMA disabled.\n",
  381. dev->name);
  382. priv->use_dma = 0;
  383. return 1;
  384. }
  385. return 0;
  386. }
  387. /*
  388. * dgrs_rcv_frame()
  389. *
  390. * Process a received frame. This is called from the interrupt
  391. * routine, and works for both switch mode and multi-NIC mode.
  392. *
  393. * Note that when in multi-NIC mode, we want to always access the
  394. * hardware using the dev and priv structures of the first port,
  395. * so that we are using only one set of variables to maintain
  396. * the board interface status, but we want to use the Nth port
  397. * dev and priv structures to maintain statistics and to pass
  398. * the packet up.
  399. *
  400. * Only the first device structure is attached to the interrupt.
  401. * We use the special "chan" variable at the end of the first RBD
  402. * to select the Nth device in multi-NIC mode.
  403. *
  404. * We currently do chained DMA on a per-packet basis when the
  405. * packet is "long", and we spin the CPU a short time polling
  406. * for DMA completion. This avoids a second interrupt overhead,
  407. * and gives the best performance for light traffic to the host.
  408. *
  409. * However, a better scheme that could be implemented would be
  410. * to see how many packets are outstanding for the host, and if
  411. * the number is "large", create a long chain to DMA several
  412. * packets into the host in one go. In this case, we would set
  413. * up some state variables to let the host CPU continue doing
  414. * other things until a DMA completion interrupt comes along.
  415. */
  416. static void
  417. dgrs_rcv_frame(
  418. struct net_device *dev0,
  419. DGRS_PRIV *priv0,
  420. I596_CB *cbp
  421. )
  422. {
  423. int len;
  424. I596_TBD *tbdp;
  425. struct sk_buff *skb;
  426. uchar *putp;
  427. uchar *p;
  428. struct net_device *devN;
  429. DGRS_PRIV *privN;
  430. /*
  431. * Determine Nth priv and dev structure pointers
  432. */
  433. if (dgrs_nicmode)
  434. { /* Multi-NIC mode */
  435. int chan = ((I596_RBD *) S2H(cbp->xmit.tbdp))->chan;
  436. devN = priv0->devtbl[chan-1];
  437. /*
  438. * If devN is null, we got an interrupt before the I/F
  439. * has been initialized. Pitch the packet.
  440. */
  441. if (devN == NULL)
  442. goto out;
  443. privN = (DGRS_PRIV *) devN->priv;
  444. }
  445. else
  446. { /* Switch mode */
  447. devN = dev0;
  448. privN = priv0;
  449. }
  450. if (0) printk("%s: rcv len=%ld\n", devN->name, cbp->xmit.count);
  451. /*
  452. * Allocate a message block big enough to hold the whole frame
  453. */
  454. len = cbp->xmit.count;
  455. if ((skb = dev_alloc_skb(len+5)) == NULL)
  456. {
  457. printk("%s: dev_alloc_skb failed for rcv buffer\n", devN->name);
  458. ++privN->stats.rx_dropped;
  459. /* discarding the frame */
  460. goto out;
  461. }
  462. skb_reserve(skb, 2); /* Align IP header */
  463. again:
  464. putp = p = skb_put(skb, len);
  465. /*
  466. * There are three modes here for doing the packet copy.
  467. * If we have DMA, and the packet is "long", we use the
  468. * chaining mode of DMA. If it's shorter, we use single
  469. * DMA's. Otherwise, we use memcpy().
  470. */
  471. if (priv0->use_dma && priv0->dmadesc_h && len > 64)
  472. {
  473. /*
  474. * If we can use DMA and it's a long frame, copy it using
  475. * DMA chaining.
  476. */
  477. DMACHAIN *ddp_h; /* Host virtual DMA desc. pointer */
  478. DMACHAIN *ddp_s; /* Switch physical DMA desc. pointer */
  479. uchar *phys_p;
  480. /*
  481. * Get the physical address of the STREAMS buffer.
  482. * NOTE: allocb() guarantees that the whole buffer
  483. * is in a single page if the length < 4096.
  484. */
  485. phys_p = (uchar *) virt_to_phys(putp);
  486. ddp_h = priv0->dmadesc_h;
  487. ddp_s = priv0->dmadesc_s;
  488. tbdp = (I596_TBD *) S2H(cbp->xmit.tbdp);
  489. for (;;)
  490. {
  491. int count;
  492. int amt;
  493. count = tbdp->count;
  494. amt = count & 0x3fff;
  495. if (amt == 0)
  496. break; /* For safety */
  497. if ( (p-putp) >= len)
  498. {
  499. printk("%s: cbp = %lx\n", devN->name, (long) H2S(cbp));
  500. proc_reset(dev0, 1); /* Freeze IDT */
  501. break; /* For Safety */
  502. }
  503. ddp_h->pciaddr = (ulong) phys_p;
  504. ddp_h->lcladdr = S2DMA(tbdp->buf);
  505. ddp_h->len = amt;
  506. phys_p += amt;
  507. p += amt;
  508. if (count & I596_TBD_EOF)
  509. {
  510. ddp_h->next = PLX_DMA_DESC_TO_HOST
  511. | PLX_DMA_DESC_EOC;
  512. ++ddp_h;
  513. break;
  514. }
  515. else
  516. {
  517. ++ddp_s;
  518. ddp_h->next = PLX_DMA_DESC_TO_HOST
  519. | (ulong) ddp_s;
  520. tbdp = (I596_TBD *) S2H(tbdp->next);
  521. ++ddp_h;
  522. }
  523. }
  524. if (ddp_h - priv0->dmadesc_h)
  525. {
  526. int rc;
  527. rc = do_plx_dma(dev0,
  528. 0, (ulong) priv0->dmadesc_s, len, 0);
  529. if (rc)
  530. {
  531. printk("%s: Chained DMA failure\n", devN->name);
  532. goto again;
  533. }
  534. }
  535. }
  536. else if (priv0->use_dma)
  537. {
  538. /*
  539. * If we can use DMA and it's a shorter frame, copy it
  540. * using single DMA transfers.
  541. */
  542. uchar *phys_p;
  543. /*
  544. * Get the physical address of the STREAMS buffer.
  545. * NOTE: allocb() guarantees that the whole buffer
  546. * is in a single page if the length < 4096.
  547. */
  548. phys_p = (uchar *) virt_to_phys(putp);
  549. tbdp = (I596_TBD *) S2H(cbp->xmit.tbdp);
  550. for (;;)
  551. {
  552. int count;
  553. int amt;
  554. int rc;
  555. count = tbdp->count;
  556. amt = count & 0x3fff;
  557. if (amt == 0)
  558. break; /* For safety */
  559. if ( (p-putp) >= len)
  560. {
  561. printk("%s: cbp = %lx\n", devN->name, (long) H2S(cbp));
  562. proc_reset(dev0, 1); /* Freeze IDT */
  563. break; /* For Safety */
  564. }
  565. rc = do_plx_dma(dev0, (ulong) phys_p,
  566. S2DMA(tbdp->buf), amt, 1);
  567. if (rc)
  568. {
  569. memcpy(p, S2H(tbdp->buf), amt);
  570. printk("%s: Single DMA failed\n", devN->name);
  571. }
  572. phys_p += amt;
  573. p += amt;
  574. if (count & I596_TBD_EOF)
  575. break;
  576. tbdp = (I596_TBD *) S2H(tbdp->next);
  577. }
  578. }
  579. else
  580. {
  581. /*
  582. * Otherwise, copy it piece by piece using memcpy()
  583. */
  584. tbdp = (I596_TBD *) S2H(cbp->xmit.tbdp);
  585. for (;;)
  586. {
  587. int count;
  588. int amt;
  589. count = tbdp->count;
  590. amt = count & 0x3fff;
  591. if (amt == 0)
  592. break; /* For safety */
  593. if ( (p-putp) >= len)
  594. {
  595. printk("%s: cbp = %lx\n", devN->name, (long) H2S(cbp));
  596. proc_reset(dev0, 1); /* Freeze IDT */
  597. break; /* For Safety */
  598. }
  599. memcpy(p, S2H(tbdp->buf), amt);
  600. p += amt;
  601. if (count & I596_TBD_EOF)
  602. break;
  603. tbdp = (I596_TBD *) S2H(tbdp->next);
  604. }
  605. }
  606. /*
  607. * Pass the frame to upper half
  608. */
  609. skb->protocol = eth_type_trans(skb, devN);
  610. netif_rx(skb);
  611. devN->last_rx = jiffies;
  612. ++privN->stats.rx_packets;
  613. privN->stats.rx_bytes += len;
  614. out:
  615. cbp->xmit.status = I596_CB_STATUS_C | I596_CB_STATUS_OK;
  616. }
  617. /*
  618. * Start transmission of a frame
  619. *
  620. * The interface to the board is simple: we pretend that we are
  621. * a fifth 82596 ethernet controller 'receiving' data, and copy the
  622. * data into the same structures that a real 82596 would. This way,
  623. * the board firmware handles the host 'port' the same as any other.
  624. *
  625. * NOTE: we do not use Bus master DMA for this routine. Turns out
  626. * that it is not needed. Slave writes over the PCI bus are about
  627. * as fast as DMA, due to the fact that the PLX part can do burst
  628. * writes. The same is not true for data being read from the board.
  629. *
  630. * For multi-NIC mode, we tell the firmware the desired 82596
  631. * output port by setting the special "dstchan" member at the
  632. * end of the traditional 82596 RFD structure.
  633. */
  634. static int dgrs_start_xmit(struct sk_buff *skb, struct net_device *devN)
  635. {
  636. DGRS_PRIV *privN = (DGRS_PRIV *) devN->priv;
  637. struct net_device *dev0;
  638. DGRS_PRIV *priv0;
  639. I596_RBD *rbdp;
  640. int count;
  641. int i, len, amt;
  642. /*
  643. * Determine 0th priv and dev structure pointers
  644. */
  645. if (dgrs_nicmode)
  646. {
  647. dev0 = privN->devtbl[0];
  648. priv0 = (DGRS_PRIV *) dev0->priv;
  649. }
  650. else
  651. {
  652. dev0 = devN;
  653. priv0 = privN;
  654. }
  655. if (dgrs_debug > 1)
  656. printk("%s: xmit len=%d\n", devN->name, (int) skb->len);
  657. devN->trans_start = jiffies;
  658. netif_start_queue(devN);
  659. if (priv0->rfdp->cmd & I596_RFD_EL)
  660. { /* Out of RFD's */
  661. if (0) printk("%s: NO RFD's\n", devN->name);
  662. goto no_resources;
  663. }
  664. rbdp = priv0->rbdp;
  665. count = 0;
  666. priv0->rfdp->rbdp = (I596_RBD *) H2S(rbdp);
  667. i = 0; len = skb->len;
  668. for (;;)
  669. {
  670. if (rbdp->size & I596_RBD_EL)
  671. { /* Out of RBD's */
  672. if (0) printk("%s: NO RBD's\n", devN->name);
  673. goto no_resources;
  674. }
  675. amt = min_t(unsigned int, len, rbdp->size - count);
  676. skb_copy_from_linear_data_offset(skb, i, S2H(rbdp->buf) + count, amt);
  677. i += amt;
  678. count += amt;
  679. len -= amt;
  680. if (len == 0)
  681. {
  682. if (skb->len < 60)
  683. rbdp->count = 60 | I596_RBD_EOF;
  684. else
  685. rbdp->count = count | I596_RBD_EOF;
  686. rbdp = (I596_RBD *) S2H(rbdp->next);
  687. goto frame_done;
  688. }
  689. else if (count < 32)
  690. {
  691. /* More data to come, but we used less than 32
  692. * bytes of this RBD. Keep filling this RBD.
  693. */
  694. {} /* Yes, we do nothing here */
  695. }
  696. else
  697. {
  698. rbdp->count = count;
  699. rbdp = (I596_RBD *) S2H(rbdp->next);
  700. count = 0;
  701. }
  702. }
  703. frame_done:
  704. priv0->rbdp = rbdp;
  705. if (dgrs_nicmode)
  706. priv0->rfdp->dstchan = privN->chan;
  707. priv0->rfdp->status = I596_RFD_C | I596_RFD_OK;
  708. priv0->rfdp = (I596_RFD *) S2H(priv0->rfdp->next);
  709. ++privN->stats.tx_packets;
  710. dev_kfree_skb (skb);
  711. return (0);
  712. no_resources:
  713. priv0->scbp->status |= I596_SCB_RNR; /* simulate I82596 */
  714. return (-EAGAIN);
  715. }
  716. /*
  717. * Open the interface
  718. */
  719. static int
  720. dgrs_open( struct net_device *dev )
  721. {
  722. netif_start_queue(dev);
  723. return (0);
  724. }
  725. /*
  726. * Close the interface
  727. */
  728. static int dgrs_close( struct net_device *dev )
  729. {
  730. netif_stop_queue(dev);
  731. return (0);
  732. }
  733. /*
  734. * Get statistics
  735. */
  736. static struct net_device_stats *dgrs_get_stats( struct net_device *dev )
  737. {
  738. DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
  739. return (&priv->stats);
  740. }
  741. /*
  742. * Set multicast list and/or promiscuous mode
  743. */
  744. static void dgrs_set_multicast_list( struct net_device *dev)
  745. {
  746. DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
  747. priv->port->is_promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
  748. }
  749. /*
  750. * Unique ioctl's
  751. */
  752. static int dgrs_ioctl(struct net_device *devN, struct ifreq *ifr, int cmd)
  753. {
  754. DGRS_PRIV *privN = (DGRS_PRIV *) devN->priv;
  755. DGRS_IOCTL ioc;
  756. int i;
  757. if (cmd != DGRSIOCTL)
  758. return -EINVAL;
  759. if(copy_from_user(&ioc, ifr->ifr_data, sizeof(DGRS_IOCTL)))
  760. return -EFAULT;
  761. switch (ioc.cmd)
  762. {
  763. case DGRS_GETMEM:
  764. if (ioc.len != sizeof(ulong))
  765. return -EINVAL;
  766. if(copy_to_user(ioc.data, &devN->mem_start, ioc.len))
  767. return -EFAULT;
  768. return (0);
  769. case DGRS_SETFILTER:
  770. if (!capable(CAP_NET_ADMIN))
  771. return -EPERM;
  772. if (ioc.port > privN->bcomm->bc_nports)
  773. return -EINVAL;
  774. if (ioc.filter >= NFILTERS)
  775. return -EINVAL;
  776. if (ioc.len > privN->bcomm->bc_filter_area_len)
  777. return -EINVAL;
  778. /* Wait for old command to finish */
  779. for (i = 0; i < 1000; ++i)
  780. {
  781. if ( (volatile long) privN->bcomm->bc_filter_cmd <= 0 )
  782. break;
  783. udelay(1);
  784. }
  785. if (i >= 1000)
  786. return -EIO;
  787. privN->bcomm->bc_filter_port = ioc.port;
  788. privN->bcomm->bc_filter_num = ioc.filter;
  789. privN->bcomm->bc_filter_len = ioc.len;
  790. if (ioc.len)
  791. {
  792. if(copy_from_user(S2HN(privN->bcomm->bc_filter_area),
  793. ioc.data, ioc.len))
  794. return -EFAULT;
  795. privN->bcomm->bc_filter_cmd = BC_FILTER_SET;
  796. }
  797. else
  798. privN->bcomm->bc_filter_cmd = BC_FILTER_CLR;
  799. return(0);
  800. default:
  801. return -EOPNOTSUPP;
  802. }
  803. }
  804. /*
  805. * Process interrupts
  806. *
  807. * dev, priv will always refer to the 0th device in Multi-NIC mode.
  808. */
  809. static irqreturn_t dgrs_intr(int irq, void *dev_id)
  810. {
  811. struct net_device *dev0 = dev_id;
  812. DGRS_PRIV *priv0 = dev0->priv;
  813. I596_CB *cbp;
  814. int cmd;
  815. int i;
  816. ++priv0->intrcnt;
  817. if (1) ++priv0->bcomm->bc_cnt[4];
  818. if (0)
  819. {
  820. static int cnt = 100;
  821. if (--cnt > 0)
  822. printk("%s: interrupt: irq %d\n", dev0->name, irq);
  823. }
  824. /*
  825. * Get 596 command
  826. */
  827. cmd = priv0->scbp->cmd;
  828. /*
  829. * See if RU has been restarted
  830. */
  831. if ( (cmd & I596_SCB_RUC) == I596_SCB_RUC_START)
  832. {
  833. if (0) printk("%s: RUC start\n", dev0->name);
  834. priv0->rfdp = (I596_RFD *) S2H(priv0->scbp->rfdp);
  835. priv0->rbdp = (I596_RBD *) S2H(priv0->rfdp->rbdp);
  836. priv0->scbp->status &= ~(I596_SCB_RNR|I596_SCB_RUS);
  837. /*
  838. * Tell upper half (halves)
  839. */
  840. if (dgrs_nicmode)
  841. {
  842. for (i = 0; i < priv0->nports; ++i)
  843. netif_wake_queue (priv0->devtbl[i]);
  844. }
  845. else
  846. netif_wake_queue (dev0);
  847. /* if (bd->flags & TX_QUEUED)
  848. DL_sched(bd, bdd); */
  849. }
  850. /*
  851. * See if any CU commands to process
  852. */
  853. if ( (cmd & I596_SCB_CUC) != I596_SCB_CUC_START)
  854. {
  855. priv0->scbp->cmd = 0; /* Ignore all other commands */
  856. goto ack_intr;
  857. }
  858. priv0->scbp->status &= ~(I596_SCB_CNA|I596_SCB_CUS);
  859. /*
  860. * Process a command
  861. */
  862. cbp = (I596_CB *) S2H(priv0->scbp->cbp);
  863. priv0->scbp->cmd = 0; /* Safe to clear the command */
  864. for (;;)
  865. {
  866. switch (cbp->nop.cmd & I596_CB_CMD)
  867. {
  868. case I596_CB_CMD_XMIT:
  869. dgrs_rcv_frame(dev0, priv0, cbp);
  870. break;
  871. default:
  872. cbp->nop.status = I596_CB_STATUS_C | I596_CB_STATUS_OK;
  873. break;
  874. }
  875. if (cbp->nop.cmd & I596_CB_CMD_EL)
  876. break;
  877. cbp = (I596_CB *) S2H(cbp->nop.next);
  878. }
  879. priv0->scbp->status |= I596_SCB_CNA;
  880. /*
  881. * Ack the interrupt
  882. */
  883. ack_intr:
  884. if (priv0->plxreg)
  885. OUTL(dev0->base_addr + PLX_LCL2PCI_DOORBELL, 1);
  886. return IRQ_HANDLED;
  887. }
  888. /*
  889. * Download the board firmware
  890. */
  891. static int __init
  892. dgrs_download(struct net_device *dev0)
  893. {
  894. DGRS_PRIV *priv0 = (DGRS_PRIV *) dev0->priv;
  895. int is;
  896. unsigned long i;
  897. static const int iv2is[16] = {
  898. 0, 0, 0, ES4H_IS_INT3,
  899. 0, ES4H_IS_INT5, 0, ES4H_IS_INT7,
  900. 0, 0, ES4H_IS_INT10, ES4H_IS_INT11,
  901. ES4H_IS_INT12, 0, 0, ES4H_IS_INT15 };
  902. /*
  903. * Map in the dual port memory
  904. */
  905. priv0->vmem = ioremap(dev0->mem_start, 2048*1024);
  906. if (!priv0->vmem)
  907. {
  908. printk("%s: cannot map in board memory\n", dev0->name);
  909. return -ENXIO;
  910. }
  911. /*
  912. * Hold the processor and configure the board addresses
  913. */
  914. if (priv0->plxreg)
  915. { /* PCI bus */
  916. proc_reset(dev0, 1);
  917. }
  918. else
  919. { /* EISA bus */
  920. is = iv2is[dev0->irq & 0x0f];
  921. if (!is)
  922. {
  923. printk("%s: Illegal IRQ %d\n", dev0->name, dev0->irq);
  924. iounmap(priv0->vmem);
  925. priv0->vmem = NULL;
  926. return -ENXIO;
  927. }
  928. OUTB(dev0->base_addr + ES4H_AS_31_24,
  929. (uchar) (dev0->mem_start >> 24) );
  930. OUTB(dev0->base_addr + ES4H_AS_23_16,
  931. (uchar) (dev0->mem_start >> 16) );
  932. priv0->is_reg = ES4H_IS_LINEAR | is |
  933. ((uchar) (dev0->mem_start >> 8) & ES4H_IS_AS15);
  934. OUTB(dev0->base_addr + ES4H_IS, priv0->is_reg);
  935. OUTB(dev0->base_addr + ES4H_EC, ES4H_EC_ENABLE);
  936. OUTB(dev0->base_addr + ES4H_PC, ES4H_PC_RESET);
  937. OUTB(dev0->base_addr + ES4H_MW, ES4H_MW_ENABLE | 0x00);
  938. }
  939. /*
  940. * See if we can do DMA on the SE-6
  941. */
  942. priv0->use_dma = check_board_dma(dev0);
  943. if (priv0->use_dma)
  944. printk("%s: Bus Master DMA is enabled.\n", dev0->name);
  945. /*
  946. * Load and verify the code at the desired address
  947. */
  948. memcpy(priv0->vmem, dgrs_code, dgrs_ncode); /* Load code */
  949. if (memcmp(priv0->vmem, dgrs_code, dgrs_ncode))
  950. {
  951. iounmap(priv0->vmem);
  952. priv0->vmem = NULL;
  953. printk("%s: download compare failed\n", dev0->name);
  954. return -ENXIO;
  955. }
  956. /*
  957. * Configurables
  958. */
  959. priv0->bcomm = (struct bios_comm *) (priv0->vmem + 0x0100);
  960. priv0->bcomm->bc_nowait = 1; /* Tell board to make printf not wait */
  961. priv0->bcomm->bc_squelch = 0; /* Flag from Space.c */
  962. priv0->bcomm->bc_150ohm = 0; /* Flag from Space.c */
  963. priv0->bcomm->bc_spew = 0; /* Debug flag from Space.c */
  964. priv0->bcomm->bc_maxrfd = 0; /* Debug flag from Space.c */
  965. priv0->bcomm->bc_maxrbd = 0; /* Debug flag from Space.c */
  966. /*
  967. * Tell board we are operating in switch mode (1) or in
  968. * multi-NIC mode (2).
  969. */
  970. priv0->bcomm->bc_host = dgrs_nicmode ? BC_MULTINIC : BC_SWITCH;
  971. /*
  972. * Request memory space on board for DMA chains
  973. */
  974. if (priv0->use_dma)
  975. priv0->bcomm->bc_hostarea_len = (2048/64) * 16;
  976. /*
  977. * NVRAM configurables from Space.c
  978. */
  979. priv0->bcomm->bc_spantree = dgrs_spantree;
  980. priv0->bcomm->bc_hashexpire = dgrs_hashexpire;
  981. memcpy(priv0->bcomm->bc_ipaddr, dgrs_ipaddr, 4);
  982. memcpy(priv0->bcomm->bc_iptrap, dgrs_iptrap, 4);
  983. memcpy(priv0->bcomm->bc_ipxnet, &dgrs_ipxnet, 4);
  984. /*
  985. * Release processor, wait 8 seconds for board to initialize
  986. */
  987. proc_reset(dev0, 0);
  988. for (i = jiffies + 8 * HZ; time_after(i, jiffies); )
  989. {
  990. barrier(); /* Gcc 2.95 needs this */
  991. if (priv0->bcomm->bc_status >= BC_RUN)
  992. break;
  993. }
  994. if (priv0->bcomm->bc_status < BC_RUN)
  995. {
  996. printk("%s: board not operating\n", dev0->name);
  997. iounmap(priv0->vmem);
  998. priv0->vmem = NULL;
  999. return -ENXIO;
  1000. }
  1001. priv0->port = (PORT *) S2H(priv0->bcomm->bc_port);
  1002. priv0->scbp = (I596_SCB *) S2H(priv0->port->scbp);
  1003. priv0->rfdp = (I596_RFD *) S2H(priv0->scbp->rfdp);
  1004. priv0->rbdp = (I596_RBD *) S2H(priv0->rfdp->rbdp);
  1005. priv0->scbp->status = I596_SCB_CNA; /* CU is idle */
  1006. /*
  1007. * Get switch physical and host virtual pointers to DMA
  1008. * chaining area. NOTE: the MSB of the switch physical
  1009. * address *must* be turned off. Otherwise, the HW kludge
  1010. * that allows host access of the PLX DMA registers will
  1011. * erroneously select the PLX registers.
  1012. */
  1013. priv0->dmadesc_s = (DMACHAIN *) S2DMA(priv0->bcomm->bc_hostarea);
  1014. if (priv0->dmadesc_s)
  1015. priv0->dmadesc_h = (DMACHAIN *) S2H(priv0->dmadesc_s);
  1016. else
  1017. priv0->dmadesc_h = NULL;
  1018. /*
  1019. * Enable board interrupts
  1020. */
  1021. if (priv0->plxreg)
  1022. { /* PCI bus */
  1023. OUTL(dev0->base_addr + PLX_INT_CSR,
  1024. inl(dev0->base_addr + PLX_INT_CSR)
  1025. | PLX_PCI_DOORBELL_IE); /* Enable intr to host */
  1026. OUTL(dev0->base_addr + PLX_LCL2PCI_DOORBELL, 1);
  1027. }
  1028. else
  1029. { /* EISA bus */
  1030. }
  1031. return (0);
  1032. }
  1033. /*
  1034. * Probe (init) a board
  1035. */
  1036. static int __init
  1037. dgrs_probe1(struct net_device *dev)
  1038. {
  1039. DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
  1040. unsigned long i;
  1041. int rc;
  1042. printk("%s: Digi RightSwitch io=%lx mem=%lx irq=%d plx=%lx dma=%lx\n",
  1043. dev->name, dev->base_addr, dev->mem_start, dev->irq,
  1044. priv->plxreg, priv->plxdma);
  1045. /*
  1046. * Download the firmware and light the processor
  1047. */
  1048. rc = dgrs_download(dev);
  1049. if (rc)
  1050. goto err_out;
  1051. /*
  1052. * Get ether address of board
  1053. */
  1054. printk("%s: Ethernet address", dev->name);
  1055. memcpy(dev->dev_addr, priv->port->ethaddr, 6);
  1056. for (i = 0; i < 6; ++i)
  1057. printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
  1058. printk("\n");
  1059. if (dev->dev_addr[0] & 1)
  1060. {
  1061. printk("%s: Illegal Ethernet Address\n", dev->name);
  1062. rc = -ENXIO;
  1063. goto err_out;
  1064. }
  1065. /*
  1066. * ACK outstanding interrupts, hook the interrupt,
  1067. * and verify that we are getting interrupts from the board.
  1068. */
  1069. if (priv->plxreg)
  1070. OUTL(dev->base_addr + PLX_LCL2PCI_DOORBELL, 1);
  1071. rc = request_irq(dev->irq, &dgrs_intr, IRQF_SHARED, "RightSwitch", dev);
  1072. if (rc)
  1073. goto err_out;
  1074. priv->intrcnt = 0;
  1075. for (i = jiffies + 2*HZ + HZ/2; time_after(i, jiffies); )
  1076. {
  1077. cpu_relax();
  1078. if (priv->intrcnt >= 2)
  1079. break;
  1080. }
  1081. if (priv->intrcnt < 2)
  1082. {
  1083. printk(KERN_ERR "%s: Not interrupting on IRQ %d (%d)\n",
  1084. dev->name, dev->irq, priv->intrcnt);
  1085. rc = -ENXIO;
  1086. goto err_free_irq;
  1087. }
  1088. /*
  1089. * Entry points...
  1090. */
  1091. dev->open = &dgrs_open;
  1092. dev->stop = &dgrs_close;
  1093. dev->get_stats = &dgrs_get_stats;
  1094. dev->hard_start_xmit = &dgrs_start_xmit;
  1095. dev->set_multicast_list = &dgrs_set_multicast_list;
  1096. dev->do_ioctl = &dgrs_ioctl;
  1097. return rc;
  1098. err_free_irq:
  1099. free_irq(dev->irq, dev);
  1100. err_out:
  1101. return rc;
  1102. }
  1103. static int __init
  1104. dgrs_initclone(struct net_device *dev)
  1105. {
  1106. DGRS_PRIV *priv = (DGRS_PRIV *) dev->priv;
  1107. int i;
  1108. printk("%s: Digi RightSwitch port %d ",
  1109. dev->name, priv->chan);
  1110. for (i = 0; i < 6; ++i)
  1111. printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
  1112. printk("\n");
  1113. return (0);
  1114. }
  1115. static struct net_device * __init
  1116. dgrs_found_device(
  1117. int io,
  1118. ulong mem,
  1119. int irq,
  1120. ulong plxreg,
  1121. ulong plxdma,
  1122. struct device *pdev
  1123. )
  1124. {
  1125. DGRS_PRIV *priv;
  1126. struct net_device *dev;
  1127. int i, ret = -ENOMEM;
  1128. dev = alloc_etherdev(sizeof(DGRS_PRIV));
  1129. if (!dev)
  1130. goto err0;
  1131. priv = (DGRS_PRIV *)dev->priv;
  1132. dev->base_addr = io;
  1133. dev->mem_start = mem;
  1134. dev->mem_end = mem + 2048 * 1024 - 1;
  1135. dev->irq = irq;
  1136. priv->plxreg = plxreg;
  1137. priv->plxdma = plxdma;
  1138. priv->vplxdma = NULL;
  1139. priv->chan = 1;
  1140. priv->devtbl[0] = dev;
  1141. SET_MODULE_OWNER(dev);
  1142. SET_NETDEV_DEV(dev, pdev);
  1143. ret = dgrs_probe1(dev);
  1144. if (ret)
  1145. goto err1;
  1146. ret = register_netdev(dev);
  1147. if (ret)
  1148. goto err2;
  1149. if ( !dgrs_nicmode )
  1150. return dev; /* Switch mode, we are done */
  1151. /*
  1152. * Operating card as N separate NICs
  1153. */
  1154. priv->nports = priv->bcomm->bc_nports;
  1155. for (i = 1; i < priv->nports; ++i)
  1156. {
  1157. struct net_device *devN;
  1158. DGRS_PRIV *privN;
  1159. /* Allocate new dev and priv structures */
  1160. devN = alloc_etherdev(sizeof(DGRS_PRIV));
  1161. ret = -ENOMEM;
  1162. if (!devN)
  1163. goto fail;
  1164. /* Don't copy the network device structure! */
  1165. /* copy the priv structure of dev[0] */
  1166. privN = (DGRS_PRIV *)devN->priv;
  1167. *privN = *priv;
  1168. /* ... and zero out VM areas */
  1169. privN->vmem = NULL;
  1170. privN->vplxdma = NULL;
  1171. /* ... and zero out IRQ */
  1172. devN->irq = 0;
  1173. /* ... and base MAC address off address of 1st port */
  1174. devN->dev_addr[5] += i;
  1175. ret = dgrs_initclone(devN);
  1176. if (ret)
  1177. goto fail;
  1178. SET_MODULE_OWNER(devN);
  1179. SET_NETDEV_DEV(dev, pdev);
  1180. ret = register_netdev(devN);
  1181. if (ret) {
  1182. free_netdev(devN);
  1183. goto fail;
  1184. }
  1185. privN->chan = i+1;
  1186. priv->devtbl[i] = devN;
  1187. }
  1188. return dev;
  1189. fail:
  1190. while (i >= 0) {
  1191. struct net_device *d = priv->devtbl[i--];
  1192. unregister_netdev(d);
  1193. free_netdev(d);
  1194. }
  1195. err2:
  1196. free_irq(dev->irq, dev);
  1197. err1:
  1198. free_netdev(dev);
  1199. err0:
  1200. return ERR_PTR(ret);
  1201. }
  1202. static void __devexit dgrs_remove(struct net_device *dev)
  1203. {
  1204. DGRS_PRIV *priv = dev->priv;
  1205. int i;
  1206. unregister_netdev(dev);
  1207. for (i = 1; i < priv->nports; ++i) {
  1208. struct net_device *d = priv->devtbl[i];
  1209. if (d) {
  1210. unregister_netdev(d);
  1211. free_netdev(d);
  1212. }
  1213. }
  1214. proc_reset(priv->devtbl[0], 1);
  1215. if (priv->vmem)
  1216. iounmap(priv->vmem);
  1217. if (priv->vplxdma)
  1218. iounmap((uchar *) priv->vplxdma);
  1219. if (dev->irq)
  1220. free_irq(dev->irq, dev);
  1221. for (i = 1; i < priv->nports; ++i) {
  1222. if (priv->devtbl[i])
  1223. unregister_netdev(priv->devtbl[i]);
  1224. }
  1225. }
  1226. #ifdef CONFIG_PCI
  1227. static int __init dgrs_pci_probe(struct pci_dev *pdev,
  1228. const struct pci_device_id *ent)
  1229. {
  1230. struct net_device *dev;
  1231. int err;
  1232. uint io;
  1233. uint mem;
  1234. uint irq;
  1235. uint plxreg;
  1236. uint plxdma;
  1237. /*
  1238. * Get and check the bus-master and latency values.
  1239. * Some PCI BIOSes fail to set the master-enable bit,
  1240. * and the latency timer must be set to the maximum
  1241. * value to avoid data corruption that occurs when the
  1242. * timer expires during a transfer. Yes, it's a bug.
  1243. */
  1244. err = pci_enable_device(pdev);
  1245. if (err)
  1246. return err;
  1247. err = pci_request_regions(pdev, "RightSwitch");
  1248. if (err)
  1249. return err;
  1250. pci_set_master(pdev);
  1251. plxreg = pci_resource_start (pdev, 0);
  1252. io = pci_resource_start (pdev, 1);
  1253. mem = pci_resource_start (pdev, 2);
  1254. pci_read_config_dword(pdev, 0x30, &plxdma);
  1255. irq = pdev->irq;
  1256. plxdma &= ~15;
  1257. /*
  1258. * On some BIOSES, the PLX "expansion rom" (used for DMA)
  1259. * address comes up as "0". This is probably because
  1260. * the BIOS doesn't see a valid 55 AA ROM signature at
  1261. * the "ROM" start and zeroes the address. To get
  1262. * around this problem the SE-6 is configured to ask
  1263. * for 4 MB of space for the dual port memory. We then
  1264. * must set its range back to 2 MB, and use the upper
  1265. * half for DMA register access
  1266. */
  1267. OUTL(io + PLX_SPACE0_RANGE, 0xFFE00000L);
  1268. if (plxdma == 0)
  1269. plxdma = mem + (2048L * 1024L);
  1270. pci_write_config_dword(pdev, 0x30, plxdma + 1);
  1271. pci_read_config_dword(pdev, 0x30, &plxdma);
  1272. plxdma &= ~15;
  1273. dev = dgrs_found_device(io, mem, irq, plxreg, plxdma, &pdev->dev);
  1274. if (IS_ERR(dev)) {
  1275. pci_release_regions(pdev);
  1276. return PTR_ERR(dev);
  1277. }
  1278. pci_set_drvdata(pdev, dev);
  1279. return 0;
  1280. }
  1281. static void __devexit dgrs_pci_remove(struct pci_dev *pdev)
  1282. {
  1283. struct net_device *dev = pci_get_drvdata(pdev);
  1284. dgrs_remove(dev);
  1285. pci_release_regions(pdev);
  1286. free_netdev(dev);
  1287. }
  1288. static struct pci_driver dgrs_pci_driver = {
  1289. .name = "dgrs",
  1290. .id_table = dgrs_pci_tbl,
  1291. .probe = dgrs_pci_probe,
  1292. .remove = __devexit_p(dgrs_pci_remove),
  1293. };
  1294. #else
  1295. static struct pci_driver dgrs_pci_driver = {};
  1296. #endif
  1297. #ifdef CONFIG_EISA
  1298. static int is2iv[8] __initdata = { 0, 3, 5, 7, 10, 11, 12, 15 };
  1299. static int __init dgrs_eisa_probe (struct device *gendev)
  1300. {
  1301. struct net_device *dev;
  1302. struct eisa_device *edev = to_eisa_device(gendev);
  1303. uint io = edev->base_addr;
  1304. uint mem;
  1305. uint irq;
  1306. int rc = -ENODEV; /* Not EISA configured */
  1307. if (!request_region(io, 256, "RightSwitch")) {
  1308. printk(KERN_ERR "dgrs: eisa io 0x%x, which is busy.\n", io);
  1309. return -EBUSY;
  1310. }
  1311. if ( ! (inb(io+ES4H_EC) & ES4H_EC_ENABLE) )
  1312. goto err_out;
  1313. mem = (inb(io+ES4H_AS_31_24) << 24)
  1314. + (inb(io+ES4H_AS_23_16) << 16);
  1315. irq = is2iv[ inb(io+ES4H_IS) & ES4H_IS_INTMASK ];
  1316. dev = dgrs_found_device(io, mem, irq, 0L, 0L, gendev);
  1317. if (IS_ERR(dev)) {
  1318. rc = PTR_ERR(dev);
  1319. goto err_out;
  1320. }
  1321. gendev->driver_data = dev;
  1322. return 0;
  1323. err_out:
  1324. release_region(io, 256);
  1325. return rc;
  1326. }
  1327. static int __devexit dgrs_eisa_remove(struct device *gendev)
  1328. {
  1329. struct net_device *dev = gendev->driver_data;
  1330. dgrs_remove(dev);
  1331. release_region(dev->base_addr, 256);
  1332. free_netdev(dev);
  1333. return 0;
  1334. }
  1335. static struct eisa_driver dgrs_eisa_driver = {
  1336. .id_table = dgrs_eisa_tbl,
  1337. .driver = {
  1338. .name = "dgrs",
  1339. .probe = dgrs_eisa_probe,
  1340. .remove = __devexit_p(dgrs_eisa_remove),
  1341. }
  1342. };
  1343. #endif
  1344. /*
  1345. * Variables that can be overriden from module command line
  1346. */
  1347. static int debug = -1;
  1348. static int dma = -1;
  1349. static int hashexpire = -1;
  1350. static int spantree = -1;
  1351. static int ipaddr[4] = { -1 };
  1352. static int iptrap[4] = { -1 };
  1353. static __u32 ipxnet = -1;
  1354. static int nicmode = -1;
  1355. module_param(debug, int, 0);
  1356. module_param(dma, int, 0);
  1357. module_param(hashexpire, int, 0);
  1358. module_param(spantree, int, 0);
  1359. module_param_array(ipaddr, int, NULL, 0);
  1360. module_param_array(iptrap, int, NULL, 0);
  1361. module_param(ipxnet, int, 0);
  1362. module_param(nicmode, int, 0);
  1363. MODULE_PARM_DESC(debug, "Digi RightSwitch enable debugging (0-1)");
  1364. MODULE_PARM_DESC(dma, "Digi RightSwitch enable BM DMA (0-1)");
  1365. MODULE_PARM_DESC(nicmode, "Digi RightSwitch operating mode (1: switch, 2: multi-NIC)");
  1366. static int __init dgrs_init_module (void)
  1367. {
  1368. int i;
  1369. int err;
  1370. /*
  1371. * Command line variable overrides
  1372. * debug=NNN
  1373. * dma=0/1
  1374. * spantree=0/1
  1375. * hashexpire=NNN
  1376. * ipaddr=A,B,C,D
  1377. * iptrap=A,B,C,D
  1378. * ipxnet=NNN
  1379. * nicmode=NNN
  1380. */
  1381. if (debug >= 0)
  1382. dgrs_debug = debug;
  1383. if (dma >= 0)
  1384. dgrs_dma = dma;
  1385. if (nicmode >= 0)
  1386. dgrs_nicmode = nicmode;
  1387. if (hashexpire >= 0)
  1388. dgrs_hashexpire = hashexpire;
  1389. if (spantree >= 0)
  1390. dgrs_spantree = spantree;
  1391. if (ipaddr[0] != -1)
  1392. for (i = 0; i < 4; ++i)
  1393. dgrs_ipaddr[i] = ipaddr[i];
  1394. if (iptrap[0] != -1)
  1395. for (i = 0; i < 4; ++i)
  1396. dgrs_iptrap[i] = iptrap[i];
  1397. if (ipxnet != -1)
  1398. dgrs_ipxnet = htonl( ipxnet );
  1399. if (dgrs_debug)
  1400. {
  1401. printk(KERN_INFO "dgrs: SW=%s FW=Build %d %s\nFW Version=%s\n",
  1402. version, dgrs_firmnum, dgrs_firmdate, dgrs_firmver);
  1403. }
  1404. /*
  1405. * Find and configure all the cards
  1406. */
  1407. #ifdef CONFIG_EISA
  1408. err = eisa_driver_register(&dgrs_eisa_driver);
  1409. if (err)
  1410. return err;
  1411. #endif
  1412. err = pci_register_driver(&dgrs_pci_driver);
  1413. if (err)
  1414. return err;
  1415. return 0;
  1416. }
  1417. static void __exit dgrs_cleanup_module (void)
  1418. {
  1419. #ifdef CONFIG_EISA
  1420. eisa_driver_unregister (&dgrs_eisa_driver);
  1421. #endif
  1422. #ifdef CONFIG_PCI
  1423. pci_unregister_driver (&dgrs_pci_driver);
  1424. #endif
  1425. }
  1426. module_init(dgrs_init_module);
  1427. module_exit(dgrs_cleanup_module);