dgrs.c 38 KB

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