skfddi.c 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261
  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 DEFINE_PCI_DEVICE_TABLE(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_multicast_list = 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 __devexit 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. pci_set_drvdata(pdev, NULL);
  317. }
  318. /*
  319. * ====================
  320. * = skfp_driver_init =
  321. * ====================
  322. *
  323. * Overview:
  324. * Initializes remaining adapter board structure information
  325. * and makes sure adapter is in a safe state prior to skfp_open().
  326. *
  327. * Returns:
  328. * Condition code
  329. *
  330. * Arguments:
  331. * dev - pointer to device information
  332. *
  333. * Functional Description:
  334. * This function allocates additional resources such as the host memory
  335. * blocks needed by the adapter.
  336. * The adapter is also reset. The OS must call skfp_open() to open
  337. * the adapter and bring it on-line.
  338. *
  339. * Return Codes:
  340. * 0 - initialization succeeded
  341. * -1 - initialization failed
  342. */
  343. static int skfp_driver_init(struct net_device *dev)
  344. {
  345. struct s_smc *smc = netdev_priv(dev);
  346. skfddi_priv *bp = &smc->os;
  347. int err = -EIO;
  348. pr_debug("entering skfp_driver_init\n");
  349. // set the io address in private structures
  350. bp->base_addr = dev->base_addr;
  351. // Get the interrupt level from the PCI Configuration Table
  352. smc->hw.irq = dev->irq;
  353. spin_lock_init(&bp->DriverLock);
  354. // Allocate invalid frame
  355. bp->LocalRxBuffer = pci_alloc_consistent(&bp->pdev, MAX_FRAME_SIZE, &bp->LocalRxBufferDMA);
  356. if (!bp->LocalRxBuffer) {
  357. printk("could not allocate mem for ");
  358. printk("LocalRxBuffer: %d byte\n", MAX_FRAME_SIZE);
  359. goto fail;
  360. }
  361. // Determine the required size of the 'shared' memory area.
  362. bp->SharedMemSize = mac_drv_check_space();
  363. pr_debug("Memory for HWM: %ld\n", bp->SharedMemSize);
  364. if (bp->SharedMemSize > 0) {
  365. bp->SharedMemSize += 16; // for descriptor alignment
  366. bp->SharedMemAddr = pci_alloc_consistent(&bp->pdev,
  367. bp->SharedMemSize,
  368. &bp->SharedMemDMA);
  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. bp->SharedMemHeap = 0; // Nothing used yet.
  376. } else {
  377. bp->SharedMemAddr = NULL;
  378. bp->SharedMemHeap = 0;
  379. } // SharedMemSize > 0
  380. memset(bp->SharedMemAddr, 0, bp->SharedMemSize);
  381. card_stop(smc); // Reset adapter.
  382. pr_debug("mac_drv_init()..\n");
  383. if (mac_drv_init(smc) != 0) {
  384. pr_debug("mac_drv_init() failed\n");
  385. goto fail;
  386. }
  387. read_address(smc, NULL);
  388. pr_debug("HW-Addr: %pMF\n", smc->hw.fddi_canon_addr.a);
  389. memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
  390. smt_reset_defaults(smc, 0);
  391. return 0;
  392. fail:
  393. if (bp->SharedMemAddr) {
  394. pci_free_consistent(&bp->pdev,
  395. bp->SharedMemSize,
  396. bp->SharedMemAddr,
  397. bp->SharedMemDMA);
  398. bp->SharedMemAddr = NULL;
  399. }
  400. if (bp->LocalRxBuffer) {
  401. pci_free_consistent(&bp->pdev, MAX_FRAME_SIZE,
  402. bp->LocalRxBuffer, bp->LocalRxBufferDMA);
  403. bp->LocalRxBuffer = NULL;
  404. }
  405. return err;
  406. } // skfp_driver_init
  407. /*
  408. * =============
  409. * = skfp_open =
  410. * =============
  411. *
  412. * Overview:
  413. * Opens the adapter
  414. *
  415. * Returns:
  416. * Condition code
  417. *
  418. * Arguments:
  419. * dev - pointer to device information
  420. *
  421. * Functional Description:
  422. * This function brings the adapter to an operational state.
  423. *
  424. * Return Codes:
  425. * 0 - Adapter was successfully opened
  426. * -EAGAIN - Could not register IRQ
  427. */
  428. static int skfp_open(struct net_device *dev)
  429. {
  430. struct s_smc *smc = netdev_priv(dev);
  431. int err;
  432. pr_debug("entering skfp_open\n");
  433. /* Register IRQ - support shared interrupts by passing device ptr */
  434. err = request_irq(dev->irq, skfp_interrupt, IRQF_SHARED,
  435. dev->name, dev);
  436. if (err)
  437. return err;
  438. /*
  439. * Set current address to factory MAC address
  440. *
  441. * Note: We've already done this step in skfp_driver_init.
  442. * However, it's possible that a user has set a node
  443. * address override, then closed and reopened the
  444. * adapter. Unless we reset the device address field
  445. * now, we'll continue to use the existing modified
  446. * address.
  447. */
  448. read_address(smc, NULL);
  449. memcpy(dev->dev_addr, smc->hw.fddi_canon_addr.a, 6);
  450. init_smt(smc, NULL);
  451. smt_online(smc, 1);
  452. STI_FBI();
  453. /* Clear local multicast address tables */
  454. mac_clear_multicast(smc);
  455. /* Disable promiscuous filter settings */
  456. mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
  457. netif_start_queue(dev);
  458. return 0;
  459. } // skfp_open
  460. /*
  461. * ==============
  462. * = skfp_close =
  463. * ==============
  464. *
  465. * Overview:
  466. * Closes the device/module.
  467. *
  468. * Returns:
  469. * Condition code
  470. *
  471. * Arguments:
  472. * dev - pointer to device information
  473. *
  474. * Functional Description:
  475. * This routine closes the adapter and brings it to a safe state.
  476. * The interrupt service routine is deregistered with the OS.
  477. * The adapter can be opened again with another call to skfp_open().
  478. *
  479. * Return Codes:
  480. * Always return 0.
  481. *
  482. * Assumptions:
  483. * No further requests for this adapter are made after this routine is
  484. * called. skfp_open() can be called to reset and reinitialize the
  485. * adapter.
  486. */
  487. static int skfp_close(struct net_device *dev)
  488. {
  489. struct s_smc *smc = netdev_priv(dev);
  490. skfddi_priv *bp = &smc->os;
  491. CLI_FBI();
  492. smt_reset_defaults(smc, 1);
  493. card_stop(smc);
  494. mac_drv_clear_tx_queue(smc);
  495. mac_drv_clear_rx_queue(smc);
  496. netif_stop_queue(dev);
  497. /* Deregister (free) IRQ */
  498. free_irq(dev->irq, dev);
  499. skb_queue_purge(&bp->SendSkbQueue);
  500. bp->QueueSkb = MAX_TX_QUEUE_LEN;
  501. return 0;
  502. } // skfp_close
  503. /*
  504. * ==================
  505. * = skfp_interrupt =
  506. * ==================
  507. *
  508. * Overview:
  509. * Interrupt processing routine
  510. *
  511. * Returns:
  512. * None
  513. *
  514. * Arguments:
  515. * irq - interrupt vector
  516. * dev_id - pointer to device information
  517. *
  518. * Functional Description:
  519. * This routine calls the interrupt processing routine for this adapter. It
  520. * disables and reenables adapter interrupts, as appropriate. We can support
  521. * shared interrupts since the incoming dev_id pointer provides our device
  522. * structure context. All the real work is done in the hardware module.
  523. *
  524. * Return Codes:
  525. * None
  526. *
  527. * Assumptions:
  528. * The interrupt acknowledgement at the hardware level (eg. ACKing the PIC
  529. * on Intel-based systems) is done by the operating system outside this
  530. * routine.
  531. *
  532. * System interrupts are enabled through this call.
  533. *
  534. * Side Effects:
  535. * Interrupts are disabled, then reenabled at the adapter.
  536. */
  537. static irqreturn_t skfp_interrupt(int irq, void *dev_id)
  538. {
  539. struct net_device *dev = dev_id;
  540. struct s_smc *smc; /* private board structure pointer */
  541. skfddi_priv *bp;
  542. smc = netdev_priv(dev);
  543. bp = &smc->os;
  544. // IRQs enabled or disabled ?
  545. if (inpd(ADDR(B0_IMSK)) == 0) {
  546. // IRQs are disabled: must be shared interrupt
  547. return IRQ_NONE;
  548. }
  549. // Note: At this point, IRQs are enabled.
  550. if ((inpd(ISR_A) & smc->hw.is_imask) == 0) { // IRQ?
  551. // Adapter did not issue an IRQ: must be shared interrupt
  552. return IRQ_NONE;
  553. }
  554. CLI_FBI(); // Disable IRQs from our adapter.
  555. spin_lock(&bp->DriverLock);
  556. // Call interrupt handler in hardware module (HWM).
  557. fddi_isr(smc);
  558. if (smc->os.ResetRequested) {
  559. ResetAdapter(smc);
  560. smc->os.ResetRequested = FALSE;
  561. }
  562. spin_unlock(&bp->DriverLock);
  563. STI_FBI(); // Enable IRQs from our adapter.
  564. return IRQ_HANDLED;
  565. } // skfp_interrupt
  566. /*
  567. * ======================
  568. * = skfp_ctl_get_stats =
  569. * ======================
  570. *
  571. * Overview:
  572. * Get statistics for FDDI adapter
  573. *
  574. * Returns:
  575. * Pointer to FDDI statistics structure
  576. *
  577. * Arguments:
  578. * dev - pointer to device information
  579. *
  580. * Functional Description:
  581. * Gets current MIB objects from adapter, then
  582. * returns FDDI statistics structure as defined
  583. * in if_fddi.h.
  584. *
  585. * Note: Since the FDDI statistics structure is
  586. * still new and the device structure doesn't
  587. * have an FDDI-specific get statistics handler,
  588. * we'll return the FDDI statistics structure as
  589. * a pointer to an Ethernet statistics structure.
  590. * That way, at least the first part of the statistics
  591. * structure can be decoded properly.
  592. * We'll have to pay attention to this routine as the
  593. * device structure becomes more mature and LAN media
  594. * independent.
  595. *
  596. */
  597. static struct net_device_stats *skfp_ctl_get_stats(struct net_device *dev)
  598. {
  599. struct s_smc *bp = netdev_priv(dev);
  600. /* Fill the bp->stats structure with driver-maintained counters */
  601. bp->os.MacStat.port_bs_flag[0] = 0x1234;
  602. bp->os.MacStat.port_bs_flag[1] = 0x5678;
  603. // goos: need to fill out fddi statistic
  604. #if 0
  605. /* Get FDDI SMT MIB objects */
  606. /* Fill the bp->stats structure with the SMT MIB object values */
  607. 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));
  608. bp->stats.smt_op_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_op_version_id;
  609. bp->stats.smt_hi_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_hi_version_id;
  610. bp->stats.smt_lo_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_lo_version_id;
  611. 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));
  612. bp->stats.smt_mib_version_id = bp->cmd_rsp_virt->smt_mib_get.smt_mib_version_id;
  613. bp->stats.smt_mac_cts = bp->cmd_rsp_virt->smt_mib_get.smt_mac_ct;
  614. bp->stats.smt_non_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_non_master_ct;
  615. bp->stats.smt_master_cts = bp->cmd_rsp_virt->smt_mib_get.smt_master_ct;
  616. bp->stats.smt_available_paths = bp->cmd_rsp_virt->smt_mib_get.smt_available_paths;
  617. bp->stats.smt_config_capabilities = bp->cmd_rsp_virt->smt_mib_get.smt_config_capabilities;
  618. bp->stats.smt_config_policy = bp->cmd_rsp_virt->smt_mib_get.smt_config_policy;
  619. bp->stats.smt_connection_policy = bp->cmd_rsp_virt->smt_mib_get.smt_connection_policy;
  620. bp->stats.smt_t_notify = bp->cmd_rsp_virt->smt_mib_get.smt_t_notify;
  621. bp->stats.smt_stat_rpt_policy = bp->cmd_rsp_virt->smt_mib_get.smt_stat_rpt_policy;
  622. bp->stats.smt_trace_max_expiration = bp->cmd_rsp_virt->smt_mib_get.smt_trace_max_expiration;
  623. bp->stats.smt_bypass_present = bp->cmd_rsp_virt->smt_mib_get.smt_bypass_present;
  624. bp->stats.smt_ecm_state = bp->cmd_rsp_virt->smt_mib_get.smt_ecm_state;
  625. bp->stats.smt_cf_state = bp->cmd_rsp_virt->smt_mib_get.smt_cf_state;
  626. bp->stats.smt_remote_disconnect_flag = bp->cmd_rsp_virt->smt_mib_get.smt_remote_disconnect_flag;
  627. bp->stats.smt_station_status = bp->cmd_rsp_virt->smt_mib_get.smt_station_status;
  628. bp->stats.smt_peer_wrap_flag = bp->cmd_rsp_virt->smt_mib_get.smt_peer_wrap_flag;
  629. bp->stats.smt_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_msg_time_stamp.ls;
  630. bp->stats.smt_transition_time_stamp = bp->cmd_rsp_virt->smt_mib_get.smt_transition_time_stamp.ls;
  631. bp->stats.mac_frame_status_functions = bp->cmd_rsp_virt->smt_mib_get.mac_frame_status_functions;
  632. bp->stats.mac_t_max_capability = bp->cmd_rsp_virt->smt_mib_get.mac_t_max_capability;
  633. bp->stats.mac_tvx_capability = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_capability;
  634. bp->stats.mac_available_paths = bp->cmd_rsp_virt->smt_mib_get.mac_available_paths;
  635. bp->stats.mac_current_path = bp->cmd_rsp_virt->smt_mib_get.mac_current_path;
  636. memcpy(bp->stats.mac_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_upstream_nbr, FDDI_K_ALEN);
  637. memcpy(bp->stats.mac_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_downstream_nbr, FDDI_K_ALEN);
  638. memcpy(bp->stats.mac_old_upstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_upstream_nbr, FDDI_K_ALEN);
  639. memcpy(bp->stats.mac_old_downstream_nbr, &bp->cmd_rsp_virt->smt_mib_get.mac_old_downstream_nbr, FDDI_K_ALEN);
  640. bp->stats.mac_dup_address_test = bp->cmd_rsp_virt->smt_mib_get.mac_dup_address_test;
  641. bp->stats.mac_requested_paths = bp->cmd_rsp_virt->smt_mib_get.mac_requested_paths;
  642. bp->stats.mac_downstream_port_type = bp->cmd_rsp_virt->smt_mib_get.mac_downstream_port_type;
  643. memcpy(bp->stats.mac_smt_address, &bp->cmd_rsp_virt->smt_mib_get.mac_smt_address, FDDI_K_ALEN);
  644. bp->stats.mac_t_req = bp->cmd_rsp_virt->smt_mib_get.mac_t_req;
  645. bp->stats.mac_t_neg = bp->cmd_rsp_virt->smt_mib_get.mac_t_neg;
  646. bp->stats.mac_t_max = bp->cmd_rsp_virt->smt_mib_get.mac_t_max;
  647. bp->stats.mac_tvx_value = bp->cmd_rsp_virt->smt_mib_get.mac_tvx_value;
  648. bp->stats.mac_frame_error_threshold = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_threshold;
  649. bp->stats.mac_frame_error_ratio = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_ratio;
  650. bp->stats.mac_rmt_state = bp->cmd_rsp_virt->smt_mib_get.mac_rmt_state;
  651. bp->stats.mac_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_da_flag;
  652. bp->stats.mac_una_da_flag = bp->cmd_rsp_virt->smt_mib_get.mac_unda_flag;
  653. bp->stats.mac_frame_error_flag = bp->cmd_rsp_virt->smt_mib_get.mac_frame_error_flag;
  654. bp->stats.mac_ma_unitdata_available = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_available;
  655. bp->stats.mac_hardware_present = bp->cmd_rsp_virt->smt_mib_get.mac_hardware_present;
  656. bp->stats.mac_ma_unitdata_enable = bp->cmd_rsp_virt->smt_mib_get.mac_ma_unitdata_enable;
  657. bp->stats.path_tvx_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_tvx_lower_bound;
  658. bp->stats.path_t_max_lower_bound = bp->cmd_rsp_virt->smt_mib_get.path_t_max_lower_bound;
  659. bp->stats.path_max_t_req = bp->cmd_rsp_virt->smt_mib_get.path_max_t_req;
  660. memcpy(bp->stats.path_configuration, &bp->cmd_rsp_virt->smt_mib_get.path_configuration, sizeof(bp->cmd_rsp_virt->smt_mib_get.path_configuration));
  661. bp->stats.port_my_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[0];
  662. bp->stats.port_my_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_my_type[1];
  663. bp->stats.port_neighbor_type[0] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[0];
  664. bp->stats.port_neighbor_type[1] = bp->cmd_rsp_virt->smt_mib_get.port_neighbor_type[1];
  665. bp->stats.port_connection_policies[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[0];
  666. bp->stats.port_connection_policies[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_policies[1];
  667. bp->stats.port_mac_indicated[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[0];
  668. bp->stats.port_mac_indicated[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_indicated[1];
  669. bp->stats.port_current_path[0] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[0];
  670. bp->stats.port_current_path[1] = bp->cmd_rsp_virt->smt_mib_get.port_current_path[1];
  671. memcpy(&bp->stats.port_requested_paths[0 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[0], 3);
  672. memcpy(&bp->stats.port_requested_paths[1 * 3], &bp->cmd_rsp_virt->smt_mib_get.port_requested_paths[1], 3);
  673. bp->stats.port_mac_placement[0] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[0];
  674. bp->stats.port_mac_placement[1] = bp->cmd_rsp_virt->smt_mib_get.port_mac_placement[1];
  675. bp->stats.port_available_paths[0] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[0];
  676. bp->stats.port_available_paths[1] = bp->cmd_rsp_virt->smt_mib_get.port_available_paths[1];
  677. bp->stats.port_pmd_class[0] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[0];
  678. bp->stats.port_pmd_class[1] = bp->cmd_rsp_virt->smt_mib_get.port_pmd_class[1];
  679. bp->stats.port_connection_capabilities[0] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[0];
  680. bp->stats.port_connection_capabilities[1] = bp->cmd_rsp_virt->smt_mib_get.port_connection_capabilities[1];
  681. bp->stats.port_bs_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[0];
  682. bp->stats.port_bs_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_bs_flag[1];
  683. bp->stats.port_ler_estimate[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[0];
  684. bp->stats.port_ler_estimate[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_estimate[1];
  685. bp->stats.port_ler_cutoff[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[0];
  686. bp->stats.port_ler_cutoff[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_cutoff[1];
  687. bp->stats.port_ler_alarm[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[0];
  688. bp->stats.port_ler_alarm[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_alarm[1];
  689. bp->stats.port_connect_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[0];
  690. bp->stats.port_connect_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_connect_state[1];
  691. bp->stats.port_pcm_state[0] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[0];
  692. bp->stats.port_pcm_state[1] = bp->cmd_rsp_virt->smt_mib_get.port_pcm_state[1];
  693. bp->stats.port_pc_withhold[0] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[0];
  694. bp->stats.port_pc_withhold[1] = bp->cmd_rsp_virt->smt_mib_get.port_pc_withhold[1];
  695. bp->stats.port_ler_flag[0] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[0];
  696. bp->stats.port_ler_flag[1] = bp->cmd_rsp_virt->smt_mib_get.port_ler_flag[1];
  697. bp->stats.port_hardware_present[0] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[0];
  698. bp->stats.port_hardware_present[1] = bp->cmd_rsp_virt->smt_mib_get.port_hardware_present[1];
  699. /* Fill the bp->stats structure with the FDDI counter values */
  700. bp->stats.mac_frame_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.frame_cnt.ls;
  701. bp->stats.mac_copied_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.copied_cnt.ls;
  702. bp->stats.mac_transmit_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.transmit_cnt.ls;
  703. bp->stats.mac_error_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.error_cnt.ls;
  704. bp->stats.mac_lost_cts = bp->cmd_rsp_virt->cntrs_get.cntrs.lost_cnt.ls;
  705. bp->stats.port_lct_fail_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[0].ls;
  706. bp->stats.port_lct_fail_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lct_rejects[1].ls;
  707. bp->stats.port_lem_reject_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[0].ls;
  708. bp->stats.port_lem_reject_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.lem_rejects[1].ls;
  709. bp->stats.port_lem_cts[0] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[0].ls;
  710. bp->stats.port_lem_cts[1] = bp->cmd_rsp_virt->cntrs_get.cntrs.link_errors[1].ls;
  711. #endif
  712. return (struct net_device_stats *)&bp->os.MacStat;
  713. } // ctl_get_stat
  714. /*
  715. * ==============================
  716. * = skfp_ctl_set_multicast_list =
  717. * ==============================
  718. *
  719. * Overview:
  720. * Enable/Disable LLC frame promiscuous mode reception
  721. * on the adapter and/or update multicast address table.
  722. *
  723. * Returns:
  724. * None
  725. *
  726. * Arguments:
  727. * dev - pointer to device information
  728. *
  729. * Functional Description:
  730. * This function acquires the driver lock and only calls
  731. * skfp_ctl_set_multicast_list_wo_lock then.
  732. * This routine follows a fairly simple algorithm for setting the
  733. * adapter filters and CAM:
  734. *
  735. * if IFF_PROMISC flag is set
  736. * enable promiscuous mode
  737. * else
  738. * disable promiscuous mode
  739. * if number of multicast addresses <= max. multicast number
  740. * add mc addresses to adapter table
  741. * else
  742. * enable promiscuous mode
  743. * update adapter filters
  744. *
  745. * Assumptions:
  746. * Multicast addresses are presented in canonical (LSB) format.
  747. *
  748. * Side Effects:
  749. * On-board adapter filters are updated.
  750. */
  751. static void skfp_ctl_set_multicast_list(struct net_device *dev)
  752. {
  753. struct s_smc *smc = netdev_priv(dev);
  754. skfddi_priv *bp = &smc->os;
  755. unsigned long Flags;
  756. spin_lock_irqsave(&bp->DriverLock, Flags);
  757. skfp_ctl_set_multicast_list_wo_lock(dev);
  758. spin_unlock_irqrestore(&bp->DriverLock, Flags);
  759. } // skfp_ctl_set_multicast_list
  760. static void skfp_ctl_set_multicast_list_wo_lock(struct net_device *dev)
  761. {
  762. struct s_smc *smc = netdev_priv(dev);
  763. struct netdev_hw_addr *ha;
  764. /* Enable promiscuous mode, if necessary */
  765. if (dev->flags & IFF_PROMISC) {
  766. mac_drv_rx_mode(smc, RX_ENABLE_PROMISC);
  767. pr_debug("PROMISCUOUS MODE ENABLED\n");
  768. }
  769. /* Else, update multicast address table */
  770. else {
  771. mac_drv_rx_mode(smc, RX_DISABLE_PROMISC);
  772. pr_debug("PROMISCUOUS MODE DISABLED\n");
  773. // Reset all MC addresses
  774. mac_clear_multicast(smc);
  775. mac_drv_rx_mode(smc, RX_DISABLE_ALLMULTI);
  776. if (dev->flags & IFF_ALLMULTI) {
  777. mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
  778. pr_debug("ENABLE ALL MC ADDRESSES\n");
  779. } else if (!netdev_mc_empty(dev)) {
  780. if (netdev_mc_count(dev) <= FPMAX_MULTICAST) {
  781. /* use exact filtering */
  782. // point to first multicast addr
  783. netdev_for_each_mc_addr(ha, dev) {
  784. mac_add_multicast(smc,
  785. (struct fddi_addr *)ha->addr,
  786. 1);
  787. pr_debug("ENABLE MC ADDRESS: %pMF\n",
  788. ha->addr);
  789. }
  790. } else { // more MC addresses than HW supports
  791. mac_drv_rx_mode(smc, RX_ENABLE_ALLMULTI);
  792. pr_debug("ENABLE ALL MC ADDRESSES\n");
  793. }
  794. } else { // no MC addresses
  795. pr_debug("DISABLE ALL MC ADDRESSES\n");
  796. }
  797. /* Update adapter filters */
  798. mac_update_multicast(smc);
  799. }
  800. } // skfp_ctl_set_multicast_list_wo_lock
  801. /*
  802. * ===========================
  803. * = skfp_ctl_set_mac_address =
  804. * ===========================
  805. *
  806. * Overview:
  807. * set new mac address on adapter and update dev_addr field in device table.
  808. *
  809. * Returns:
  810. * None
  811. *
  812. * Arguments:
  813. * dev - pointer to device information
  814. * addr - pointer to sockaddr structure containing unicast address to set
  815. *
  816. * Assumptions:
  817. * The address pointed to by addr->sa_data is a valid unicast
  818. * address and is presented in canonical (LSB) format.
  819. */
  820. static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
  821. {
  822. struct s_smc *smc = netdev_priv(dev);
  823. struct sockaddr *p_sockaddr = (struct sockaddr *) addr;
  824. skfddi_priv *bp = &smc->os;
  825. unsigned long Flags;
  826. memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
  827. spin_lock_irqsave(&bp->DriverLock, Flags);
  828. ResetAdapter(smc);
  829. spin_unlock_irqrestore(&bp->DriverLock, Flags);
  830. return 0; /* always return zero */
  831. } // skfp_ctl_set_mac_address
  832. /*
  833. * ==============
  834. * = skfp_ioctl =
  835. * ==============
  836. *
  837. * Overview:
  838. *
  839. * Perform IOCTL call functions here. Some are privileged operations and the
  840. * effective uid is checked in those cases.
  841. *
  842. * Returns:
  843. * status value
  844. * 0 - success
  845. * other - failure
  846. *
  847. * Arguments:
  848. * dev - pointer to device information
  849. * rq - pointer to ioctl request structure
  850. * cmd - ?
  851. *
  852. */
  853. static int skfp_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  854. {
  855. struct s_smc *smc = netdev_priv(dev);
  856. skfddi_priv *lp = &smc->os;
  857. struct s_skfp_ioctl ioc;
  858. int status = 0;
  859. if (copy_from_user(&ioc, rq->ifr_data, sizeof(struct s_skfp_ioctl)))
  860. return -EFAULT;
  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 pci_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 = pci_map_single(&bp->pdev, skb->data,
  1041. skb->len, PCI_DMA_TODEVICE);
  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. pci_unmap_single(&bp->pdev, dma_address,
  1050. skb->len, PCI_DMA_TODEVICE);
  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, 6);
  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. pci_unmap_single(&bp->pdev, r->rxd_os.dma_addr,
  1288. MaxFrameSize, PCI_DMA_FROMDEVICE);
  1289. r->rxd_os.dma_addr = 0;
  1290. }
  1291. }
  1292. } // dma_complete
  1293. /************************
  1294. *
  1295. * mac_drv_tx_complete
  1296. *
  1297. * Transmit of a packet is complete. Release the tx staging buffer.
  1298. *
  1299. * Args
  1300. * smc - A pointer to the SMT context struct.
  1301. *
  1302. * txd - A pointer to the last TxD which is used by the frame.
  1303. * Out
  1304. * Returns nothing.
  1305. *
  1306. ************************/
  1307. void mac_drv_tx_complete(struct s_smc *smc, volatile struct s_smt_fp_txd *txd)
  1308. {
  1309. struct sk_buff *skb;
  1310. pr_debug("entering mac_drv_tx_complete\n");
  1311. // Check if this TxD points to a skb
  1312. if (!(skb = txd->txd_os.skb)) {
  1313. pr_debug("TXD with no skb assigned.\n");
  1314. return;
  1315. }
  1316. txd->txd_os.skb = NULL;
  1317. // release the DMA mapping
  1318. pci_unmap_single(&smc->os.pdev, txd->txd_os.dma_addr,
  1319. skb->len, PCI_DMA_TODEVICE);
  1320. txd->txd_os.dma_addr = 0;
  1321. smc->os.MacStat.gen.tx_packets++; // Count transmitted packets.
  1322. smc->os.MacStat.gen.tx_bytes+=skb->len; // Count bytes
  1323. // free the skb
  1324. dev_kfree_skb_irq(skb);
  1325. pr_debug("leaving mac_drv_tx_complete\n");
  1326. } // mac_drv_tx_complete
  1327. /************************
  1328. *
  1329. * dump packets to logfile
  1330. *
  1331. ************************/
  1332. #ifdef DUMPPACKETS
  1333. void dump_data(unsigned char *Data, int length)
  1334. {
  1335. int i, j;
  1336. unsigned char s[255], sh[10];
  1337. if (length > 64) {
  1338. length = 64;
  1339. }
  1340. printk(KERN_INFO "---Packet start---\n");
  1341. for (i = 0, j = 0; i < length / 8; i++, j += 8)
  1342. printk(KERN_INFO "%02x %02x %02x %02x %02x %02x %02x %02x\n",
  1343. Data[j + 0], Data[j + 1], Data[j + 2], Data[j + 3],
  1344. Data[j + 4], Data[j + 5], Data[j + 6], Data[j + 7]);
  1345. strcpy(s, "");
  1346. for (i = 0; i < length % 8; i++) {
  1347. sprintf(sh, "%02x ", Data[j + i]);
  1348. strcat(s, sh);
  1349. }
  1350. printk(KERN_INFO "%s\n", s);
  1351. printk(KERN_INFO "------------------\n");
  1352. } // dump_data
  1353. #else
  1354. #define dump_data(data,len)
  1355. #endif // DUMPPACKETS
  1356. /************************
  1357. *
  1358. * mac_drv_rx_complete
  1359. *
  1360. * The hardware module calls this function if an LLC frame is received
  1361. * in a receive buffer. Also the SMT, NSA, and directed beacon frames
  1362. * from the network will be passed to the LLC layer by this function
  1363. * if passing is enabled.
  1364. *
  1365. * mac_drv_rx_complete forwards the frame to the LLC layer if it should
  1366. * be received. It also fills the RxD ring with new receive buffers if
  1367. * some can be queued.
  1368. * Args
  1369. * smc - A pointer to the SMT context struct.
  1370. *
  1371. * rxd - A pointer to the first RxD which is used by the receive frame.
  1372. *
  1373. * frag_count - Count of RxDs used by the received frame.
  1374. *
  1375. * len - Frame length.
  1376. * Out
  1377. * Nothing.
  1378. *
  1379. ************************/
  1380. void mac_drv_rx_complete(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  1381. int frag_count, int len)
  1382. {
  1383. skfddi_priv *bp = &smc->os;
  1384. struct sk_buff *skb;
  1385. unsigned char *virt, *cp;
  1386. unsigned short ri;
  1387. u_int RifLength;
  1388. pr_debug("entering mac_drv_rx_complete (len=%d)\n", len);
  1389. if (frag_count != 1) { // This is not allowed to happen.
  1390. printk("fddi: Multi-fragment receive!\n");
  1391. goto RequeueRxd; // Re-use the given RXD(s).
  1392. }
  1393. skb = rxd->rxd_os.skb;
  1394. if (!skb) {
  1395. pr_debug("No skb in rxd\n");
  1396. smc->os.MacStat.gen.rx_errors++;
  1397. goto RequeueRxd;
  1398. }
  1399. virt = skb->data;
  1400. // The DMA mapping was released in dma_complete above.
  1401. dump_data(skb->data, len);
  1402. /*
  1403. * FDDI Frame format:
  1404. * +-------+-------+-------+------------+--------+------------+
  1405. * | FC[1] | DA[6] | SA[6] | RIF[0..18] | LLC[3] | Data[0..n] |
  1406. * +-------+-------+-------+------------+--------+------------+
  1407. *
  1408. * FC = Frame Control
  1409. * DA = Destination Address
  1410. * SA = Source Address
  1411. * RIF = Routing Information Field
  1412. * LLC = Logical Link Control
  1413. */
  1414. // Remove Routing Information Field (RIF), if present.
  1415. if ((virt[1 + 6] & FDDI_RII) == 0)
  1416. RifLength = 0;
  1417. else {
  1418. int n;
  1419. // goos: RIF removal has still to be tested
  1420. pr_debug("RIF found\n");
  1421. // Get RIF length from Routing Control (RC) field.
  1422. cp = virt + FDDI_MAC_HDR_LEN; // Point behind MAC header.
  1423. ri = ntohs(*((__be16 *) cp));
  1424. RifLength = ri & FDDI_RCF_LEN_MASK;
  1425. if (len < (int) (FDDI_MAC_HDR_LEN + RifLength)) {
  1426. printk("fddi: Invalid RIF.\n");
  1427. goto RequeueRxd; // Discard the frame.
  1428. }
  1429. virt[1 + 6] &= ~FDDI_RII; // Clear RII bit.
  1430. // regions overlap
  1431. virt = cp + RifLength;
  1432. for (n = FDDI_MAC_HDR_LEN; n; n--)
  1433. *--virt = *--cp;
  1434. // adjust sbd->data pointer
  1435. skb_pull(skb, RifLength);
  1436. len -= RifLength;
  1437. RifLength = 0;
  1438. }
  1439. // Count statistics.
  1440. smc->os.MacStat.gen.rx_packets++; // Count indicated receive
  1441. // packets.
  1442. smc->os.MacStat.gen.rx_bytes+=len; // Count bytes.
  1443. // virt points to header again
  1444. if (virt[1] & 0x01) { // Check group (multicast) bit.
  1445. smc->os.MacStat.gen.multicast++;
  1446. }
  1447. // deliver frame to system
  1448. rxd->rxd_os.skb = NULL;
  1449. skb_trim(skb, len);
  1450. skb->protocol = fddi_type_trans(skb, bp->dev);
  1451. netif_rx(skb);
  1452. HWM_RX_CHECK(smc, RX_LOW_WATERMARK);
  1453. return;
  1454. RequeueRxd:
  1455. pr_debug("Rx: re-queue RXD.\n");
  1456. mac_drv_requeue_rxd(smc, rxd, frag_count);
  1457. smc->os.MacStat.gen.rx_errors++; // Count receive packets
  1458. // not indicated.
  1459. } // mac_drv_rx_complete
  1460. /************************
  1461. *
  1462. * mac_drv_requeue_rxd
  1463. *
  1464. * The hardware module calls this function to request the OS-specific
  1465. * module to queue the receive buffer(s) represented by the pointer
  1466. * to the RxD and the frag_count into the receive queue again. This
  1467. * buffer was filled with an invalid frame or an SMT frame.
  1468. * Args
  1469. * smc - A pointer to the SMT context struct.
  1470. *
  1471. * rxd - A pointer to the first RxD which is used by the receive frame.
  1472. *
  1473. * frag_count - Count of RxDs used by the received frame.
  1474. * Out
  1475. * Nothing.
  1476. *
  1477. ************************/
  1478. void mac_drv_requeue_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  1479. int frag_count)
  1480. {
  1481. volatile struct s_smt_fp_rxd *next_rxd;
  1482. volatile struct s_smt_fp_rxd *src_rxd;
  1483. struct sk_buff *skb;
  1484. int MaxFrameSize;
  1485. unsigned char *v_addr;
  1486. dma_addr_t b_addr;
  1487. if (frag_count != 1) // This is not allowed to happen.
  1488. printk("fddi: Multi-fragment requeue!\n");
  1489. MaxFrameSize = smc->os.MaxFrameSize;
  1490. src_rxd = rxd;
  1491. for (; frag_count > 0; frag_count--) {
  1492. next_rxd = src_rxd->rxd_next;
  1493. rxd = HWM_GET_CURR_RXD(smc);
  1494. skb = src_rxd->rxd_os.skb;
  1495. if (skb == NULL) { // this should not happen
  1496. pr_debug("Requeue with no skb in rxd!\n");
  1497. skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
  1498. if (skb) {
  1499. // we got a skb
  1500. rxd->rxd_os.skb = skb;
  1501. skb_reserve(skb, 3);
  1502. skb_put(skb, MaxFrameSize);
  1503. v_addr = skb->data;
  1504. b_addr = pci_map_single(&smc->os.pdev,
  1505. v_addr,
  1506. MaxFrameSize,
  1507. PCI_DMA_FROMDEVICE);
  1508. rxd->rxd_os.dma_addr = b_addr;
  1509. } else {
  1510. // no skb available, use local buffer
  1511. pr_debug("Queueing invalid buffer!\n");
  1512. rxd->rxd_os.skb = NULL;
  1513. v_addr = smc->os.LocalRxBuffer;
  1514. b_addr = smc->os.LocalRxBufferDMA;
  1515. }
  1516. } else {
  1517. // we use skb from old rxd
  1518. rxd->rxd_os.skb = skb;
  1519. v_addr = skb->data;
  1520. b_addr = pci_map_single(&smc->os.pdev,
  1521. v_addr,
  1522. MaxFrameSize,
  1523. PCI_DMA_FROMDEVICE);
  1524. rxd->rxd_os.dma_addr = b_addr;
  1525. }
  1526. hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
  1527. FIRST_FRAG | LAST_FRAG);
  1528. src_rxd = next_rxd;
  1529. }
  1530. } // mac_drv_requeue_rxd
  1531. /************************
  1532. *
  1533. * mac_drv_fill_rxd
  1534. *
  1535. * The hardware module calls this function at initialization time
  1536. * to fill the RxD ring with receive buffers. It is also called by
  1537. * mac_drv_rx_complete if rx_free is large enough to queue some new
  1538. * receive buffers into the RxD ring. mac_drv_fill_rxd queues new
  1539. * receive buffers as long as enough RxDs and receive buffers are
  1540. * available.
  1541. * Args
  1542. * smc - A pointer to the SMT context struct.
  1543. * Out
  1544. * Nothing.
  1545. *
  1546. ************************/
  1547. void mac_drv_fill_rxd(struct s_smc *smc)
  1548. {
  1549. int MaxFrameSize;
  1550. unsigned char *v_addr;
  1551. unsigned long b_addr;
  1552. struct sk_buff *skb;
  1553. volatile struct s_smt_fp_rxd *rxd;
  1554. pr_debug("entering mac_drv_fill_rxd\n");
  1555. // Walk through the list of free receive buffers, passing receive
  1556. // buffers to the HWM as long as RXDs are available.
  1557. MaxFrameSize = smc->os.MaxFrameSize;
  1558. // Check if there is any RXD left.
  1559. while (HWM_GET_RX_FREE(smc) > 0) {
  1560. pr_debug(".\n");
  1561. rxd = HWM_GET_CURR_RXD(smc);
  1562. skb = alloc_skb(MaxFrameSize + 3, GFP_ATOMIC);
  1563. if (skb) {
  1564. // we got a skb
  1565. skb_reserve(skb, 3);
  1566. skb_put(skb, MaxFrameSize);
  1567. v_addr = skb->data;
  1568. b_addr = pci_map_single(&smc->os.pdev,
  1569. v_addr,
  1570. MaxFrameSize,
  1571. PCI_DMA_FROMDEVICE);
  1572. rxd->rxd_os.dma_addr = b_addr;
  1573. } else {
  1574. // no skb available, use local buffer
  1575. // System has run out of buffer memory, but we want to
  1576. // keep the receiver running in hope of better times.
  1577. // Multiple descriptors may point to this local buffer,
  1578. // so data in it must be considered invalid.
  1579. pr_debug("Queueing invalid buffer!\n");
  1580. v_addr = smc->os.LocalRxBuffer;
  1581. b_addr = smc->os.LocalRxBufferDMA;
  1582. }
  1583. rxd->rxd_os.skb = skb;
  1584. // Pass receive buffer to HWM.
  1585. hwm_rx_frag(smc, v_addr, b_addr, MaxFrameSize,
  1586. FIRST_FRAG | LAST_FRAG);
  1587. }
  1588. pr_debug("leaving mac_drv_fill_rxd\n");
  1589. } // mac_drv_fill_rxd
  1590. /************************
  1591. *
  1592. * mac_drv_clear_rxd
  1593. *
  1594. * The hardware module calls this function to release unused
  1595. * receive buffers.
  1596. * Args
  1597. * smc - A pointer to the SMT context struct.
  1598. *
  1599. * rxd - A pointer to the first RxD which is used by the receive buffer.
  1600. *
  1601. * frag_count - Count of RxDs used by the receive buffer.
  1602. * Out
  1603. * Nothing.
  1604. *
  1605. ************************/
  1606. void mac_drv_clear_rxd(struct s_smc *smc, volatile struct s_smt_fp_rxd *rxd,
  1607. int frag_count)
  1608. {
  1609. struct sk_buff *skb;
  1610. pr_debug("entering mac_drv_clear_rxd\n");
  1611. if (frag_count != 1) // This is not allowed to happen.
  1612. printk("fddi: Multi-fragment clear!\n");
  1613. for (; frag_count > 0; frag_count--) {
  1614. skb = rxd->rxd_os.skb;
  1615. if (skb != NULL) {
  1616. skfddi_priv *bp = &smc->os;
  1617. int MaxFrameSize = bp->MaxFrameSize;
  1618. pci_unmap_single(&bp->pdev, rxd->rxd_os.dma_addr,
  1619. MaxFrameSize, PCI_DMA_FROMDEVICE);
  1620. dev_kfree_skb(skb);
  1621. rxd->rxd_os.skb = NULL;
  1622. }
  1623. rxd = rxd->rxd_next; // Next RXD.
  1624. }
  1625. } // mac_drv_clear_rxd
  1626. /************************
  1627. *
  1628. * mac_drv_rx_init
  1629. *
  1630. * The hardware module calls this routine when an SMT or NSA frame of the
  1631. * local SMT should be delivered to the LLC layer.
  1632. *
  1633. * It is necessary to have this function, because there is no other way to
  1634. * copy the contents of SMT MBufs into receive buffers.
  1635. *
  1636. * mac_drv_rx_init allocates the required target memory for this frame,
  1637. * and receives the frame fragment by fragment by calling mac_drv_rx_frag.
  1638. * Args
  1639. * smc - A pointer to the SMT context struct.
  1640. *
  1641. * len - The length (in bytes) of the received frame (FC, DA, SA, Data).
  1642. *
  1643. * fc - The Frame Control field of the received frame.
  1644. *
  1645. * look_ahead - A pointer to the lookahead data buffer (may be NULL).
  1646. *
  1647. * la_len - The length of the lookahead data stored in the lookahead
  1648. * buffer (may be zero).
  1649. * Out
  1650. * Always returns zero (0).
  1651. *
  1652. ************************/
  1653. int mac_drv_rx_init(struct s_smc *smc, int len, int fc,
  1654. char *look_ahead, int la_len)
  1655. {
  1656. struct sk_buff *skb;
  1657. pr_debug("entering mac_drv_rx_init(len=%d)\n", len);
  1658. // "Received" a SMT or NSA frame of the local SMT.
  1659. if (len != la_len || len < FDDI_MAC_HDR_LEN || !look_ahead) {
  1660. pr_debug("fddi: Discard invalid local SMT frame\n");
  1661. pr_debug(" len=%d, la_len=%d, (ULONG) look_ahead=%08lXh.\n",
  1662. len, la_len, (unsigned long) look_ahead);
  1663. return 0;
  1664. }
  1665. skb = alloc_skb(len + 3, GFP_ATOMIC);
  1666. if (!skb) {
  1667. pr_debug("fddi: Local SMT: skb memory exhausted.\n");
  1668. return 0;
  1669. }
  1670. skb_reserve(skb, 3);
  1671. skb_put(skb, len);
  1672. skb_copy_to_linear_data(skb, look_ahead, len);
  1673. // deliver frame to system
  1674. skb->protocol = fddi_type_trans(skb, smc->os.dev);
  1675. netif_rx(skb);
  1676. return 0;
  1677. } // mac_drv_rx_init
  1678. /************************
  1679. *
  1680. * smt_timer_poll
  1681. *
  1682. * This routine is called periodically by the SMT module to clean up the
  1683. * driver.
  1684. *
  1685. * Return any queued frames back to the upper protocol layers if the ring
  1686. * is down.
  1687. * Args
  1688. * smc - A pointer to the SMT context struct.
  1689. * Out
  1690. * Nothing.
  1691. *
  1692. ************************/
  1693. void smt_timer_poll(struct s_smc *smc)
  1694. {
  1695. } // smt_timer_poll
  1696. /************************
  1697. *
  1698. * ring_status_indication
  1699. *
  1700. * This function indicates a change of the ring state.
  1701. * Args
  1702. * smc - A pointer to the SMT context struct.
  1703. *
  1704. * status - The current ring status.
  1705. * Out
  1706. * Nothing.
  1707. *
  1708. ************************/
  1709. void ring_status_indication(struct s_smc *smc, u_long status)
  1710. {
  1711. pr_debug("ring_status_indication( ");
  1712. if (status & RS_RES15)
  1713. pr_debug("RS_RES15 ");
  1714. if (status & RS_HARDERROR)
  1715. pr_debug("RS_HARDERROR ");
  1716. if (status & RS_SOFTERROR)
  1717. pr_debug("RS_SOFTERROR ");
  1718. if (status & RS_BEACON)
  1719. pr_debug("RS_BEACON ");
  1720. if (status & RS_PATHTEST)
  1721. pr_debug("RS_PATHTEST ");
  1722. if (status & RS_SELFTEST)
  1723. pr_debug("RS_SELFTEST ");
  1724. if (status & RS_RES9)
  1725. pr_debug("RS_RES9 ");
  1726. if (status & RS_DISCONNECT)
  1727. pr_debug("RS_DISCONNECT ");
  1728. if (status & RS_RES7)
  1729. pr_debug("RS_RES7 ");
  1730. if (status & RS_DUPADDR)
  1731. pr_debug("RS_DUPADDR ");
  1732. if (status & RS_NORINGOP)
  1733. pr_debug("RS_NORINGOP ");
  1734. if (status & RS_VERSION)
  1735. pr_debug("RS_VERSION ");
  1736. if (status & RS_STUCKBYPASSS)
  1737. pr_debug("RS_STUCKBYPASSS ");
  1738. if (status & RS_EVENT)
  1739. pr_debug("RS_EVENT ");
  1740. if (status & RS_RINGOPCHANGE)
  1741. pr_debug("RS_RINGOPCHANGE ");
  1742. if (status & RS_RES0)
  1743. pr_debug("RS_RES0 ");
  1744. pr_debug("]\n");
  1745. } // ring_status_indication
  1746. /************************
  1747. *
  1748. * smt_get_time
  1749. *
  1750. * Gets the current time from the system.
  1751. * Args
  1752. * None.
  1753. * Out
  1754. * The current time in TICKS_PER_SECOND.
  1755. *
  1756. * TICKS_PER_SECOND has the unit 'count of timer ticks per second'. It is
  1757. * defined in "targetos.h". The definition of TICKS_PER_SECOND must comply
  1758. * to the time returned by smt_get_time().
  1759. *
  1760. ************************/
  1761. unsigned long smt_get_time(void)
  1762. {
  1763. return jiffies;
  1764. } // smt_get_time
  1765. /************************
  1766. *
  1767. * smt_stat_counter
  1768. *
  1769. * Status counter update (ring_op, fifo full).
  1770. * Args
  1771. * smc - A pointer to the SMT context struct.
  1772. *
  1773. * stat - = 0: A ring operational change occurred.
  1774. * = 1: The FORMAC FIFO buffer is full / FIFO overflow.
  1775. * Out
  1776. * Nothing.
  1777. *
  1778. ************************/
  1779. void smt_stat_counter(struct s_smc *smc, int stat)
  1780. {
  1781. // BOOLEAN RingIsUp ;
  1782. pr_debug("smt_stat_counter\n");
  1783. switch (stat) {
  1784. case 0:
  1785. pr_debug("Ring operational change.\n");
  1786. break;
  1787. case 1:
  1788. pr_debug("Receive fifo overflow.\n");
  1789. smc->os.MacStat.gen.rx_errors++;
  1790. break;
  1791. default:
  1792. pr_debug("Unknown status (%d).\n", stat);
  1793. break;
  1794. }
  1795. } // smt_stat_counter
  1796. /************************
  1797. *
  1798. * cfm_state_change
  1799. *
  1800. * Sets CFM state in custom statistics.
  1801. * Args
  1802. * smc - A pointer to the SMT context struct.
  1803. *
  1804. * c_state - Possible values are:
  1805. *
  1806. * EC0_OUT, EC1_IN, EC2_TRACE, EC3_LEAVE, EC4_PATH_TEST,
  1807. * EC5_INSERT, EC6_CHECK, EC7_DEINSERT
  1808. * Out
  1809. * Nothing.
  1810. *
  1811. ************************/
  1812. void cfm_state_change(struct s_smc *smc, int c_state)
  1813. {
  1814. #ifdef DRIVERDEBUG
  1815. char *s;
  1816. switch (c_state) {
  1817. case SC0_ISOLATED:
  1818. s = "SC0_ISOLATED";
  1819. break;
  1820. case SC1_WRAP_A:
  1821. s = "SC1_WRAP_A";
  1822. break;
  1823. case SC2_WRAP_B:
  1824. s = "SC2_WRAP_B";
  1825. break;
  1826. case SC4_THRU_A:
  1827. s = "SC4_THRU_A";
  1828. break;
  1829. case SC5_THRU_B:
  1830. s = "SC5_THRU_B";
  1831. break;
  1832. case SC7_WRAP_S:
  1833. s = "SC7_WRAP_S";
  1834. break;
  1835. case SC9_C_WRAP_A:
  1836. s = "SC9_C_WRAP_A";
  1837. break;
  1838. case SC10_C_WRAP_B:
  1839. s = "SC10_C_WRAP_B";
  1840. break;
  1841. case SC11_C_WRAP_S:
  1842. s = "SC11_C_WRAP_S";
  1843. break;
  1844. default:
  1845. pr_debug("cfm_state_change: unknown %d\n", c_state);
  1846. return;
  1847. }
  1848. pr_debug("cfm_state_change: %s\n", s);
  1849. #endif // DRIVERDEBUG
  1850. } // cfm_state_change
  1851. /************************
  1852. *
  1853. * ecm_state_change
  1854. *
  1855. * Sets ECM state in custom statistics.
  1856. * Args
  1857. * smc - A pointer to the SMT context struct.
  1858. *
  1859. * e_state - Possible values are:
  1860. *
  1861. * SC0_ISOLATED, SC1_WRAP_A (5), SC2_WRAP_B (6), SC4_THRU_A (12),
  1862. * SC5_THRU_B (7), SC7_WRAP_S (8)
  1863. * Out
  1864. * Nothing.
  1865. *
  1866. ************************/
  1867. void ecm_state_change(struct s_smc *smc, int e_state)
  1868. {
  1869. #ifdef DRIVERDEBUG
  1870. char *s;
  1871. switch (e_state) {
  1872. case EC0_OUT:
  1873. s = "EC0_OUT";
  1874. break;
  1875. case EC1_IN:
  1876. s = "EC1_IN";
  1877. break;
  1878. case EC2_TRACE:
  1879. s = "EC2_TRACE";
  1880. break;
  1881. case EC3_LEAVE:
  1882. s = "EC3_LEAVE";
  1883. break;
  1884. case EC4_PATH_TEST:
  1885. s = "EC4_PATH_TEST";
  1886. break;
  1887. case EC5_INSERT:
  1888. s = "EC5_INSERT";
  1889. break;
  1890. case EC6_CHECK:
  1891. s = "EC6_CHECK";
  1892. break;
  1893. case EC7_DEINSERT:
  1894. s = "EC7_DEINSERT";
  1895. break;
  1896. default:
  1897. s = "unknown";
  1898. break;
  1899. }
  1900. pr_debug("ecm_state_change: %s\n", s);
  1901. #endif //DRIVERDEBUG
  1902. } // ecm_state_change
  1903. /************************
  1904. *
  1905. * rmt_state_change
  1906. *
  1907. * Sets RMT state in custom statistics.
  1908. * Args
  1909. * smc - A pointer to the SMT context struct.
  1910. *
  1911. * r_state - Possible values are:
  1912. *
  1913. * RM0_ISOLATED, RM1_NON_OP, RM2_RING_OP, RM3_DETECT,
  1914. * RM4_NON_OP_DUP, RM5_RING_OP_DUP, RM6_DIRECTED, RM7_TRACE
  1915. * Out
  1916. * Nothing.
  1917. *
  1918. ************************/
  1919. void rmt_state_change(struct s_smc *smc, int r_state)
  1920. {
  1921. #ifdef DRIVERDEBUG
  1922. char *s;
  1923. switch (r_state) {
  1924. case RM0_ISOLATED:
  1925. s = "RM0_ISOLATED";
  1926. break;
  1927. case RM1_NON_OP:
  1928. s = "RM1_NON_OP - not operational";
  1929. break;
  1930. case RM2_RING_OP:
  1931. s = "RM2_RING_OP - ring operational";
  1932. break;
  1933. case RM3_DETECT:
  1934. s = "RM3_DETECT - detect dupl addresses";
  1935. break;
  1936. case RM4_NON_OP_DUP:
  1937. s = "RM4_NON_OP_DUP - dupl. addr detected";
  1938. break;
  1939. case RM5_RING_OP_DUP:
  1940. s = "RM5_RING_OP_DUP - ring oper. with dupl. addr";
  1941. break;
  1942. case RM6_DIRECTED:
  1943. s = "RM6_DIRECTED - sending directed beacons";
  1944. break;
  1945. case RM7_TRACE:
  1946. s = "RM7_TRACE - trace initiated";
  1947. break;
  1948. default:
  1949. s = "unknown";
  1950. break;
  1951. }
  1952. pr_debug("[rmt_state_change: %s]\n", s);
  1953. #endif // DRIVERDEBUG
  1954. } // rmt_state_change
  1955. /************************
  1956. *
  1957. * drv_reset_indication
  1958. *
  1959. * This function is called by the SMT when it has detected a severe
  1960. * hardware problem. The driver should perform a reset on the adapter
  1961. * as soon as possible, but not from within this function.
  1962. * Args
  1963. * smc - A pointer to the SMT context struct.
  1964. * Out
  1965. * Nothing.
  1966. *
  1967. ************************/
  1968. void drv_reset_indication(struct s_smc *smc)
  1969. {
  1970. pr_debug("entering drv_reset_indication\n");
  1971. smc->os.ResetRequested = TRUE; // Set flag.
  1972. } // drv_reset_indication
  1973. static struct pci_driver skfddi_pci_driver = {
  1974. .name = "skfddi",
  1975. .id_table = skfddi_pci_tbl,
  1976. .probe = skfp_init_one,
  1977. .remove = __devexit_p(skfp_remove_one),
  1978. };
  1979. static int __init skfd_init(void)
  1980. {
  1981. return pci_register_driver(&skfddi_pci_driver);
  1982. }
  1983. static void __exit skfd_exit(void)
  1984. {
  1985. pci_unregister_driver(&skfddi_pci_driver);
  1986. }
  1987. module_init(skfd_init);
  1988. module_exit(skfd_exit);