skfddi.c 63 KB

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