skfddi.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  1. /*
  2. * File Name:
  3. * skfddi.c
  4. *
  5. * Copyright Information:
  6. * Copyright SysKonnect 1998,1999.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * The information in this file is provided "AS IS" without warranty.
  14. *
  15. * Abstract:
  16. * A Linux device driver supporting the SysKonnect FDDI PCI controller
  17. * familie.
  18. *
  19. * Maintainers:
  20. * CG Christoph Goos (cgoos@syskonnect.de)
  21. *
  22. * Contributors:
  23. * DM David S. Miller
  24. *
  25. * Address all question to:
  26. * linux@syskonnect.de
  27. *
  28. * The technical manual for the adapters is available from SysKonnect's
  29. * web pages: www.syskonnect.com
  30. * Goto "Support" and search Knowledge Base for "manual".
  31. *
  32. * Driver Architecture:
  33. * The driver architecture is based on the DEC FDDI driver by
  34. * Lawrence V. Stefani and several ethernet drivers.
  35. * I also used an existing Windows NT miniport driver.
  36. * All hardware dependent functions are handled by the SysKonnect
  37. * Hardware Module.
  38. * The only headerfiles that are directly related to this source
  39. * are skfddi.c, h/types.h, h/osdef1st.h, h/targetos.h.
  40. * The others belong to the SysKonnect FDDI Hardware Module and
  41. * should better not be changed.
  42. *
  43. * Modification History:
  44. * Date Name Description
  45. * 02-Mar-98 CG Created.
  46. *
  47. * 10-Mar-99 CG Support for 2.2.x added.
  48. * 25-Mar-99 CG Corrected IRQ routing for SMP (APIC)
  49. * 26-Oct-99 CG Fixed compilation error on 2.2.13
  50. * 12-Nov-99 CG Source code release
  51. * 22-Nov-99 CG Included in kernel source.
  52. * 07-May-00 DM 64 bit fixes, new dma interface
  53. * 31-Jul-03 DB Audit copy_*_user in skfp_ioctl
  54. * Daniele Bellucci <bellucda@tiscali.it>
  55. * 03-Dec-03 SH Convert to PCI device model
  56. *
  57. * Compilation options (-Dxxx):
  58. * DRIVERDEBUG print lots of messages to log file
  59. * DUMPPACKETS print received/transmitted packets to logfile
  60. *
  61. * Tested cpu architectures:
  62. * - i386
  63. * - sparc64
  64. */
  65. /* Version information string - should be updated prior to */
  66. /* each new release!!! */
  67. #define VERSION "2.07"
  68. static const char * const boot_msg =
  69. "SysKonnect FDDI PCI Adapter driver v" VERSION " for\n"
  70. " SK-55xx/SK-58xx adapters (SK-NET FDDI-FP/UP/LP)";
  71. /* Include files */
  72. #include <linux/capability.h>
  73. #include <linux/module.h>
  74. #include <linux/kernel.h>
  75. #include <linux/errno.h>
  76. #include <linux/ioport.h>
  77. #include <linux/interrupt.h>
  78. #include <linux/pci.h>
  79. #include <linux/netdevice.h>
  80. #include <linux/fddidevice.h>
  81. #include <linux/skbuff.h>
  82. #include <linux/bitops.h>
  83. #include <linux/gfp.h>
  84. #include <asm/byteorder.h>
  85. #include <asm/io.h>
  86. #include <asm/uaccess.h>
  87. #include "h/types.h"
  88. #undef ADDR // undo Linux definition
  89. #include "h/skfbi.h"
  90. #include "h/fddi.h"
  91. #include "h/smc.h"
  92. #include "h/smtstate.h"
  93. // Define module-wide (static) routines
  94. static int skfp_driver_init(struct net_device *dev);
  95. static int skfp_open(struct net_device *dev);
  96. static int skfp_close(struct net_device *dev);
  97. static irqreturn_t skfp_interrupt(int irq, void *dev_id);
  98. static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev);
  99. static void skfp_ctl_set_multicast_list(struct net_device *dev);
  100. static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev);
  101. static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr);
  102. static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
  103. static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
  104. struct net_device *dev);
  105. static void send_queued_packets(struct s_smc *smc);
  106. static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr);
  107. static void ResetAdapter(struct s_smc *smc);
  108. // Functions needed by the hardware module
  109. void *mac_drv_get_space(struct s_smc *smc, u_int size);
  110. void *mac_drv_get_desc_mem(struct s_smc *smc, u_int size);
  111. unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt);
  112. unsigned long dma_master(struct s_smc *smc, void *virt, int len, int flag);
  113. void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr,
  114. int flag);
  115. void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd);
  116. void llc_restart_tx(struct s_smc *smc);
  117. void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  118. int frag_count, int len);
  119. void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  120. int frag_count);
  121. void mac_drv_fill_rxd(struct s_smc *smc);
  122. void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  123. int frag_count);
  124. int mac_drv_rx_init(struct s_smc *smc, int len, int fc, char *look_ahead,
  125. int la_len);
  126. void dump_data(unsigned char *Data, int length);
  127. // External functions from the hardware module
  128. extern u_int mac_drv_check_space(void);
  129. extern int mac_drv_init(struct s_smc *smc);
  130. extern void hwm_tx_frag(struct s_smc *smc, char far * virt, u_long phys,
  131. int len, int frame_status);
  132. extern int hwm_tx_init(struct s_smc *smc, u_char fc, int frag_count,
  133. int frame_len, int frame_status);
  134. extern void fddi_isr(struct s_smc *smc);
  135. extern void hwm_rx_frag(struct s_smc *smc, char far * virt, u_long phys,
  136. int len, int frame_status);
  137. extern void mac_drv_rx_mode(struct s_smc *smc, int mode);
  138. extern void mac_drv_clear_rx_queue(struct s_smc *smc);
  139. extern void enable_tx_irq(struct s_smc *smc, u_short queue);
  140. static const struct pci_device_id skfddi_pci_tbl[] = {
  141. { PCI_VENDOR_ID_SK, PCI_DEVICE_ID_SK_FP, PCI_ANY_ID, PCI_ANY_ID, },
  142. { } /* Terminating entry */
  143. };
  144. MODULE_DEVICE_TABLE(pci, skfddi_pci_tbl);
  145. MODULE_LICENSE("GPL");
  146. MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
  147. // Define module-wide (static) variables
  148. static int num_boards; /* total number of adapters configured */
  149. static const struct net_device_ops skfp_netdev_ops = {
  150. .ndo_open = skfp_open,
  151. .ndo_stop = skfp_close,
  152. .ndo_start_xmit = skfp_send_pkt,
  153. .ndo_get_stats = skfp_ctl_get_stats,
  154. .ndo_change_mtu = fddi_change_mtu,
  155. .ndo_set_rx_mode = skfp_ctl_set_multicast_list,
  156. .ndo_set_mac_address = skfp_ctl_set_mac_address,
  157. .ndo_do_ioctl = skfp_ioctl,
  158. };
  159. /*
  160. * =================
  161. * = skfp_init_one =
  162. * =================
  163. *
  164. * Overview:
  165. * Probes for supported FDDI PCI controllers
  166. *
  167. * Returns:
  168. * Condition code
  169. *
  170. * Arguments:
  171. * pdev - pointer to PCI device information
  172. *
  173. * Functional Description:
  174. * This is now called by PCI driver registration process
  175. * for each board found.
  176. *
  177. * Return Codes:
  178. * 0 - This device (fddi0, fddi1, etc) configured successfully
  179. * -ENODEV - No devices present, or no SysKonnect FDDI PCI device
  180. * present for this device name
  181. *
  182. *
  183. * Side Effects:
  184. * Device structures for FDDI adapters (fddi0, fddi1, etc) are
  185. * initialized and the board resources are read and stored in
  186. * the device structure.
  187. */
  188. static int skfp_init_one(struct pci_dev *pdev,
  189. const struct pci_device_id *ent)
  190. {
  191. struct net_device *dev;
  192. struct s_smc *smc; /* board pointer */
  193. void __iomem *mem;
  194. int err;
  195. pr_debug("entering skfp_init_one\n");
  196. if (num_boards == 0)
  197. printk("%s\n", boot_msg);
  198. err = pci_enable_device(pdev);
  199. if (err)
  200. return err;
  201. err = pci_request_regions(pdev, "skfddi");
  202. if (err)
  203. goto err_out1;
  204. pci_set_master(pdev);
  205. #ifdef MEM_MAPPED_IO
  206. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  207. printk(KERN_ERR "skfp: region is not an MMIO resource\n");
  208. err = -EIO;
  209. goto err_out2;
  210. }
  211. mem = ioremap(pci_resource_start(pdev, 0), 0x4000);
  212. #else
  213. if (!(pci_resource_flags(pdev, 1) & IO_RESOURCE_IO)) {
  214. printk(KERN_ERR "skfp: region is not PIO resource\n");
  215. err = -EIO;
  216. goto err_out2;
  217. }
  218. mem = ioport_map(pci_resource_start(pdev, 1), FP_IO_LEN);
  219. #endif
  220. if (!mem) {
  221. printk(KERN_ERR "skfp: Unable to map register, "
  222. "FDDI adapter will be disabled.\n");
  223. err = -EIO;
  224. goto err_out2;
  225. }
  226. dev = alloc_fddidev(sizeof(struct s_smc));
  227. if (!dev) {
  228. printk(KERN_ERR "skfp: Unable to allocate fddi device, "
  229. "FDDI adapter will be disabled.\n");
  230. err = -ENOMEM;
  231. goto err_out3;
  232. }
  233. dev->irq = pdev->irq;
  234. dev->netdev_ops = &skfp_netdev_ops;
  235. SET_NETDEV_DEV(dev, &pdev->dev);
  236. /* Initialize board structure with bus-specific info */
  237. smc = netdev_priv(dev);
  238. smc->os.dev = dev;
  239. smc->os.bus_type = SK_BUS_TYPE_PCI;
  240. smc->os.pdev = *pdev;
  241. smc->os.QueueSkb = MAX_TX_QUEUE_LEN;
  242. smc->os.MaxFrameSize = MAX_FRAME_SIZE;
  243. smc->os.dev = dev;
  244. smc->hw.slot = -1;
  245. smc->hw.iop = mem;
  246. smc->os.ResetRequested = FALSE;
  247. skb_queue_head_init(&smc->os.SendSkbQueue);
  248. dev->base_addr = (unsigned long)mem;
  249. err = skfp_driver_init(dev);
  250. if (err)
  251. goto err_out4;
  252. err = register_netdev(dev);
  253. if (err)
  254. goto err_out5;
  255. ++num_boards;
  256. pci_set_drvdata(pdev, dev);
  257. if ((pdev->subsystem_device & 0xff00) == 0x5500 ||
  258. (pdev->subsystem_device & 0xff00) == 0x5800)
  259. printk("%s: SysKonnect FDDI PCI adapter"
  260. " found (SK-%04X)\n", dev->name,
  261. pdev->subsystem_device);
  262. else
  263. printk("%s: FDDI PCI adapter found\n", dev->name);
  264. return 0;
  265. err_out5:
  266. if (smc->os.SharedMemAddr)
  267. pci_free_consistent(pdev, smc->os.SharedMemSize,
  268. smc->os.SharedMemAddr,
  269. smc->os.SharedMemDMA);
  270. pci_free_consistent(pdev, MAX_FRAME_SIZE,
  271. smc->os.LocalRxBuffer, smc->os.LocalRxBufferDMA);
  272. err_out4:
  273. free_netdev(dev);
  274. err_out3:
  275. #ifdef MEM_MAPPED_IO
  276. iounmap(mem);
  277. #else
  278. ioport_unmap(mem);
  279. #endif
  280. err_out2:
  281. pci_release_regions(pdev);
  282. err_out1:
  283. pci_disable_device(pdev);
  284. return err;
  285. }
  286. /*
  287. * Called for each adapter board from pci_unregister_driver
  288. */
  289. static void skfp_remove_one(struct pci_dev *pdev)
  290. {
  291. struct net_device *p = pci_get_drvdata(pdev);
  292. struct s_smc *lp = netdev_priv(p);
  293. unregister_netdev(p);
  294. if (lp->os.SharedMemAddr) {
  295. pci_free_consistent(&lp->os.pdev,
  296. lp->os.SharedMemSize,
  297. lp->os.SharedMemAddr,
  298. lp->os.SharedMemDMA);
  299. lp->os.SharedMemAddr = NULL;
  300. }
  301. if (lp->os.LocalRxBuffer) {
  302. pci_free_consistent(&lp->os.pdev,
  303. MAX_FRAME_SIZE,
  304. lp->os.LocalRxBuffer,
  305. lp->os.LocalRxBufferDMA);
  306. lp->os.LocalRxBuffer = NULL;
  307. }
  308. #ifdef MEM_MAPPED_IO
  309. iounmap(lp->hw.iop);
  310. #else
  311. ioport_unmap(lp->hw.iop);
  312. #endif
  313. pci_release_regions(pdev);
  314. free_netdev(p);
  315. pci_disable_device(pdev);
  316. }
  317. /*
  318. * ====================
  319. * = skfp_driver_init =
  320. * ====================
  321. *
  322. * Overview:
  323. * Initializes remaining adapter board structure information
  324. * and makes sure adapter is in a safe state prior to skfp_open().
  325. *
  326. * Returns:
  327. * Condition code
  328. *
  329. * Arguments:
  330. * dev - pointer to device information
  331. *
  332. * Functional Description:
  333. * This function allocates additional resources such as the host memory
  334. * blocks needed by the adapter.
  335. * The adapter is also reset. The OS must call skfp_open() to open
  336. * the adapter and bring it on-line.
  337. *
  338. * Return Codes:
  339. * 0 - initialization succeeded
  340. * -1 - initialization failed
  341. */
  342. static int skfp_driver_init(struct net_device *dev)
  343. {
  344. struct s_smc *smc = netdev_priv(dev);
  345. skfddi_priv *bp = &smc->os;
  346. int err = -EIO;
  347. pr_debug("entering skfp_driver_init\n");
  348. // set the io address in private structures
  349. bp->base_addr = dev->base_addr;
  350. // Get the interrupt level from the PCI Configuration Table
  351. smc->hw.irq = dev->irq;
  352. spin_lock_init(&bp->DriverLock);
  353. // Allocate invalid frame
  354. bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
  355. if (!bp->LocalRxBuffer) {
  356. printk("could not allocate mem for ");
  357. printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
  358. goto fail;
  359. }
  360. // Determine the required size of the 'shared' memory area.
  361. bp->SharedMemSize = mac_drv_check_space();
  362. pr_debug("Memory for HWM: %ld\n", bp->SharedMemSize);
  363. if (bp->SharedMemSize > 0) {
  364. bp->SharedMemSize += 16; // for descriptor alignment
  365. bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
  366. bp->SharedMemSize,
  367. &bp->SharedMemDMA);
  368. if (!bp->SharedMemAddr) {
  369. printk("could not allocate mem for ");
  370. printk("hardware module: %ld byte\n",
  371. bp->SharedMemSize);
  372. goto fail;
  373. }
  374. bp->SharedMemHeap = 0; // Nothing used yet.
  375. } else {
  376. bp->SharedMemAddr = NULL;
  377. bp->SharedMemHeap = 0;
  378. } // SharedMemSize > 0
  379. memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
  380. card_stop(smc); // Reset adapter.
  381. pr_debug("mac_drv_init()..\n");
  382. if (mac_drv_init(smc) != 0) {
  383. pr_debug("mac_drv_init() failed\n");
  384. goto fail;
  385. }
  386. read_address(smc, NULL);
  387. pr_debug("HW-Addr: %pMF\n", smc->hw.fddi_canon_addr.a);
  388. memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, ETH_ALEN);
  389. smt_reset_defaults(smc, 0);
  390. return 0;
  391. fail:
  392. if (bp->SharedMemAddr) {
  393. pci_free_consistent(&bp->pdev,
  394. bp->SharedMemSize,
  395. bp->SharedMemAddr,
  396. bp->SharedMemDMA);
  397. bp->SharedMemAddr = NULL;
  398. }
  399. if (bp->LocalRxBuffer) {
  400. pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
  401. bp->LocalRxBuffer, bp->LocalRxBufferDMA);
  402. bp->LocalRxBuffer = NULL;
  403. }
  404. return err;
  405. } // skfp_driver_init
  406. /*
  407. * =============
  408. * = skfp_open =
  409. * =============
  410. *
  411. * Overview:
  412. * Opens the adapter
  413. *
  414. * Returns:
  415. * Condition code
  416. *
  417. * Arguments:
  418. * dev - pointer to device information
  419. *
  420. * Functional Description:
  421. * This function brings the adapter to an operational state.
  422. *
  423. * Return Codes:
  424. * 0 - Adapter was successfully opened
  425. * -EAGAIN - Could not register IRQ
  426. */
  427. static int skfp_open(struct net_device *dev)
  428. {
  429. struct s_smc *smc = netdev_priv(dev);
  430. int err;
  431. pr_debug("entering skfp_open\n");
  432. /* Register IRQ - support shared interrupts by passing device ptr */
  433. err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED,
  434. dev->name, dev);
  435. if (err)
  436. return err;
  437. /*
  438. * Set current address to factory MAC address
  439. *
  440. * Note: We've already done this step in skfp_driver_init.
  441. * However, it's possible that a user has set a node
  442. * address override, then closed and reopened the
  443. * adapter. Unless we reset the device address field
  444. * now, we'll continue to use the existing modified
  445. * address.
  446. */
  447. read_address(smc, NULL);
  448. memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, ETH_ALEN);
  449. init_smt(smc, NULL);
  450. smt_online(smc, 1);
  451. STI_FBI();
  452. /* Clear local multicast address tables */
  453. mac_clear_multicast(smc);
  454. /* Disable promiscuous filter settings */
  455. mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
  456. netif_start_queue(dev);
  457. return 0;
  458. } // skfp_open
  459. /*
  460. * ==============
  461. * = skfp_close =
  462. * ==============
  463. *
  464. * Overview:
  465. * Closes the device/module.
  466. *
  467. * Returns:
  468. * Condition code
  469. *
  470. * Arguments:
  471. * dev - pointer to device information
  472. *
  473. * Functional Description:
  474. * This routine closes the adapter and brings it to a safe state.
  475. * The interrupt service routine is deregistered with the OS.
  476. * The adapter can be opened again with another call to skfp_open().
  477. *
  478. * Return Codes:
  479. * Always return 0.
  480. *
  481. * Assumptions:
  482. * No further requests for this adapter are made after this routine is
  483. * called. skfp_open() can be called to reset and reinitialize the
  484. * adapter.
  485. */
  486. static int skfp_close(struct net_device *dev)
  487. {
  488. struct s_smc *smc = netdev_priv(dev);
  489. skfddi_priv *bp = &smc->os;
  490. CLI_FBI();
  491. smt_reset_defaults(smc, 1);
  492. card_stop(smc);
  493. mac_drv_clear_tx_queue(smc);
  494. mac_drv_clear_rx_queue(smc);
  495. netif_stop_queue(dev);
  496. /* Deregister (free) IRQ */
  497. free_irq(dev->irq, dev);
  498. skb_queue_purge(&bp->SendSkbQueue);
  499. bp->QueueSkb = MAX_TX_QUEUE_LEN;
  500. return 0;
  501. } // skfp_close
  502. /*
  503. * ==================
  504. * = skfp_interrupt =
  505. * ==================
  506. *
  507. * Overview:
  508. * Interrupt processing routine
  509. *
  510. * Returns:
  511. * None
  512. *
  513. * Arguments:
  514. * irq - interrupt vector
  515. * dev_id - pointer to device information
  516. *
  517. * Functional Description:
  518. * This routine calls the interrupt processing routine for this adapter. It
  519. * disables and reenables adapter interrupts, as appropriate. We can support
  520. * shared interrupts since the incoming dev_id pointer provides our device
  521. * structure context. All the real work is done in the hardware module.
  522. *
  523. * Return Codes:
  524. * None
  525. *
  526. * Assumptions:
  527. * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
  528. * on Intel-based systems) is done by the operating system outside this
  529. * routine.
  530. *
  531. * System interrupts are enabled through this call.
  532. *
  533. * Side Effects:
  534. * Interrupts are disabled, then reenabled at the adapter.
  535. */
  536. static irqreturn_t skfp_interrupt(int irq, void *dev_id)
  537. {
  538. struct net_device *dev = dev_id;
  539. struct s_smc *smc; /* private board structure pointer */
  540. skfddi_priv *bp;
  541. smc = netdev_priv(dev);
  542. bp = &smc->os;
  543. // IRQs enabled or disabled ?
  544. if (inpd(ADDR(B0_IMSK)) == 0) {
  545. // IRQs are disabled: must be shared interrupt
  546. return IRQ_NONE;
  547. }
  548. // Note: At this point, IRQs are enabled.
  549. if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ?
  550. // Adapter did not issue an IRQ: must be shared interrupt
  551. return IRQ_NONE;
  552. }
  553. CLI_FBI(); // Disable IRQs from our adapter.
  554. spin_lock(&bp->DriverLock);
  555. // Call interrupt handler in hardware module (HWM).
  556. fddi_isr(smc);
  557. if (smc->os.ResetRequested) {
  558. ResetAdapter(smc);
  559. smc->os.ResetRequested = FALSE;
  560. }
  561. spin_unlock(&bp->DriverLock);
  562. STI_FBI(); // Enable IRQs from our adapter.
  563. return IRQ_HANDLED;
  564. } // skfp_interrupt
  565. /*
  566. * ======================
  567. * = skfp_ctl_get_stats =
  568. * ======================
  569. *
  570. * Overview:
  571. * Get statistics for FDDI adapter
  572. *
  573. * Returns:
  574. * Pointer to FDDI statistics structure
  575. *
  576. * Arguments:
  577. * dev - pointer to device information
  578. *
  579. * Functional Description:
  580. * Gets current MIB objects from adapter, then
  581. * returns FDDI statistics structure as defined
  582. * in if_fddi.h.
  583. *
  584. * Note: Since the FDDI statistics structure is
  585. * still new and the device structure doesn't
  586. * have an FDDI-specific get statistics handler,
  587. * we'll return the FDDI statistics structure as
  588. * a pointer to an Ethernet statistics structure.
  589. * That way, at least the first part of the statistics
  590. * structure can be decoded properly.
  591. * We'll have to pay attention to this routine as the
  592. * device structure becomes more mature and LAN media
  593. * independent.
  594. *
  595. */
  596. static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
  597. {
  598. struct s_smc *bp = netdev_priv(dev);
  599. /* Fill the bp->stats structure with driver-maintained counters */
  600. bp->os.MacStat.port_bs_flag[0] = 0x1234;
  601. bp->os.MacStat.port_bs_flag[1] = 0x5678;
  602. // goos: need to fill out fddi statistic
  603. #if 0
  604. /* Get FDDI SMT MIB objects */
  605. /* Fill the bp->stats structure with the SMT MIB object values */
  606. memcpy(bp->stats.smt_station_id, &bp->cmd_rsp_virt->smt_mib_get.smt_station_id, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_station_id));
  607. bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
  608. bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
  609. bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
  610. memcpy(bp->stats.smt_user_data, &bp->cmd_rsp_virt->smt_mib_get.smt_user_data, sizeof(bp->cmd_rsp_virt->smt_mib_get.smt_user_data));
  611. bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
  612. bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
  613. bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
  614. bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
  615. bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
  616. bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
  617. bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
  618. bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
  619. bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
  620. bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
  621. bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
  622. bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
  623. bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
  624. bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
  625. bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
  626. bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
  627. bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
  628. bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
  629. bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
  630. bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
  631. bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
  632. bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
  633. bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
  634. bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
  635. memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
  636. memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
  637. memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
  638. memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
  639. bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
  640. bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
  641. bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
  642. memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
  643. bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
  644. bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
  645. bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
  646. bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
  647. bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
  648. bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
  649. bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
  650. bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
  651. bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
  652. bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
  653. bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
  654. bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
  655. bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
  656. bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
  657. bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
  658. bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
  659. memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
  660. bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
  661. bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
  662. bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
  663. bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
  664. bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
  665. bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
  666. bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
  667. bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
  668. bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
  669. bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
  670. memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
  671. memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
  672. bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
  673. bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
  674. bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
  675. bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
  676. bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
  677. bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
  678. bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
  679. bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
  680. bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
  681. bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
  682. bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
  683. bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
  684. bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
  685. bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
  686. bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
  687. bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
  688. bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
  689. bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
  690. bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
  691. bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
  692. bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
  693. bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
  694. bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
  695. bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
  696. bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
  697. bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
  698. /* Fill the bp->stats structure with the FDDI counter values */
  699. bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
  700. bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
  701. bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
  702. bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
  703. bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
  704. bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
  705. bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
  706. bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
  707. bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
  708. bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
  709. bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
  710. #endif
  711. return (struct net_device_stats *)&bp->os.MacStat;
  712. } // ctl_get_stat
  713. /*
  714. * ==============================
  715. * = skfp_ctl_set_multicast_list =
  716. * ==============================
  717. *
  718. * Overview:
  719. * Enable/Disable LLC frame promiscuous mode reception
  720. * on the adapter and/or update multicast address table.
  721. *
  722. * Returns:
  723. * None
  724. *
  725. * Arguments:
  726. * dev - pointer to device information
  727. *
  728. * Functional Description:
  729. * This function acquires the driver lock and only calls
  730. * skfp_ctl_set_multicast_list_wo_lock then.
  731. * This routine follows a fairly simple algorithm for setting the
  732. * adapter filters and CAM:
  733. *
  734. * if IFF_PROMISC flag is set
  735. * enable promiscuous mode
  736. * else
  737. * disable promiscuous mode
  738. * if number of multicast addresses <= max. multicast number
  739. * add mc addresses to adapter table
  740. * else
  741. * enable promiscuous mode
  742. * update adapter filters
  743. *
  744. * Assumptions:
  745. * Multicast addresses are presented in canonical (LSB) format.
  746. *
  747. * Side Effects:
  748. * On-board adapter filters are updated.
  749. */
  750. static void skfp_ctl_set_multicast_list(struct net_device *dev)
  751. {
  752. struct s_smc *smc = netdev_priv(dev);
  753. skfddi_priv *bp = &smc->os;
  754. unsigned long Flags;
  755. spin_lock_irqsave(&bp->DriverLock, Flags);
  756. skfp_ctl_set_multicast_list_wo_lock(dev);
  757. spin_unlock_irqrestore(&bp->DriverLock, Flags);
  758. } // skfp_ctl_set_multicast_list
  759. static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
  760. {
  761. struct s_smc *smc = netdev_priv(dev);
  762. struct netdev_hw_addr *ha;
  763. /* Enable promiscuous mode, if necessary */
  764. if (dev->flags & IFF_PROMISC) {
  765. mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
  766. pr_debug("PROMISCUOUS MODE ENABLED\n");
  767. }
  768. /* Else, update multicast address table */
  769. else {
  770. mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
  771. pr_debug("PROMISCUOUS MODE DISABLED\n");
  772. // Reset all MC addresses
  773. mac_clear_multicast(smc);
  774. mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
  775. if (dev->flags & IFF_ALLMULTI) {
  776. mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
  777. pr_debug("ENABLE ALL MC ADDRESSES\n");
  778. } else if (!netdev_mc_empty(dev)) {
  779. if (netdev_mc_count(dev) <= FPMAX_MULTICAST) {
  780. /* use exact filtering */
  781. // point to first multicast addr
  782. netdev_for_each_mc_addr(ha, dev) {
  783. mac_add_multicast(smc,
  784. (struct fddi_addr *)ha->addr,
  785. 1);
  786. pr_debug("ENABLE MC ADDRESS: %pMF\n",
  787. ha->addr);
  788. }
  789. } else { // more MC addresses than HW supports
  790. mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
  791. pr_debug("ENABLE ALL MC ADDRESSES\n");
  792. }
  793. } else { // no MC addresses
  794. pr_debug("DISABLE ALL MC ADDRESSES\n");
  795. }
  796. /* Update adapter filters */
  797. mac_update_multicast(smc);
  798. }
  799. } // skfp_ctl_set_multicast_list_wo_lock
  800. /*
  801. * ===========================
  802. * = skfp_ctl_set_mac_address =
  803. * ===========================
  804. *
  805. * Overview:
  806. * set new mac address on adapter and update dev_addr field in device table.
  807. *
  808. * Returns:
  809. * None
  810. *
  811. * Arguments:
  812. * dev - pointer to device information
  813. * addr - pointer to sockaddr structure containing unicast address to set
  814. *
  815. * Assumptions:
  816. * The address pointed to by addr->sa_data is a valid unicast
  817. * address and is presented in canonical (LSB) format.
  818. */
  819. static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
  820. {
  821. struct s_smc *smc = netdev_priv(dev);
  822. struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
  823. skfddi_priv *bp = &smc->os;
  824. unsigned long Flags;
  825. memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
  826. spin_lock_irqsave(&bp->DriverLock, Flags);
  827. ResetAdapter(smc);
  828. spin_unlock_irqrestore(&bp->DriverLock, Flags);
  829. return 0; /* always return zero */
  830. } // skfp_ctl_set_mac_address
  831. /*
  832. * ==============
  833. * = skfp_ioctl =
  834. * ==============
  835. *
  836. * Overview:
  837. *
  838. * Perform IOCTL call functions here. Some are privileged operations and the
  839. * effective uid is checked in those cases.
  840. *
  841. * Returns:
  842. * status value
  843. * 0 - success
  844. * other - failure
  845. *
  846. * Arguments:
  847. * dev - pointer to device information
  848. * rq - pointer to ioctl request structure
  849. * cmd - ?
  850. *
  851. */
  852. static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  853. {
  854. struct s_smc *smc = netdev_priv(dev);
  855. skfddi_priv *lp = &smc->os;
  856. struct s_skfp_ioctl ioc;
  857. int status = 0;
  858. if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
  859. return -EFAULT;
  860. switch (ioc.cmd) {
  861. case SKFP_GET_STATS: /* Get the driver statistics */
  862. ioc.len = sizeof(lp->MacStat);
  863. status = copy_to_user(ioc.data, skfp_ctl_get_stats(dev), ioc.len)
  864. ? -EFAULT : 0;
  865. break;
  866. case SKFP_CLR_STATS: /* Zero out the driver statistics */
  867. if (!capable(CAP_NET_ADMIN)) {
  868. status = -EPERM;
  869. } else {
  870. memset(&lp->MacStat, 0, sizeof(lp->MacStat));
  871. }
  872. break;
  873. default:
  874. printk("ioctl for %s: unknown cmd: %04x\n", dev->name, ioc.cmd);
  875. status = -EOPNOTSUPP;
  876. } // switch
  877. return status;
  878. } // skfp_ioctl
  879. /*
  880. * =====================
  881. * = skfp_send_pkt =
  882. * =====================
  883. *
  884. * Overview:
  885. * Queues a packet for transmission and try to transmit it.
  886. *
  887. * Returns:
  888. * Condition code
  889. *
  890. * Arguments:
  891. * skb - pointer to sk_buff to queue for transmission
  892. * dev - pointer to device information
  893. *
  894. * Functional Description:
  895. * Here we assume that an incoming skb transmit request
  896. * is contained in a single physically contiguous buffer
  897. * in which the virtual address of the start of packet
  898. * (skb->data) can be converted to a physical address
  899. * by using pci_map_single().
  900. *
  901. * We have an internal queue for packets we can not send
  902. * immediately. Packets in this queue can be given to the
  903. * adapter if transmit buffers are freed.
  904. *
  905. * We can't free the skb until after it's been DMA'd
  906. * out by the adapter, so we'll keep it in the driver and
  907. * return it in mac_drv_tx_complete.
  908. *
  909. * Return Codes:
  910. * 0 - driver has queued and/or sent packet
  911. * 1 - caller should requeue the sk_buff for later transmission
  912. *
  913. * Assumptions:
  914. * The entire packet is stored in one physically
  915. * contiguous buffer which is not cached and whose
  916. * 32-bit physical address can be determined.
  917. *
  918. * It's vital that this routine is NOT reentered for the
  919. * same board and that the OS is not in another section of
  920. * code (eg. skfp_interrupt) for the same board on a
  921. * different thread.
  922. *
  923. * Side Effects:
  924. * None
  925. */
  926. static netdev_tx_t skfp_send_pkt(struct sk_buff *skb,
  927. struct net_device *dev)
  928. {
  929. struct s_smc *smc = netdev_priv(dev);
  930. skfddi_priv *bp = &smc->os;
  931. pr_debug("skfp_send_pkt\n");
  932. /*
  933. * Verify that incoming transmit request is OK
  934. *
  935. * Note: The packet size check is consistent with other
  936. * Linux device drivers, although the correct packet
  937. * size should be verified before calling the
  938. * transmit routine.
  939. */
  940. if (!(skb->len >= FDDI_K_LLC_ZLEN && skb->len <= FDDI_K_LLC_LEN)) {
  941. bp->MacStat.gen.tx_errors++; /* bump error counter */
  942. // dequeue packets from xmt queue and send them
  943. netif_start_queue(dev);
  944. dev_kfree_skb(skb);
  945. return NETDEV_TX_OK; /* return "success" */
  946. }
  947. if (bp->QueueSkb == 0) { // return with tbusy set: queue full
  948. netif_stop_queue(dev);
  949. return NETDEV_TX_BUSY;
  950. }
  951. bp->QueueSkb--;
  952. skb_queue_tail(&bp->SendSkbQueue, skb);
  953. send_queued_packets(netdev_priv(dev));
  954. if (bp->QueueSkb == 0) {
  955. netif_stop_queue(dev);
  956. }
  957. return NETDEV_TX_OK;
  958. } // skfp_send_pkt
  959. /*
  960. * =======================
  961. * = send_queued_packets =
  962. * =======================
  963. *
  964. * Overview:
  965. * Send packets from the driver queue as long as there are some and
  966. * transmit resources are available.
  967. *
  968. * Returns:
  969. * None
  970. *
  971. * Arguments:
  972. * smc - pointer to smc (adapter) structure
  973. *
  974. * Functional Description:
  975. * Take a packet from queue if there is any. If not, then we are done.
  976. * Check if there are resources to send the packet. If not, requeue it
  977. * and exit.
  978. * Set packet descriptor flags and give packet to adapter.
  979. * Check if any send resources can be freed (we do not use the
  980. * transmit complete interrupt).
  981. */
  982. static void send_queued_packets(struct s_smc *smc)
  983. {
  984. skfddi_priv *bp = &smc->os;
  985. struct sk_buff *skb;
  986. unsigned char fc;
  987. int queue;
  988. struct s_smt_fp_txd *txd; // Current TxD.
  989. dma_addr_t dma_address;
  990. unsigned long Flags;
  991. int frame_status; // HWM tx frame status.
  992. pr_debug("send queued packets\n");
  993. for (;;) {
  994. // send first buffer from queue
  995. skb = skb_dequeue(&bp->SendSkbQueue);
  996. if (!skb) {
  997. pr_debug("queue empty\n");
  998. return;
  999. } // queue empty !
  1000. spin_lock_irqsave(&bp->DriverLock, Flags);
  1001. fc = skb->data[0];
  1002. queue = (fc & FC_SYNC_BIT) ? QUEUE_S : QUEUE_A0;
  1003. #ifdef ESS
  1004. // Check if the frame may/must be sent as a synchronous frame.
  1005. if ((fc & ~(FC_SYNC_BIT | FC_LLC_PRIOR)) == FC_ASYNC_LLC) {
  1006. // It's an LLC frame.
  1007. if (!smc->ess.sync_bw_available)
  1008. fc &= ~FC_SYNC_BIT; // No bandwidth available.
  1009. else { // Bandwidth is available.
  1010. if (smc->mib.fddiESSSynchTxMode) {
  1011. // Send as sync. frame.
  1012. fc |= FC_SYNC_BIT;
  1013. }
  1014. }
  1015. }
  1016. #endif // ESS
  1017. frame_status = hwm_tx_init(smc, fc, 1, skb->len, queue);
  1018. if ((frame_status & (LOC_TX | LAN_TX)) == 0) {
  1019. // Unable to send the frame.
  1020. if ((frame_status & RING_DOWN) != 0) {
  1021. // Ring is down.
  1022. pr_debug("Tx attempt while ring down.\n");
  1023. } else if ((frame_status & OUT_OF_TXD) != 0) {
  1024. pr_debug("%s: out of TXDs.\n", bp->dev->name);
  1025. } else {
  1026. pr_debug("%s: out of transmit resources",
  1027. bp->dev->name);
  1028. }
  1029. // Note: We will retry the operation as soon as
  1030. // transmit resources become available.
  1031. skb_queue_head(&bp->SendSkbQueue, skb);
  1032. spin_unlock_irqrestore(&bp->DriverLock, Flags);
  1033. return; // Packet has been queued.
  1034. } // if (unable to send frame)
  1035. bp->QueueSkb++; // one packet less in local queue
  1036. // source address in packet ?
  1037. CheckSourceAddress(skb->data, smc->hw.fddi_canon_addr.a);
  1038. txd = (struct s_smt_fp_txd *) HWM_GET_CURR_TXD(smc, queue);
  1039. dma_address = pci_map_single(&bp->pdev, skb->data,
  1040. skb->len, PCI_DMA_TODEVICE);
  1041. if (frame_status & LAN_TX) {
  1042. txd->txd_os.skb = skb; // save skb
  1043. txd->txd_os.dma_addr = dma_address; // save dma mapping
  1044. }
  1045. hwm_tx_frag(smc, skb->data, dma_address, skb->len,
  1046. frame_status | FIRST_FRAG | LAST_FRAG | EN_IRQ_EOF);
  1047. if (!(frame_status & LAN_TX)) { // local only frame
  1048. pci_unmap_single(&bp->pdev, dma_address,
  1049. skb->len, PCI_DMA_TODEVICE);
  1050. dev_kfree_skb_irq(skb);
  1051. }
  1052. spin_unlock_irqrestore(&bp->DriverLock, Flags);
  1053. } // for
  1054. return; // never reached
  1055. } // send_queued_packets
  1056. /************************
  1057. *
  1058. * CheckSourceAddress
  1059. *
  1060. * Verify if the source address is set. Insert it if necessary.
  1061. *
  1062. ************************/
  1063. static void CheckSourceAddress(unsigned char *frame, unsigned char *hw_addr)
  1064. {
  1065. unsigned char SRBit;
  1066. if ((((unsigned long) frame[1 + 6]) & ~0x01) != 0) // source routing bit
  1067. return;
  1068. if ((unsigned short) frame[1 + 10] != 0)
  1069. return;
  1070. SRBit = frame[1 + 6] & 0x01;
  1071. memcpy(&frame[1 + 6], hw_addr, ETH_ALEN);
  1072. frame[8] |= SRBit;
  1073. } // CheckSourceAddress
  1074. /************************
  1075. *
  1076. * ResetAdapter
  1077. *
  1078. * Reset the adapter and bring it back to operational mode.
  1079. * Args
  1080. * smc - A pointer to the SMT context struct.
  1081. * Out
  1082. * Nothing.
  1083. *
  1084. ************************/
  1085. static void ResetAdapter(struct s_smc *smc)
  1086. {
  1087. pr_debug("[fddi: ResetAdapter]\n");
  1088. // Stop the adapter.
  1089. card_stop(smc); // Stop all activity.
  1090. // Clear the transmit and receive descriptor queues.
  1091. mac_drv_clear_tx_queue(smc);
  1092. mac_drv_clear_rx_queue(smc);
  1093. // Restart the adapter.
  1094. smt_reset_defaults(smc, 1); // Initialize the SMT module.
  1095. init_smt(smc, (smc->os.dev)->dev_addr); // Initialize the hardware.
  1096. smt_online(smc, 1); // Insert into the ring again.
  1097. STI_FBI();
  1098. // Restore original receive mode (multicasts, promiscuous, etc.).
  1099. skfp_ctl_set_multicast_list_wo_lock(smc->os.dev);
  1100. } // ResetAdapter
  1101. //--------------- functions called by hardware module ----------------
  1102. /************************
  1103. *
  1104. * llc_restart_tx
  1105. *
  1106. * The hardware driver calls this routine when the transmit complete
  1107. * interrupt bits (end of frame) for the synchronous or asynchronous
  1108. * queue is set.
  1109. *
  1110. * NOTE The hardware driver calls this function also if no packets are queued.
  1111. * The routine must be able to handle this case.
  1112. * Args
  1113. * smc - A pointer to the SMT context struct.
  1114. * Out
  1115. * Nothing.
  1116. *
  1117. ************************/
  1118. void llc_restart_tx(struct s_smc *smc)
  1119. {
  1120. skfddi_priv *bp = &smc->os;
  1121. pr_debug("[llc_restart_tx]\n");
  1122. // Try to send queued packets
  1123. spin_unlock(&bp->DriverLock);
  1124. send_queued_packets(smc);
  1125. spin_lock(&bp->DriverLock);
  1126. netif_start_queue(bp->dev);// system may send again if it was blocked
  1127. } // llc_restart_tx
  1128. /************************
  1129. *
  1130. * mac_drv_get_space
  1131. *
  1132. * The hardware module calls this function to allocate the memory
  1133. * for the SMT MBufs if the define MB_OUTSIDE_SMC is specified.
  1134. * Args
  1135. * smc - A pointer to the SMT context struct.
  1136. *
  1137. * size - Size of memory in bytes to allocate.
  1138. * Out
  1139. * != 0 A pointer to the virtual address of the allocated memory.
  1140. * == 0 Allocation error.
  1141. *
  1142. ************************/
  1143. void *mac_drv_get_space(struct s_smc *smc, unsigned int size)
  1144. {
  1145. void *virt;
  1146. pr_debug("mac_drv_get_space (%d bytes), ", size);
  1147. virt = (void *) (smc->os.SharedMemAddr + smc->os.SharedMemHeap);
  1148. if ((smc->os.SharedMemHeap + size) > smc->os.SharedMemSize) {
  1149. printk("Unexpected SMT memory size requested: %d\n", size);
  1150. return NULL;
  1151. }
  1152. smc->os.SharedMemHeap += size; // Move heap pointer.
  1153. pr_debug("mac_drv_get_space end\n");
  1154. pr_debug("virt addr: %lx\n", (ulong) virt);
  1155. pr_debug("bus addr: %lx\n", (ulong)
  1156. (smc->os.SharedMemDMA +
  1157. ((char *) virt - (char *)smc->os.SharedMemAddr)));
  1158. return virt;
  1159. } // mac_drv_get_space
  1160. /************************
  1161. *
  1162. * mac_drv_get_desc_mem
  1163. *
  1164. * This function is called by the hardware dependent module.
  1165. * It allocates the memory for the RxD and TxD descriptors.
  1166. *
  1167. * This memory must be non-cached, non-movable and non-swappable.
  1168. * This memory should start at a physical page boundary.
  1169. * Args
  1170. * smc - A pointer to the SMT context struct.
  1171. *
  1172. * size - Size of memory in bytes to allocate.
  1173. * Out
  1174. * != 0 A pointer to the virtual address of the allocated memory.
  1175. * == 0 Allocation error.
  1176. *
  1177. ************************/
  1178. void *mac_drv_get_desc_mem(struct s_smc *smc, unsigned int size)
  1179. {
  1180. char *virt;
  1181. pr_debug("mac_drv_get_desc_mem\n");
  1182. // Descriptor memory must be aligned on 16-byte boundary.
  1183. virt = mac_drv_get_space(smc, size);
  1184. size = (u_int) (16 - (((unsigned long) virt) & 15UL));
  1185. size = size % 16;
  1186. pr_debug("Allocate %u bytes alignment gap ", size);
  1187. pr_debug("for descriptor memory.\n");
  1188. if (!mac_drv_get_space(smc, size)) {
  1189. printk("fddi: Unable to align descriptor memory.\n");
  1190. return NULL;
  1191. }
  1192. return virt + size;
  1193. } // mac_drv_get_desc_mem
  1194. /************************
  1195. *
  1196. * mac_drv_virt2phys
  1197. *
  1198. * Get the physical address of a given virtual address.
  1199. * Args
  1200. * smc - A pointer to the SMT context struct.
  1201. *
  1202. * virt - A (virtual) pointer into our 'shared' memory area.
  1203. * Out
  1204. * Physical address of the given virtual address.
  1205. *
  1206. ************************/
  1207. unsigned long mac_drv_virt2phys(struct s_smc *smc, void *virt)
  1208. {
  1209. return smc->os.SharedMemDMA +
  1210. ((char *) virt - (char *)smc->os.SharedMemAddr);
  1211. } // mac_drv_virt2phys
  1212. /************************
  1213. *
  1214. * dma_master
  1215. *
  1216. * The HWM calls this function, when the driver leads through a DMA
  1217. * transfer. If the OS-specific module must prepare the system hardware
  1218. * for the DMA transfer, it should do it in this function.
  1219. *
  1220. * The hardware module calls this dma_master if it wants to send an SMT
  1221. * frame. This means that the virt address passed in here is part of
  1222. * the 'shared' memory area.
  1223. * Args
  1224. * smc - A pointer to the SMT context struct.
  1225. *
  1226. * virt - The virtual address of the data.
  1227. *
  1228. * len - The length in bytes of the data.
  1229. *
  1230. * flag - Indicates the transmit direction and the buffer type:
  1231. * DMA_RD (0x01) system RAM ==> adapter buffer memory
  1232. * DMA_WR (0x02) adapter buffer memory ==> system RAM
  1233. * SMT_BUF (0x80) SMT buffer
  1234. *
  1235. * >> NOTE: SMT_BUF and DMA_RD are always set for PCI. <<
  1236. * Out
  1237. * Returns the pyhsical address for the DMA transfer.
  1238. *
  1239. ************************/
  1240. u_long dma_master(struct s_smc * smc, void *virt, int len, int flag)
  1241. {
  1242. return smc->os.SharedMemDMA +
  1243. ((char *) virt - (char *)smc->os.SharedMemAddr);
  1244. } // dma_master
  1245. /************************
  1246. *
  1247. * dma_complete
  1248. *
  1249. * The hardware module calls this routine when it has completed a DMA
  1250. * transfer. If the operating system dependent module has set up the DMA
  1251. * channel via dma_master() (e.g. Windows NT or AIX) it should clean up
  1252. * the DMA channel.
  1253. * Args
  1254. * smc - A pointer to the SMT context struct.
  1255. *
  1256. * descr - A pointer to a TxD or RxD, respectively.
  1257. *
  1258. * flag - Indicates the DMA transfer direction / SMT buffer:
  1259. * DMA_RD (0x01) system RAM ==> adapter buffer memory
  1260. * DMA_WR (0x02) adapter buffer memory ==> system RAM
  1261. * SMT_BUF (0x80) SMT buffer (managed by HWM)
  1262. * Out
  1263. * Nothing.
  1264. *
  1265. ************************/
  1266. void dma_complete(struct s_smc *smc, volatile union s_fp_descr *descr, int flag)
  1267. {
  1268. /* For TX buffers, there are two cases. If it is an SMT transmit
  1269. * buffer, there is nothing to do since we use consistent memory
  1270. * for the 'shared' memory area. The other case is for normal
  1271. * transmit packets given to us by the networking stack, and in
  1272. * that case we cleanup the PCI DMA mapping in mac_drv_tx_complete
  1273. * below.
  1274. *
  1275. * For RX buffers, we have to unmap dynamic PCI DMA mappings here
  1276. * because the hardware module is about to potentially look at
  1277. * the contents of the buffer. If we did not call the PCI DMA
  1278. * unmap first, the hardware module could read inconsistent data.
  1279. */
  1280. if (flag & DMA_WR) {
  1281. skfddi_priv *bp = &smc->os;
  1282. volatile struct s_smt_fp_rxd *r = &descr->r;
  1283. /* If SKB is NULL, we used the local buffer. */
  1284. if (r->rxd_os.skb && r->rxd_os.dma_addr) {
  1285. int MaxFrameSize = bp->MaxFrameSize;
  1286. pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
  1287. MaxFrameSize, PCI_DMA_FROMDEVICE);
  1288. r->rxd_os.dma_addr = 0;
  1289. }
  1290. }
  1291. } // dma_complete
  1292. /************************
  1293. *
  1294. * mac_drv_tx_complete
  1295. *
  1296. * Transmit of a packet is complete. Release the tx staging buffer.
  1297. *
  1298. * Args
  1299. * smc - A pointer to the SMT context struct.
  1300. *
  1301. * txd - A pointer to the last TxD which is used by the frame.
  1302. * Out
  1303. * Returns nothing.
  1304. *
  1305. ************************/
  1306. void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
  1307. {
  1308. struct sk_buff *skb;
  1309. pr_debug("entering mac_drv_tx_complete\n");
  1310. // Check if this TxD points to a skb
  1311. if (!(skb = txd->txd_os.skb)) {
  1312. pr_debug("TXD with no skb assigned.\n");
  1313. return;
  1314. }
  1315. txd->txd_os.skb = NULL;
  1316. // release the DMA mapping
  1317. pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
  1318. skb->len, PCI_DMA_TODEVICE);
  1319. txd->txd_os.dma_addr = 0;
  1320. smc->os.MacStat.gen.tx_packets++; // Count transmitted packets.
  1321. smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
  1322. // free the skb
  1323. dev_kfree_skb_irq(skb);
  1324. pr_debug("leaving mac_drv_tx_complete\n");
  1325. } // mac_drv_tx_complete
  1326. /************************
  1327. *
  1328. * dump packets to logfile
  1329. *
  1330. ************************/
  1331. #ifdef DUMPPACKETS
  1332. void dump_data(unsigned char *Data, int length)
  1333. {
  1334. int i, j;
  1335. unsigned char s[255], sh[10];
  1336. if (length > 64) {
  1337. length = 64;
  1338. }
  1339. printk(KERN_INFO "---Packet start---\n");
  1340. for (i = 0, j = 0; i < length / 8; i++, j += 8)
  1341. printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  1342. Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
  1343. Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
  1344. strcpy(s, "");
  1345. for (i = 0; i < length % 8; i++) {
  1346. sprintf(sh, "%02x ", Data[j + i]);
  1347. strcat(s, sh);
  1348. }
  1349. printk(KERN_INFO "%s\n", s);
  1350. printk(KERN_INFO "------------------\n");
  1351. } // dump_data
  1352. #else
  1353. #define dump_data(data,len)
  1354. #endif // DUMPPACKETS
  1355. /************************
  1356. *
  1357. * mac_drv_rx_complete
  1358. *
  1359. * The hardware module calls this function if an LLC frame is received
  1360. * in a receive buffer. Also the SMT, NSA, and directed beacon frames
  1361. * from the network will be passed to the LLC layer by this function
  1362. * if passing is enabled.
  1363. *
  1364. * mac_drv_rx_complete forwards the frame to the LLC layer if it should
  1365. * be received. It also fills the RxD ring with new receive buffers if
  1366. * some can be queued.
  1367. * Args
  1368. * smc - A pointer to the SMT context struct.
  1369. *
  1370. * rxd - A pointer to the first RxD which is used by the receive frame.
  1371. *
  1372. * frag_count - Count of RxDs used by the received frame.
  1373. *
  1374. * len - Frame length.
  1375. * Out
  1376. * Nothing.
  1377. *
  1378. ************************/
  1379. void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  1380. int frag_count, int len)
  1381. {
  1382. skfddi_priv *bp = &smc->os;
  1383. struct sk_buff *skb;
  1384. unsigned char *virt, *cp;
  1385. unsigned short ri;
  1386. u_int RifLength;
  1387. pr_debug("entering mac_drv_rx_complete (len=%d)\n", len);
  1388. if (frag_count != 1) { // This is not allowed to happen.
  1389. printk("fddi: Multi-fragment receive!\n");
  1390. goto RequeueRxd; // Re-use the given RXD(s).
  1391. }
  1392. skb = rxd->rxd_os.skb;
  1393. if (!skb) {
  1394. pr_debug("No skb in rxd\n");
  1395. smc->os.MacStat.gen.rx_errors++;
  1396. goto RequeueRxd;
  1397. }
  1398. virt = skb->data;
  1399. // The DMA mapping was released in dma_complete above.
  1400. dump_data(skb->data, len);
  1401. /*
  1402. * FDDI Frame format:
  1403. * +-------+-------+-------+------------+--------+------------+
  1404. * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
  1405. * +-------+-------+-------+------------+--------+------------+
  1406. *
  1407. * FC = Frame Control
  1408. * DA = Destination Address
  1409. * SA = Source Address
  1410. * RIF = Routing Information Field
  1411. * LLC = Logical Link Control
  1412. */
  1413. // Remove Routing Information Field (RIF), if present.
  1414. if ((virt[1 + 6] & FDDI_RII) == 0)
  1415. RifLength = 0;
  1416. else {
  1417. int n;
  1418. // goos: RIF removal has still to be tested
  1419. pr_debug("RIF found\n");
  1420. // Get RIF length from Routing Control (RC) field.
  1421. cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
  1422. ri = ntohs(*((__be16 *) cp));
  1423. RifLength = ri & FDDI_RCF_LEN_MASK;
  1424. if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
  1425. printk("fddi: Invalid RIF.\n");
  1426. goto RequeueRxd; // Discard the frame.
  1427. }
  1428. virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
  1429. // regions overlap
  1430. virt = cp + RifLength;
  1431. for (n = FDDI_MAC_HDR_LEN; n; n--)
  1432. *--virt = *--cp;
  1433. // adjust sbd->data pointer
  1434. skb_pull(skb, RifLength);
  1435. len -= RifLength;
  1436. RifLength = 0;
  1437. }
  1438. // Count statistics.
  1439. smc->os.MacStat.gen.rx_packets++; // Count indicated receive
  1440. // packets.
  1441. smc->os.MacStat.gen.rx_bytes+=len; // Count bytes.
  1442. // virt points to header again
  1443. if (virt[1] & 0x01) { // Check group (multicast) bit.
  1444. smc->os.MacStat.gen.multicast++;
  1445. }
  1446. // deliver frame to system
  1447. rxd->rxd_os.skb = NULL;
  1448. skb_trim(skb, len);
  1449. skb->protocol = fddi_type_trans(skb, bp->dev);
  1450. netif_rx(skb);
  1451. HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
  1452. return;
  1453. RequeueRxd:
  1454. pr_debug("Rx: re-queue RXD.\n");
  1455. mac_drv_requeue_rxd(smc, rxd, frag_count);
  1456. smc->os.MacStat.gen.rx_errors++; // Count receive packets
  1457. // not indicated.
  1458. } // mac_drv_rx_complete
  1459. /************************
  1460. *
  1461. * mac_drv_requeue_rxd
  1462. *
  1463. * The hardware module calls this function to request the OS-specific
  1464. * module to queue the receive buffer(s) represented by the pointer
  1465. * to the RxD and the frag_count into the receive queue again. This
  1466. * buffer was filled with an invalid frame or an SMT frame.
  1467. * Args
  1468. * smc - A pointer to the SMT context struct.
  1469. *
  1470. * rxd - A pointer to the first RxD which is used by the receive frame.
  1471. *
  1472. * frag_count - Count of RxDs used by the received frame.
  1473. * Out
  1474. * Nothing.
  1475. *
  1476. ************************/
  1477. void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  1478. int frag_count)
  1479. {
  1480. volatile struct s_smt_fp_rxd *next_rxd;
  1481. volatile struct s_smt_fp_rxd *src_rxd;
  1482. struct sk_buff *skb;
  1483. int MaxFrameSize;
  1484. unsigned char *v_addr;
  1485. dma_addr_t b_addr;
  1486. if (frag_count != 1) // This is not allowed to happen.
  1487. printk("fddi: Multi-fragment requeue!\n");
  1488. MaxFrameSize = smc->os.MaxFrameSize;
  1489. src_rxd = rxd;
  1490. for (; frag_count > 0; frag_count--) {
  1491. next_rxd = src_rxd->rxd_next;
  1492. rxd = HWM_GET_CURR_RXD(smc);
  1493. skb = src_rxd->rxd_os.skb;
  1494. if (skb == NULL) { // this should not happen
  1495. pr_debug("Requeue with no skb in rxd!\n");
  1496. skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
  1497. if (skb) {
  1498. // we got a skb
  1499. rxd->rxd_os.skb = skb;
  1500. skb_reserve(skb, 3);
  1501. skb_put(skb, MaxFrameSize);
  1502. v_addr = skb->data;
  1503. b_addr = pci_map_single(&smc->os.pdev,
  1504. v_addr,
  1505. MaxFrameSize,
  1506. PCI_DMA_FROMDEVICE);
  1507. rxd->rxd_os.dma_addr = b_addr;
  1508. } else {
  1509. // no skb available, use local buffer
  1510. pr_debug("Queueing invalid buffer!\n");
  1511. rxd->rxd_os.skb = NULL;
  1512. v_addr = smc->os.LocalRxBuffer;
  1513. b_addr = smc->os.LocalRxBufferDMA;
  1514. }
  1515. } else {
  1516. // we use skb from old rxd
  1517. rxd->rxd_os.skb = skb;
  1518. v_addr = skb->data;
  1519. b_addr = pci_map_single(&smc->os.pdev,
  1520. v_addr,
  1521. MaxFrameSize,
  1522. PCI_DMA_FROMDEVICE);
  1523. rxd->rxd_os.dma_addr = b_addr;
  1524. }
  1525. hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
  1526. FIRST_FRAG | LAST_FRAG);
  1527. src_rxd = next_rxd;
  1528. }
  1529. } // mac_drv_requeue_rxd
  1530. /************************
  1531. *
  1532. * mac_drv_fill_rxd
  1533. *
  1534. * The hardware module calls this function at initialization time
  1535. * to fill the RxD ring with receive buffers. It is also called by
  1536. * mac_drv_rx_complete if rx_free is large enough to queue some new
  1537. * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
  1538. * receive buffers as long as enough RxDs and receive buffers are
  1539. * available.
  1540. * Args
  1541. * smc - A pointer to the SMT context struct.
  1542. * Out
  1543. * Nothing.
  1544. *
  1545. ************************/
  1546. void mac_drv_fill_rxd(struct s_smc *smc)
  1547. {
  1548. int MaxFrameSize;
  1549. unsigned char *v_addr;
  1550. unsigned long b_addr;
  1551. struct sk_buff *skb;
  1552. volatile struct s_smt_fp_rxd *rxd;
  1553. pr_debug("entering mac_drv_fill_rxd\n");
  1554. // Walk through the list of free receive buffers, passing receive
  1555. // buffers to the HWM as long as RXDs are available.
  1556. MaxFrameSize = smc->os.MaxFrameSize;
  1557. // Check if there is any RXD left.
  1558. while (HWM_GET_RX_FREE(smc) > 0) {
  1559. pr_debug(".\n");
  1560. rxd = HWM_GET_CURR_RXD(smc);
  1561. skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
  1562. if (skb) {
  1563. // we got a skb
  1564. skb_reserve(skb, 3);
  1565. skb_put(skb, MaxFrameSize);
  1566. v_addr = skb->data;
  1567. b_addr = pci_map_single(&smc->os.pdev,
  1568. v_addr,
  1569. MaxFrameSize,
  1570. PCI_DMA_FROMDEVICE);
  1571. rxd->rxd_os.dma_addr = b_addr;
  1572. } else {
  1573. // no skb available, use local buffer
  1574. // System has run out of buffer memory, but we want to
  1575. // keep the receiver running in hope of better times.
  1576. // Multiple descriptors may point to this local buffer,
  1577. // so data in it must be considered invalid.
  1578. pr_debug("Queueing invalid buffer!\n");
  1579. v_addr = smc->os.LocalRxBuffer;
  1580. b_addr = smc->os.LocalRxBufferDMA;
  1581. }
  1582. rxd->rxd_os.skb = skb;
  1583. // Pass receive buffer to HWM.
  1584. hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
  1585. FIRST_FRAG | LAST_FRAG);
  1586. }
  1587. pr_debug("leaving mac_drv_fill_rxd\n");
  1588. } // mac_drv_fill_rxd
  1589. /************************
  1590. *
  1591. * mac_drv_clear_rxd
  1592. *
  1593. * The hardware module calls this function to release unused
  1594. * receive buffers.
  1595. * Args
  1596. * smc - A pointer to the SMT context struct.
  1597. *
  1598. * rxd - A pointer to the first RxD which is used by the receive buffer.
  1599. *
  1600. * frag_count - Count of RxDs used by the receive buffer.
  1601. * Out
  1602. * Nothing.
  1603. *
  1604. ************************/
  1605. void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  1606. int frag_count)
  1607. {
  1608. struct sk_buff *skb;
  1609. pr_debug("entering mac_drv_clear_rxd\n");
  1610. if (frag_count != 1) // This is not allowed to happen.
  1611. printk("fddi: Multi-fragment clear!\n");
  1612. for (; frag_count > 0; frag_count--) {
  1613. skb = rxd->rxd_os.skb;
  1614. if (skb != NULL) {
  1615. skfddi_priv *bp = &smc->os;
  1616. int MaxFrameSize = bp->MaxFrameSize;
  1617. pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
  1618. MaxFrameSize, PCI_DMA_FROMDEVICE);
  1619. dev_kfree_skb(skb);
  1620. rxd->rxd_os.skb = NULL;
  1621. }
  1622. rxd = rxd->rxd_next; // Next RXD.
  1623. }
  1624. } // mac_drv_clear_rxd
  1625. /************************
  1626. *
  1627. * mac_drv_rx_init
  1628. *
  1629. * The hardware module calls this routine when an SMT or NSA frame of the
  1630. * local SMT should be delivered to the LLC layer.
  1631. *
  1632. * It is necessary to have this function, because there is no other way to
  1633. * copy the contents of SMT MBufs into receive buffers.
  1634. *
  1635. * mac_drv_rx_init allocates the required target memory for this frame,
  1636. * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
  1637. * Args
  1638. * smc - A pointer to the SMT context struct.
  1639. *
  1640. * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
  1641. *
  1642. * fc - The Frame Control field of the received frame.
  1643. *
  1644. * look_ahead - A pointer to the lookahead data buffer (may be NULL).
  1645. *
  1646. * la_len - The length of the lookahead data stored in the lookahead
  1647. * buffer (may be zero).
  1648. * Out
  1649. * Always returns zero (0).
  1650. *
  1651. ************************/
  1652. int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
  1653. char *look_ahead, int la_len)
  1654. {
  1655. struct sk_buff *skb;
  1656. pr_debug("entering mac_drv_rx_init(len=%d)\n", len);
  1657. // "Received" a SMT or NSA frame of the local SMT.
  1658. if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
  1659. pr_debug("fddi: Discard invalid local SMT frame\n");
  1660. pr_debug(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
  1661. len, la_len, (unsigned long) look_ahead);
  1662. return 0;
  1663. }
  1664. skb = alloc_skb(len + 3, GFP_ATOMIC);
  1665. if (!skb) {
  1666. pr_debug("fddi: Local SMT: skb memory exhausted.\n");
  1667. return 0;
  1668. }
  1669. skb_reserve(skb, 3);
  1670. skb_put(skb, len);
  1671. skb_copy_to_linear_data(skb, look_ahead, len);
  1672. // deliver frame to system
  1673. skb->protocol = fddi_type_trans(skb, smc->os.dev);
  1674. netif_rx(skb);
  1675. return 0;
  1676. } // mac_drv_rx_init
  1677. /************************
  1678. *
  1679. * smt_timer_poll
  1680. *
  1681. * This routine is called periodically by the SMT module to clean up the
  1682. * driver.
  1683. *
  1684. * Return any queued frames back to the upper protocol layers if the ring
  1685. * is down.
  1686. * Args
  1687. * smc - A pointer to the SMT context struct.
  1688. * Out
  1689. * Nothing.
  1690. *
  1691. ************************/
  1692. void smt_timer_poll(struct s_smc *smc)
  1693. {
  1694. } // smt_timer_poll
  1695. /************************
  1696. *
  1697. * ring_status_indication
  1698. *
  1699. * This function indicates a change of the ring state.
  1700. * Args
  1701. * smc - A pointer to the SMT context struct.
  1702. *
  1703. * status - The current ring status.
  1704. * Out
  1705. * Nothing.
  1706. *
  1707. ************************/
  1708. void ring_status_indication(struct s_smc *smc, u_long status)
  1709. {
  1710. pr_debug("ring_status_indication( ");
  1711. if (status & RS_RES15)
  1712. pr_debug("RS_RES15 ");
  1713. if (status & RS_HARDERROR)
  1714. pr_debug("RS_HARDERROR ");
  1715. if (status & RS_SOFTERROR)
  1716. pr_debug("RS_SOFTERROR ");
  1717. if (status & RS_BEACON)
  1718. pr_debug("RS_BEACON ");
  1719. if (status & RS_PATHTEST)
  1720. pr_debug("RS_PATHTEST ");
  1721. if (status & RS_SELFTEST)
  1722. pr_debug("RS_SELFTEST ");
  1723. if (status & RS_RES9)
  1724. pr_debug("RS_RES9 ");
  1725. if (status & RS_DISCONNECT)
  1726. pr_debug("RS_DISCONNECT ");
  1727. if (status & RS_RES7)
  1728. pr_debug("RS_RES7 ");
  1729. if (status & RS_DUPADDR)
  1730. pr_debug("RS_DUPADDR ");
  1731. if (status & RS_NORINGOP)
  1732. pr_debug("RS_NORINGOP ");
  1733. if (status & RS_VERSION)
  1734. pr_debug("RS_VERSION ");
  1735. if (status & RS_STUCKBYPASSS)
  1736. pr_debug("RS_STUCKBYPASSS ");
  1737. if (status & RS_EVENT)
  1738. pr_debug("RS_EVENT ");
  1739. if (status & RS_RINGOPCHANGE)
  1740. pr_debug("RS_RINGOPCHANGE ");
  1741. if (status & RS_RES0)
  1742. pr_debug("RS_RES0 ");
  1743. pr_debug("]\n");
  1744. } // ring_status_indication
  1745. /************************
  1746. *
  1747. * smt_get_time
  1748. *
  1749. * Gets the current time from the system.
  1750. * Args
  1751. * None.
  1752. * Out
  1753. * The current time in TICKS_PER_SECOND.
  1754. *
  1755. * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
  1756. * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
  1757. * to the time returned by smt_get_time().
  1758. *
  1759. ************************/
  1760. unsigned long smt_get_time(void)
  1761. {
  1762. return jiffies;
  1763. } // smt_get_time
  1764. /************************
  1765. *
  1766. * smt_stat_counter
  1767. *
  1768. * Status counter update (ring_op, fifo full).
  1769. * Args
  1770. * smc - A pointer to the SMT context struct.
  1771. *
  1772. * stat - = 0: A ring operational change occurred.
  1773. * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
  1774. * Out
  1775. * Nothing.
  1776. *
  1777. ************************/
  1778. void smt_stat_counter(struct s_smc *smc, int stat)
  1779. {
  1780. // BOOLEAN RingIsUp ;
  1781. pr_debug("smt_stat_counter\n");
  1782. switch (stat) {
  1783. case 0:
  1784. pr_debug("Ring operational change.\n");
  1785. break;
  1786. case 1:
  1787. pr_debug("Receive fifo overflow.\n");
  1788. smc->os.MacStat.gen.rx_errors++;
  1789. break;
  1790. default:
  1791. pr_debug("Unknown status (%d).\n", stat);
  1792. break;
  1793. }
  1794. } // smt_stat_counter
  1795. /************************
  1796. *
  1797. * cfm_state_change
  1798. *
  1799. * Sets CFM state in custom statistics.
  1800. * Args
  1801. * smc - A pointer to the SMT context struct.
  1802. *
  1803. * c_state - Possible values are:
  1804. *
  1805. * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
  1806. * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
  1807. * Out
  1808. * Nothing.
  1809. *
  1810. ************************/
  1811. void cfm_state_change(struct s_smc *smc, int c_state)
  1812. {
  1813. #ifdef DRIVERDEBUG
  1814. char *s;
  1815. switch (c_state) {
  1816. case SC0_ISOLATED:
  1817. s = "SC0_ISOLATED";
  1818. break;
  1819. case SC1_WRAP_A:
  1820. s = "SC1_WRAP_A";
  1821. break;
  1822. case SC2_WRAP_B:
  1823. s = "SC2_WRAP_B";
  1824. break;
  1825. case SC4_THRU_A:
  1826. s = "SC4_THRU_A";
  1827. break;
  1828. case SC5_THRU_B:
  1829. s = "SC5_THRU_B";
  1830. break;
  1831. case SC7_WRAP_S:
  1832. s = "SC7_WRAP_S";
  1833. break;
  1834. case SC9_C_WRAP_A:
  1835. s = "SC9_C_WRAP_A";
  1836. break;
  1837. case SC10_C_WRAP_B:
  1838. s = "SC10_C_WRAP_B";
  1839. break;
  1840. case SC11_C_WRAP_S:
  1841. s = "SC11_C_WRAP_S";
  1842. break;
  1843. default:
  1844. pr_debug("cfm_state_change: unknown %d\n", c_state);
  1845. return;
  1846. }
  1847. pr_debug("cfm_state_change: %s\n", s);
  1848. #endif // DRIVERDEBUG
  1849. } // cfm_state_change
  1850. /************************
  1851. *
  1852. * ecm_state_change
  1853. *
  1854. * Sets ECM state in custom statistics.
  1855. * Args
  1856. * smc - A pointer to the SMT context struct.
  1857. *
  1858. * e_state - Possible values are:
  1859. *
  1860. * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
  1861. * SC5_THRU_B (7), SC7_WRAP_S (8)
  1862. * Out
  1863. * Nothing.
  1864. *
  1865. ************************/
  1866. void ecm_state_change(struct s_smc *smc, int e_state)
  1867. {
  1868. #ifdef DRIVERDEBUG
  1869. char *s;
  1870. switch (e_state) {
  1871. case EC0_OUT:
  1872. s = "EC0_OUT";
  1873. break;
  1874. case EC1_IN:
  1875. s = "EC1_IN";
  1876. break;
  1877. case EC2_TRACE:
  1878. s = "EC2_TRACE";
  1879. break;
  1880. case EC3_LEAVE:
  1881. s = "EC3_LEAVE";
  1882. break;
  1883. case EC4_PATH_TEST:
  1884. s = "EC4_PATH_TEST";
  1885. break;
  1886. case EC5_INSERT:
  1887. s = "EC5_INSERT";
  1888. break;
  1889. case EC6_CHECK:
  1890. s = "EC6_CHECK";
  1891. break;
  1892. case EC7_DEINSERT:
  1893. s = "EC7_DEINSERT";
  1894. break;
  1895. default:
  1896. s = "unknown";
  1897. break;
  1898. }
  1899. pr_debug("ecm_state_change: %s\n", s);
  1900. #endif //DRIVERDEBUG
  1901. } // ecm_state_change
  1902. /************************
  1903. *
  1904. * rmt_state_change
  1905. *
  1906. * Sets RMT state in custom statistics.
  1907. * Args
  1908. * smc - A pointer to the SMT context struct.
  1909. *
  1910. * r_state - Possible values are:
  1911. *
  1912. * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
  1913. * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
  1914. * Out
  1915. * Nothing.
  1916. *
  1917. ************************/
  1918. void rmt_state_change(struct s_smc *smc, int r_state)
  1919. {
  1920. #ifdef DRIVERDEBUG
  1921. char *s;
  1922. switch (r_state) {
  1923. case RM0_ISOLATED:
  1924. s = "RM0_ISOLATED";
  1925. break;
  1926. case RM1_NON_OP:
  1927. s = "RM1_NON_OP - not operational";
  1928. break;
  1929. case RM2_RING_OP:
  1930. s = "RM2_RING_OP - ring operational";
  1931. break;
  1932. case RM3_DETECT:
  1933. s = "RM3_DETECT - detect dupl addresses";
  1934. break;
  1935. case RM4_NON_OP_DUP:
  1936. s = "RM4_NON_OP_DUP - dupl. addr detected";
  1937. break;
  1938. case RM5_RING_OP_DUP:
  1939. s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
  1940. break;
  1941. case RM6_DIRECTED:
  1942. s = "RM6_DIRECTED - sending directed beacons";
  1943. break;
  1944. case RM7_TRACE:
  1945. s = "RM7_TRACE - trace initiated";
  1946. break;
  1947. default:
  1948. s = "unknown";
  1949. break;
  1950. }
  1951. pr_debug("[rmt_state_change: %s]\n", s);
  1952. #endif // DRIVERDEBUG
  1953. } // rmt_state_change
  1954. /************************
  1955. *
  1956. * drv_reset_indication
  1957. *
  1958. * This function is called by the SMT when it has detected a severe
  1959. * hardware problem. The driver should perform a reset on the adapter
  1960. * as soon as possible, but not from within this function.
  1961. * Args
  1962. * smc - A pointer to the SMT context struct.
  1963. * Out
  1964. * Nothing.
  1965. *
  1966. ************************/
  1967. void drv_reset_indication(struct s_smc *smc)
  1968. {
  1969. pr_debug("entering drv_reset_indication\n");
  1970. smc->os.ResetRequested = TRUE; // Set flag.
  1971. } // drv_reset_indication
  1972. static struct pci_driver skfddi_pci_driver = {
  1973. .name = "skfddi",
  1974. .id_table = skfddi_pci_tbl,
  1975. .probe = skfp_init_one,
  1976. .remove = skfp_remove_one,
  1977. };
  1978. module_pci_driver(skfddi_pci_driver);