vxge-main.c 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528
  1. /******************************************************************************
  2. * This software may be used and distributed according to the terms of
  3. * the GNU General Public License (GPL), incorporated herein by reference.
  4. * Drivers based on or derived from this code fall under the GPL and must
  5. * retain the authorship, copyright and license notice. This file is not
  6. * a complete program and may only be used when the entire operating
  7. * system is licensed under the GPL.
  8. * See the file COPYING in this distribution for more information.
  9. *
  10. * vxge-main.c: Driver for Neterion Inc's X3100 Series 10GbE PCIe I/O
  11. * Virtualized Server Adapter.
  12. * Copyright(c) 2002-2009 Neterion Inc.
  13. *
  14. * The module loadable parameters that are supported by the driver and a brief
  15. * explanation of all the variables:
  16. * vlan_tag_strip:
  17. * Strip VLAN Tag enable/disable. Instructs the device to remove
  18. * the VLAN tag from all received tagged frames that are not
  19. * replicated at the internal L2 switch.
  20. * 0 - Do not strip the VLAN tag.
  21. * 1 - Strip the VLAN tag.
  22. *
  23. * addr_learn_en:
  24. * Enable learning the mac address of the guest OS interface in
  25. * a virtualization environment.
  26. * 0 - DISABLE
  27. * 1 - ENABLE
  28. *
  29. * max_config_port:
  30. * Maximum number of port to be supported.
  31. * MIN -1 and MAX - 2
  32. *
  33. * max_config_vpath:
  34. * This configures the maximum no of VPATH configures for each
  35. * device function.
  36. * MIN - 1 and MAX - 17
  37. *
  38. * max_config_dev:
  39. * This configures maximum no of Device function to be enabled.
  40. * MIN - 1 and MAX - 17
  41. *
  42. ******************************************************************************/
  43. #include <linux/if_vlan.h>
  44. #include <linux/pci.h>
  45. #include <linux/tcp.h>
  46. #include <net/ip.h>
  47. #include <linux/netdevice.h>
  48. #include <linux/etherdevice.h>
  49. #include "vxge-main.h"
  50. #include "vxge-reg.h"
  51. MODULE_LICENSE("Dual BSD/GPL");
  52. MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
  53. "Virtualized Server Adapter");
  54. static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
  55. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
  56. PCI_ANY_ID},
  57. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
  58. PCI_ANY_ID},
  59. {0}
  60. };
  61. MODULE_DEVICE_TABLE(pci, vxge_id_table);
  62. VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
  63. VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
  64. VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
  65. VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
  66. VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
  67. VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
  68. static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
  69. {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
  70. static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
  71. {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
  72. module_param_array(bw_percentage, uint, NULL, 0);
  73. static struct vxge_drv_config *driver_config;
  74. static inline int is_vxge_card_up(struct vxgedev *vdev)
  75. {
  76. return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  77. }
  78. static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
  79. {
  80. unsigned long flags = 0;
  81. struct sk_buff **skb_ptr = NULL;
  82. struct sk_buff **temp;
  83. #define NR_SKB_COMPLETED 128
  84. struct sk_buff *completed[NR_SKB_COMPLETED];
  85. int more;
  86. do {
  87. more = 0;
  88. skb_ptr = completed;
  89. if (spin_trylock_irqsave(&fifo->tx_lock, flags)) {
  90. vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
  91. NR_SKB_COMPLETED, &more);
  92. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  93. }
  94. /* free SKBs */
  95. for (temp = completed; temp != skb_ptr; temp++)
  96. dev_kfree_skb_irq(*temp);
  97. } while (more) ;
  98. }
  99. static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
  100. {
  101. int i;
  102. /* Complete all transmits */
  103. for (i = 0; i < vdev->no_of_vpath; i++)
  104. VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
  105. }
  106. static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
  107. {
  108. int i;
  109. struct vxge_ring *ring;
  110. /* Complete all receives*/
  111. for (i = 0; i < vdev->no_of_vpath; i++) {
  112. ring = &vdev->vpaths[i].ring;
  113. vxge_hw_vpath_poll_rx(ring->handle);
  114. }
  115. }
  116. /*
  117. * MultiQ manipulation helper functions
  118. */
  119. void vxge_stop_all_tx_queue(struct vxgedev *vdev)
  120. {
  121. int i;
  122. struct net_device *dev = vdev->ndev;
  123. if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
  124. for (i = 0; i < vdev->no_of_vpath; i++)
  125. vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_STOP;
  126. }
  127. netif_tx_stop_all_queues(dev);
  128. }
  129. void vxge_stop_tx_queue(struct vxge_fifo *fifo)
  130. {
  131. struct net_device *dev = fifo->ndev;
  132. struct netdev_queue *txq = NULL;
  133. if (fifo->tx_steering_type == TX_MULTIQ_STEERING)
  134. txq = netdev_get_tx_queue(dev, fifo->driver_id);
  135. else {
  136. txq = netdev_get_tx_queue(dev, 0);
  137. fifo->queue_state = VPATH_QUEUE_STOP;
  138. }
  139. netif_tx_stop_queue(txq);
  140. }
  141. void vxge_start_all_tx_queue(struct vxgedev *vdev)
  142. {
  143. int i;
  144. struct net_device *dev = vdev->ndev;
  145. if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
  146. for (i = 0; i < vdev->no_of_vpath; i++)
  147. vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_START;
  148. }
  149. netif_tx_start_all_queues(dev);
  150. }
  151. static void vxge_wake_all_tx_queue(struct vxgedev *vdev)
  152. {
  153. int i;
  154. struct net_device *dev = vdev->ndev;
  155. if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
  156. for (i = 0; i < vdev->no_of_vpath; i++)
  157. vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_START;
  158. }
  159. netif_tx_wake_all_queues(dev);
  160. }
  161. void vxge_wake_tx_queue(struct vxge_fifo *fifo, struct sk_buff *skb)
  162. {
  163. struct net_device *dev = fifo->ndev;
  164. int vpath_no = fifo->driver_id;
  165. struct netdev_queue *txq = NULL;
  166. if (fifo->tx_steering_type == TX_MULTIQ_STEERING) {
  167. txq = netdev_get_tx_queue(dev, vpath_no);
  168. if (netif_tx_queue_stopped(txq))
  169. netif_tx_wake_queue(txq);
  170. } else {
  171. txq = netdev_get_tx_queue(dev, 0);
  172. if (fifo->queue_state == VPATH_QUEUE_STOP)
  173. if (netif_tx_queue_stopped(txq)) {
  174. fifo->queue_state = VPATH_QUEUE_START;
  175. netif_tx_wake_queue(txq);
  176. }
  177. }
  178. }
  179. /*
  180. * vxge_callback_link_up
  181. *
  182. * This function is called during interrupt context to notify link up state
  183. * change.
  184. */
  185. void
  186. vxge_callback_link_up(struct __vxge_hw_device *hldev)
  187. {
  188. struct net_device *dev = hldev->ndev;
  189. struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
  190. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  191. vdev->ndev->name, __func__, __LINE__);
  192. printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
  193. vdev->stats.link_up++;
  194. netif_carrier_on(vdev->ndev);
  195. vxge_wake_all_tx_queue(vdev);
  196. vxge_debug_entryexit(VXGE_TRACE,
  197. "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
  198. }
  199. /*
  200. * vxge_callback_link_down
  201. *
  202. * This function is called during interrupt context to notify link down state
  203. * change.
  204. */
  205. void
  206. vxge_callback_link_down(struct __vxge_hw_device *hldev)
  207. {
  208. struct net_device *dev = hldev->ndev;
  209. struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
  210. vxge_debug_entryexit(VXGE_TRACE,
  211. "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
  212. printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
  213. vdev->stats.link_down++;
  214. netif_carrier_off(vdev->ndev);
  215. vxge_stop_all_tx_queue(vdev);
  216. vxge_debug_entryexit(VXGE_TRACE,
  217. "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
  218. }
  219. /*
  220. * vxge_rx_alloc
  221. *
  222. * Allocate SKB.
  223. */
  224. static struct sk_buff*
  225. vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
  226. {
  227. struct net_device *dev;
  228. struct sk_buff *skb;
  229. struct vxge_rx_priv *rx_priv;
  230. dev = ring->ndev;
  231. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  232. ring->ndev->name, __func__, __LINE__);
  233. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  234. /* try to allocate skb first. this one may fail */
  235. skb = netdev_alloc_skb(dev, skb_size +
  236. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  237. if (skb == NULL) {
  238. vxge_debug_mem(VXGE_ERR,
  239. "%s: out of memory to allocate SKB", dev->name);
  240. ring->stats.skb_alloc_fail++;
  241. return NULL;
  242. }
  243. vxge_debug_mem(VXGE_TRACE,
  244. "%s: %s:%d Skb : 0x%p", ring->ndev->name,
  245. __func__, __LINE__, skb);
  246. skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  247. rx_priv->skb = skb;
  248. rx_priv->skb_data = NULL;
  249. rx_priv->data_size = skb_size;
  250. vxge_debug_entryexit(VXGE_TRACE,
  251. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  252. return skb;
  253. }
  254. /*
  255. * vxge_rx_map
  256. */
  257. static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
  258. {
  259. struct vxge_rx_priv *rx_priv;
  260. dma_addr_t dma_addr;
  261. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  262. ring->ndev->name, __func__, __LINE__);
  263. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  264. rx_priv->skb_data = rx_priv->skb->data;
  265. dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
  266. rx_priv->data_size, PCI_DMA_FROMDEVICE);
  267. if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
  268. ring->stats.pci_map_fail++;
  269. return -EIO;
  270. }
  271. vxge_debug_mem(VXGE_TRACE,
  272. "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
  273. ring->ndev->name, __func__, __LINE__,
  274. (unsigned long long)dma_addr);
  275. vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
  276. rx_priv->data_dma = dma_addr;
  277. vxge_debug_entryexit(VXGE_TRACE,
  278. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  279. return 0;
  280. }
  281. /*
  282. * vxge_rx_initial_replenish
  283. * Allocation of RxD as an initial replenish procedure.
  284. */
  285. static enum vxge_hw_status
  286. vxge_rx_initial_replenish(void *dtrh, void *userdata)
  287. {
  288. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  289. struct vxge_rx_priv *rx_priv;
  290. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  291. ring->ndev->name, __func__, __LINE__);
  292. if (vxge_rx_alloc(dtrh, ring,
  293. VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
  294. return VXGE_HW_FAIL;
  295. if (vxge_rx_map(dtrh, ring)) {
  296. rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
  297. dev_kfree_skb(rx_priv->skb);
  298. return VXGE_HW_FAIL;
  299. }
  300. vxge_debug_entryexit(VXGE_TRACE,
  301. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  302. return VXGE_HW_OK;
  303. }
  304. static inline void
  305. vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
  306. int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
  307. {
  308. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  309. ring->ndev->name, __func__, __LINE__);
  310. skb_record_rx_queue(skb, ring->driver_id);
  311. skb->protocol = eth_type_trans(skb, ring->ndev);
  312. ring->stats.rx_frms++;
  313. ring->stats.rx_bytes += pkt_length;
  314. if (skb->pkt_type == PACKET_MULTICAST)
  315. ring->stats.rx_mcast++;
  316. vxge_debug_rx(VXGE_TRACE,
  317. "%s: %s:%d skb protocol = %d",
  318. ring->ndev->name, __func__, __LINE__, skb->protocol);
  319. if (ring->gro_enable) {
  320. if (ring->vlgrp && ext_info->vlan &&
  321. (ring->vlan_tag_strip ==
  322. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
  323. vlan_gro_receive(ring->napi_p, ring->vlgrp,
  324. ext_info->vlan, skb);
  325. else
  326. napi_gro_receive(ring->napi_p, skb);
  327. } else {
  328. if (ring->vlgrp && vlan &&
  329. (ring->vlan_tag_strip ==
  330. VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
  331. vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
  332. else
  333. netif_receive_skb(skb);
  334. }
  335. vxge_debug_entryexit(VXGE_TRACE,
  336. "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
  337. }
  338. static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
  339. struct vxge_rx_priv *rx_priv)
  340. {
  341. pci_dma_sync_single_for_device(ring->pdev,
  342. rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
  343. vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
  344. vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
  345. }
  346. static inline void vxge_post(int *dtr_cnt, void **first_dtr,
  347. void *post_dtr, struct __vxge_hw_ring *ringh)
  348. {
  349. int dtr_count = *dtr_cnt;
  350. if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
  351. if (*first_dtr)
  352. vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
  353. *first_dtr = post_dtr;
  354. } else
  355. vxge_hw_ring_rxd_post_post(ringh, post_dtr);
  356. dtr_count++;
  357. *dtr_cnt = dtr_count;
  358. }
  359. /*
  360. * vxge_rx_1b_compl
  361. *
  362. * If the interrupt is because of a received frame or if the receive ring
  363. * contains fresh as yet un-processed frames, this function is called.
  364. */
  365. enum vxge_hw_status
  366. vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
  367. u8 t_code, void *userdata)
  368. {
  369. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  370. struct net_device *dev = ring->ndev;
  371. unsigned int dma_sizes;
  372. void *first_dtr = NULL;
  373. int dtr_cnt = 0;
  374. int data_size;
  375. dma_addr_t data_dma;
  376. int pkt_length;
  377. struct sk_buff *skb;
  378. struct vxge_rx_priv *rx_priv;
  379. struct vxge_hw_ring_rxd_info ext_info;
  380. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  381. ring->ndev->name, __func__, __LINE__);
  382. ring->pkts_processed = 0;
  383. vxge_hw_ring_replenish(ringh, 0);
  384. do {
  385. prefetch((char *)dtr + L1_CACHE_BYTES);
  386. rx_priv = vxge_hw_ring_rxd_private_get(dtr);
  387. skb = rx_priv->skb;
  388. data_size = rx_priv->data_size;
  389. data_dma = rx_priv->data_dma;
  390. prefetch(rx_priv->skb_data);
  391. vxge_debug_rx(VXGE_TRACE,
  392. "%s: %s:%d skb = 0x%p",
  393. ring->ndev->name, __func__, __LINE__, skb);
  394. vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
  395. pkt_length = dma_sizes;
  396. pkt_length -= ETH_FCS_LEN;
  397. vxge_debug_rx(VXGE_TRACE,
  398. "%s: %s:%d Packet Length = %d",
  399. ring->ndev->name, __func__, __LINE__, pkt_length);
  400. vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
  401. /* check skb validity */
  402. vxge_assert(skb);
  403. prefetch((char *)skb + L1_CACHE_BYTES);
  404. if (unlikely(t_code)) {
  405. if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
  406. VXGE_HW_OK) {
  407. ring->stats.rx_errors++;
  408. vxge_debug_rx(VXGE_TRACE,
  409. "%s: %s :%d Rx T_code is %d",
  410. ring->ndev->name, __func__,
  411. __LINE__, t_code);
  412. /* If the t_code is not supported and if the
  413. * t_code is other than 0x5 (unparseable packet
  414. * such as unknown UPV6 header), Drop it !!!
  415. */
  416. vxge_re_pre_post(dtr, ring, rx_priv);
  417. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  418. ring->stats.rx_dropped++;
  419. continue;
  420. }
  421. }
  422. if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
  423. if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
  424. if (!vxge_rx_map(dtr, ring)) {
  425. skb_put(skb, pkt_length);
  426. pci_unmap_single(ring->pdev, data_dma,
  427. data_size, PCI_DMA_FROMDEVICE);
  428. vxge_hw_ring_rxd_pre_post(ringh, dtr);
  429. vxge_post(&dtr_cnt, &first_dtr, dtr,
  430. ringh);
  431. } else {
  432. dev_kfree_skb(rx_priv->skb);
  433. rx_priv->skb = skb;
  434. rx_priv->data_size = data_size;
  435. vxge_re_pre_post(dtr, ring, rx_priv);
  436. vxge_post(&dtr_cnt, &first_dtr, dtr,
  437. ringh);
  438. ring->stats.rx_dropped++;
  439. break;
  440. }
  441. } else {
  442. vxge_re_pre_post(dtr, ring, rx_priv);
  443. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  444. ring->stats.rx_dropped++;
  445. break;
  446. }
  447. } else {
  448. struct sk_buff *skb_up;
  449. skb_up = netdev_alloc_skb(dev, pkt_length +
  450. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  451. if (skb_up != NULL) {
  452. skb_reserve(skb_up,
  453. VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
  454. pci_dma_sync_single_for_cpu(ring->pdev,
  455. data_dma, data_size,
  456. PCI_DMA_FROMDEVICE);
  457. vxge_debug_mem(VXGE_TRACE,
  458. "%s: %s:%d skb_up = %p",
  459. ring->ndev->name, __func__,
  460. __LINE__, skb);
  461. memcpy(skb_up->data, skb->data, pkt_length);
  462. vxge_re_pre_post(dtr, ring, rx_priv);
  463. vxge_post(&dtr_cnt, &first_dtr, dtr,
  464. ringh);
  465. /* will netif_rx small SKB instead */
  466. skb = skb_up;
  467. skb_put(skb, pkt_length);
  468. } else {
  469. vxge_re_pre_post(dtr, ring, rx_priv);
  470. vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
  471. vxge_debug_rx(VXGE_ERR,
  472. "%s: vxge_rx_1b_compl: out of "
  473. "memory", dev->name);
  474. ring->stats.skb_alloc_fail++;
  475. break;
  476. }
  477. }
  478. if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
  479. !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
  480. ring->rx_csum && /* Offload Rx side CSUM */
  481. ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
  482. ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
  483. skb->ip_summed = CHECKSUM_UNNECESSARY;
  484. else
  485. skb->ip_summed = CHECKSUM_NONE;
  486. vxge_rx_complete(ring, skb, ext_info.vlan,
  487. pkt_length, &ext_info);
  488. ring->budget--;
  489. ring->pkts_processed++;
  490. if (!ring->budget)
  491. break;
  492. } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
  493. &t_code) == VXGE_HW_OK);
  494. if (first_dtr)
  495. vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
  496. vxge_debug_entryexit(VXGE_TRACE,
  497. "%s:%d Exiting...",
  498. __func__, __LINE__);
  499. return VXGE_HW_OK;
  500. }
  501. /*
  502. * vxge_xmit_compl
  503. *
  504. * If an interrupt was raised to indicate DMA complete of the Tx packet,
  505. * this function is called. It identifies the last TxD whose buffer was
  506. * freed and frees all skbs whose data have already DMA'ed into the NICs
  507. * internal memory.
  508. */
  509. enum vxge_hw_status
  510. vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
  511. enum vxge_hw_fifo_tcode t_code, void *userdata,
  512. struct sk_buff ***skb_ptr, int nr_skb, int *more)
  513. {
  514. struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
  515. struct sk_buff *skb, **done_skb = *skb_ptr;
  516. int pkt_cnt = 0;
  517. vxge_debug_entryexit(VXGE_TRACE,
  518. "%s:%d Entered....", __func__, __LINE__);
  519. do {
  520. int frg_cnt;
  521. skb_frag_t *frag;
  522. int i = 0, j;
  523. struct vxge_tx_priv *txd_priv =
  524. vxge_hw_fifo_txdl_private_get(dtr);
  525. skb = txd_priv->skb;
  526. frg_cnt = skb_shinfo(skb)->nr_frags;
  527. frag = &skb_shinfo(skb)->frags[0];
  528. vxge_debug_tx(VXGE_TRACE,
  529. "%s: %s:%d fifo_hw = %p dtr = %p "
  530. "tcode = 0x%x", fifo->ndev->name, __func__,
  531. __LINE__, fifo_hw, dtr, t_code);
  532. /* check skb validity */
  533. vxge_assert(skb);
  534. vxge_debug_tx(VXGE_TRACE,
  535. "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
  536. fifo->ndev->name, __func__, __LINE__,
  537. skb, txd_priv, frg_cnt);
  538. if (unlikely(t_code)) {
  539. fifo->stats.tx_errors++;
  540. vxge_debug_tx(VXGE_ERR,
  541. "%s: tx: dtr %p completed due to "
  542. "error t_code %01x", fifo->ndev->name,
  543. dtr, t_code);
  544. vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
  545. }
  546. /* for unfragmented skb */
  547. pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
  548. skb_headlen(skb), PCI_DMA_TODEVICE);
  549. for (j = 0; j < frg_cnt; j++) {
  550. pci_unmap_page(fifo->pdev,
  551. txd_priv->dma_buffers[i++],
  552. frag->size, PCI_DMA_TODEVICE);
  553. frag += 1;
  554. }
  555. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  556. /* Updating the statistics block */
  557. fifo->stats.tx_frms++;
  558. fifo->stats.tx_bytes += skb->len;
  559. *done_skb++ = skb;
  560. if (--nr_skb <= 0) {
  561. *more = 1;
  562. break;
  563. }
  564. pkt_cnt++;
  565. if (pkt_cnt > fifo->indicate_max_pkts)
  566. break;
  567. } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
  568. &dtr, &t_code) == VXGE_HW_OK);
  569. *skb_ptr = done_skb;
  570. vxge_wake_tx_queue(fifo, skb);
  571. vxge_debug_entryexit(VXGE_TRACE,
  572. "%s: %s:%d Exiting...",
  573. fifo->ndev->name, __func__, __LINE__);
  574. return VXGE_HW_OK;
  575. }
  576. /* select a vpath to transmit the packet */
  577. static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb,
  578. int *do_lock)
  579. {
  580. u16 queue_len, counter = 0;
  581. if (skb->protocol == htons(ETH_P_IP)) {
  582. struct iphdr *ip;
  583. struct tcphdr *th;
  584. ip = ip_hdr(skb);
  585. if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
  586. th = (struct tcphdr *)(((unsigned char *)ip) +
  587. ip->ihl*4);
  588. queue_len = vdev->no_of_vpath;
  589. counter = (ntohs(th->source) +
  590. ntohs(th->dest)) &
  591. vdev->vpath_selector[queue_len - 1];
  592. if (counter >= queue_len)
  593. counter = queue_len - 1;
  594. if (ip->protocol == IPPROTO_UDP) {
  595. #ifdef NETIF_F_LLTX
  596. *do_lock = 0;
  597. #endif
  598. }
  599. }
  600. }
  601. return counter;
  602. }
  603. static enum vxge_hw_status vxge_search_mac_addr_in_list(
  604. struct vxge_vpath *vpath, u64 del_mac)
  605. {
  606. struct list_head *entry, *next;
  607. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  608. if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
  609. return TRUE;
  610. }
  611. return FALSE;
  612. }
  613. static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
  614. {
  615. struct macInfo mac_info;
  616. u8 *mac_address = NULL;
  617. u64 mac_addr = 0, vpath_vector = 0;
  618. int vpath_idx = 0;
  619. enum vxge_hw_status status = VXGE_HW_OK;
  620. struct vxge_vpath *vpath = NULL;
  621. struct __vxge_hw_device *hldev;
  622. hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
  623. mac_address = (u8 *)&mac_addr;
  624. memcpy(mac_address, mac_header, ETH_ALEN);
  625. /* Is this mac address already in the list? */
  626. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  627. vpath = &vdev->vpaths[vpath_idx];
  628. if (vxge_search_mac_addr_in_list(vpath, mac_addr))
  629. return vpath_idx;
  630. }
  631. memset(&mac_info, 0, sizeof(struct macInfo));
  632. memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
  633. /* Any vpath has room to add mac address to its da table? */
  634. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  635. vpath = &vdev->vpaths[vpath_idx];
  636. if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
  637. /* Add this mac address to this vpath */
  638. mac_info.vpath_no = vpath_idx;
  639. mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  640. status = vxge_add_mac_addr(vdev, &mac_info);
  641. if (status != VXGE_HW_OK)
  642. return -EPERM;
  643. return vpath_idx;
  644. }
  645. }
  646. mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
  647. vpath_idx = 0;
  648. mac_info.vpath_no = vpath_idx;
  649. /* Is the first vpath already selected as catch-basin ? */
  650. vpath = &vdev->vpaths[vpath_idx];
  651. if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
  652. /* Add this mac address to this vpath */
  653. if (FALSE == vxge_mac_list_add(vpath, &mac_info))
  654. return -EPERM;
  655. return vpath_idx;
  656. }
  657. /* Select first vpath as catch-basin */
  658. vpath_vector = vxge_mBIT(vpath->device_id);
  659. status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
  660. vxge_hw_mgmt_reg_type_mrpcim,
  661. 0,
  662. (ulong)offsetof(
  663. struct vxge_hw_mrpcim_reg,
  664. rts_mgr_cbasin_cfg),
  665. vpath_vector);
  666. if (status != VXGE_HW_OK) {
  667. vxge_debug_tx(VXGE_ERR,
  668. "%s: Unable to set the vpath-%d in catch-basin mode",
  669. VXGE_DRIVER_NAME, vpath->device_id);
  670. return -EPERM;
  671. }
  672. if (FALSE == vxge_mac_list_add(vpath, &mac_info))
  673. return -EPERM;
  674. return vpath_idx;
  675. }
  676. /**
  677. * vxge_xmit
  678. * @skb : the socket buffer containing the Tx data.
  679. * @dev : device pointer.
  680. *
  681. * This function is the Tx entry point of the driver. Neterion NIC supports
  682. * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
  683. * NOTE: when device cant queue the pkt, just the trans_start variable will
  684. * not be upadted.
  685. */
  686. static netdev_tx_t
  687. vxge_xmit(struct sk_buff *skb, struct net_device *dev)
  688. {
  689. struct vxge_fifo *fifo = NULL;
  690. void *dtr_priv;
  691. void *dtr = NULL;
  692. struct vxgedev *vdev = NULL;
  693. enum vxge_hw_status status;
  694. int frg_cnt, first_frg_len;
  695. skb_frag_t *frag;
  696. int i = 0, j = 0, avail;
  697. u64 dma_pointer;
  698. struct vxge_tx_priv *txdl_priv = NULL;
  699. struct __vxge_hw_fifo *fifo_hw;
  700. int offload_type;
  701. unsigned long flags = 0;
  702. int vpath_no = 0;
  703. int do_spin_tx_lock = 1;
  704. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  705. dev->name, __func__, __LINE__);
  706. /* A buffer with no data will be dropped */
  707. if (unlikely(skb->len <= 0)) {
  708. vxge_debug_tx(VXGE_ERR,
  709. "%s: Buffer has no data..", dev->name);
  710. dev_kfree_skb(skb);
  711. return NETDEV_TX_OK;
  712. }
  713. vdev = (struct vxgedev *)netdev_priv(dev);
  714. if (unlikely(!is_vxge_card_up(vdev))) {
  715. vxge_debug_tx(VXGE_ERR,
  716. "%s: vdev not initialized", dev->name);
  717. dev_kfree_skb(skb);
  718. return NETDEV_TX_OK;
  719. }
  720. if (vdev->config.addr_learn_en) {
  721. vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
  722. if (vpath_no == -EPERM) {
  723. vxge_debug_tx(VXGE_ERR,
  724. "%s: Failed to store the mac address",
  725. dev->name);
  726. dev_kfree_skb(skb);
  727. return NETDEV_TX_OK;
  728. }
  729. }
  730. if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
  731. vpath_no = skb_get_queue_mapping(skb);
  732. else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
  733. vpath_no = vxge_get_vpath_no(vdev, skb, &do_spin_tx_lock);
  734. vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
  735. if (vpath_no >= vdev->no_of_vpath)
  736. vpath_no = 0;
  737. fifo = &vdev->vpaths[vpath_no].fifo;
  738. fifo_hw = fifo->handle;
  739. if (do_spin_tx_lock)
  740. spin_lock_irqsave(&fifo->tx_lock, flags);
  741. else {
  742. if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
  743. return NETDEV_TX_LOCKED;
  744. }
  745. if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING) {
  746. if (netif_subqueue_stopped(dev, skb)) {
  747. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  748. return NETDEV_TX_BUSY;
  749. }
  750. } else if (unlikely(fifo->queue_state == VPATH_QUEUE_STOP)) {
  751. if (netif_queue_stopped(dev)) {
  752. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  753. return NETDEV_TX_BUSY;
  754. }
  755. }
  756. avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
  757. if (avail == 0) {
  758. vxge_debug_tx(VXGE_ERR,
  759. "%s: No free TXDs available", dev->name);
  760. fifo->stats.txd_not_free++;
  761. vxge_stop_tx_queue(fifo);
  762. goto _exit2;
  763. }
  764. /* Last TXD? Stop tx queue to avoid dropping packets. TX
  765. * completion will resume the queue.
  766. */
  767. if (avail == 1)
  768. vxge_stop_tx_queue(fifo);
  769. status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
  770. if (unlikely(status != VXGE_HW_OK)) {
  771. vxge_debug_tx(VXGE_ERR,
  772. "%s: Out of descriptors .", dev->name);
  773. fifo->stats.txd_out_of_desc++;
  774. vxge_stop_tx_queue(fifo);
  775. goto _exit2;
  776. }
  777. vxge_debug_tx(VXGE_TRACE,
  778. "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
  779. dev->name, __func__, __LINE__,
  780. fifo_hw, dtr, dtr_priv);
  781. if (vdev->vlgrp && vlan_tx_tag_present(skb)) {
  782. u16 vlan_tag = vlan_tx_tag_get(skb);
  783. vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
  784. }
  785. first_frg_len = skb_headlen(skb);
  786. dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
  787. PCI_DMA_TODEVICE);
  788. if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
  789. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  790. vxge_stop_tx_queue(fifo);
  791. fifo->stats.pci_map_fail++;
  792. goto _exit2;
  793. }
  794. txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
  795. txdl_priv->skb = skb;
  796. txdl_priv->dma_buffers[j] = dma_pointer;
  797. frg_cnt = skb_shinfo(skb)->nr_frags;
  798. vxge_debug_tx(VXGE_TRACE,
  799. "%s: %s:%d skb = %p txdl_priv = %p "
  800. "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
  801. __func__, __LINE__, skb, txdl_priv,
  802. frg_cnt, (unsigned long long)dma_pointer);
  803. vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
  804. first_frg_len);
  805. frag = &skb_shinfo(skb)->frags[0];
  806. for (i = 0; i < frg_cnt; i++) {
  807. /* ignore 0 length fragment */
  808. if (!frag->size)
  809. continue;
  810. dma_pointer =
  811. (u64)pci_map_page(fifo->pdev, frag->page,
  812. frag->page_offset, frag->size,
  813. PCI_DMA_TODEVICE);
  814. if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
  815. goto _exit0;
  816. vxge_debug_tx(VXGE_TRACE,
  817. "%s: %s:%d frag = %d dma_pointer = 0x%llx",
  818. dev->name, __func__, __LINE__, i,
  819. (unsigned long long)dma_pointer);
  820. txdl_priv->dma_buffers[j] = dma_pointer;
  821. vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
  822. frag->size);
  823. frag += 1;
  824. }
  825. offload_type = vxge_offload_type(skb);
  826. if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
  827. int mss = vxge_tcp_mss(skb);
  828. if (mss) {
  829. vxge_debug_tx(VXGE_TRACE,
  830. "%s: %s:%d mss = %d",
  831. dev->name, __func__, __LINE__, mss);
  832. vxge_hw_fifo_txdl_mss_set(dtr, mss);
  833. } else {
  834. vxge_assert(skb->len <=
  835. dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
  836. vxge_assert(0);
  837. goto _exit1;
  838. }
  839. }
  840. if (skb->ip_summed == CHECKSUM_PARTIAL)
  841. vxge_hw_fifo_txdl_cksum_set_bits(dtr,
  842. VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
  843. VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
  844. VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
  845. vxge_hw_fifo_txdl_post(fifo_hw, dtr);
  846. #ifdef NETIF_F_LLTX
  847. dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
  848. #endif
  849. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  850. VXGE_COMPLETE_VPATH_TX(fifo);
  851. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
  852. dev->name, __func__, __LINE__);
  853. return NETDEV_TX_OK;
  854. _exit0:
  855. vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
  856. _exit1:
  857. j = 0;
  858. frag = &skb_shinfo(skb)->frags[0];
  859. pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
  860. skb_headlen(skb), PCI_DMA_TODEVICE);
  861. for (; j < i; j++) {
  862. pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
  863. frag->size, PCI_DMA_TODEVICE);
  864. frag += 1;
  865. }
  866. vxge_hw_fifo_txdl_free(fifo_hw, dtr);
  867. _exit2:
  868. dev_kfree_skb(skb);
  869. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  870. VXGE_COMPLETE_VPATH_TX(fifo);
  871. return NETDEV_TX_OK;
  872. }
  873. /*
  874. * vxge_rx_term
  875. *
  876. * Function will be called by hw function to abort all outstanding receive
  877. * descriptors.
  878. */
  879. static void
  880. vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
  881. {
  882. struct vxge_ring *ring = (struct vxge_ring *)userdata;
  883. struct vxge_rx_priv *rx_priv =
  884. vxge_hw_ring_rxd_private_get(dtrh);
  885. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  886. ring->ndev->name, __func__, __LINE__);
  887. if (state != VXGE_HW_RXD_STATE_POSTED)
  888. return;
  889. pci_unmap_single(ring->pdev, rx_priv->data_dma,
  890. rx_priv->data_size, PCI_DMA_FROMDEVICE);
  891. dev_kfree_skb(rx_priv->skb);
  892. rx_priv->skb_data = NULL;
  893. vxge_debug_entryexit(VXGE_TRACE,
  894. "%s: %s:%d Exiting...",
  895. ring->ndev->name, __func__, __LINE__);
  896. }
  897. /*
  898. * vxge_tx_term
  899. *
  900. * Function will be called to abort all outstanding tx descriptors
  901. */
  902. static void
  903. vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
  904. {
  905. struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
  906. skb_frag_t *frag;
  907. int i = 0, j, frg_cnt;
  908. struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
  909. struct sk_buff *skb = txd_priv->skb;
  910. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  911. if (state != VXGE_HW_TXDL_STATE_POSTED)
  912. return;
  913. /* check skb validity */
  914. vxge_assert(skb);
  915. frg_cnt = skb_shinfo(skb)->nr_frags;
  916. frag = &skb_shinfo(skb)->frags[0];
  917. /* for unfragmented skb */
  918. pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
  919. skb_headlen(skb), PCI_DMA_TODEVICE);
  920. for (j = 0; j < frg_cnt; j++) {
  921. pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
  922. frag->size, PCI_DMA_TODEVICE);
  923. frag += 1;
  924. }
  925. dev_kfree_skb(skb);
  926. vxge_debug_entryexit(VXGE_TRACE,
  927. "%s:%d Exiting...", __func__, __LINE__);
  928. }
  929. /**
  930. * vxge_set_multicast
  931. * @dev: pointer to the device structure
  932. *
  933. * Entry point for multicast address enable/disable
  934. * This function is a driver entry point which gets called by the kernel
  935. * whenever multicast addresses must be enabled/disabled. This also gets
  936. * called to set/reset promiscuous mode. Depending on the deivce flag, we
  937. * determine, if multicast address must be enabled or if promiscuous mode
  938. * is to be disabled etc.
  939. */
  940. static void vxge_set_multicast(struct net_device *dev)
  941. {
  942. struct dev_mc_list *mclist;
  943. struct vxgedev *vdev;
  944. int i, mcast_cnt = 0;
  945. struct __vxge_hw_device *hldev;
  946. enum vxge_hw_status status = VXGE_HW_OK;
  947. struct macInfo mac_info;
  948. int vpath_idx = 0;
  949. struct vxge_mac_addrs *mac_entry;
  950. struct list_head *list_head;
  951. struct list_head *entry, *next;
  952. u8 *mac_address = NULL;
  953. vxge_debug_entryexit(VXGE_TRACE,
  954. "%s:%d", __func__, __LINE__);
  955. vdev = (struct vxgedev *)netdev_priv(dev);
  956. hldev = (struct __vxge_hw_device *)vdev->devh;
  957. if (unlikely(!is_vxge_card_up(vdev)))
  958. return;
  959. if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
  960. for (i = 0; i < vdev->no_of_vpath; i++) {
  961. vxge_assert(vdev->vpaths[i].is_open);
  962. status = vxge_hw_vpath_mcast_enable(
  963. vdev->vpaths[i].handle);
  964. vdev->all_multi_flg = 1;
  965. }
  966. } else if ((dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
  967. for (i = 0; i < vdev->no_of_vpath; i++) {
  968. vxge_assert(vdev->vpaths[i].is_open);
  969. status = vxge_hw_vpath_mcast_disable(
  970. vdev->vpaths[i].handle);
  971. vdev->all_multi_flg = 1;
  972. }
  973. }
  974. if (status != VXGE_HW_OK)
  975. vxge_debug_init(VXGE_ERR,
  976. "failed to %s multicast, status %d",
  977. dev->flags & IFF_ALLMULTI ?
  978. "enable" : "disable", status);
  979. if (!vdev->config.addr_learn_en) {
  980. if (dev->flags & IFF_PROMISC) {
  981. for (i = 0; i < vdev->no_of_vpath; i++) {
  982. vxge_assert(vdev->vpaths[i].is_open);
  983. status = vxge_hw_vpath_promisc_enable(
  984. vdev->vpaths[i].handle);
  985. }
  986. } else {
  987. for (i = 0; i < vdev->no_of_vpath; i++) {
  988. vxge_assert(vdev->vpaths[i].is_open);
  989. status = vxge_hw_vpath_promisc_disable(
  990. vdev->vpaths[i].handle);
  991. }
  992. }
  993. }
  994. memset(&mac_info, 0, sizeof(struct macInfo));
  995. /* Update individual M_CAST address list */
  996. if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
  997. mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
  998. list_head = &vdev->vpaths[0].mac_addr_list;
  999. if ((netdev_mc_count(dev) +
  1000. (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
  1001. vdev->vpaths[0].max_mac_addr_cnt)
  1002. goto _set_all_mcast;
  1003. /* Delete previous MC's */
  1004. for (i = 0; i < mcast_cnt; i++) {
  1005. if (!list_empty(list_head))
  1006. mac_entry = (struct vxge_mac_addrs *)
  1007. list_first_entry(list_head,
  1008. struct vxge_mac_addrs,
  1009. item);
  1010. list_for_each_safe(entry, next, list_head) {
  1011. mac_entry = (struct vxge_mac_addrs *) entry;
  1012. /* Copy the mac address to delete */
  1013. mac_address = (u8 *)&mac_entry->macaddr;
  1014. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1015. /* Is this a multicast address */
  1016. if (0x01 & mac_info.macaddr[0]) {
  1017. for (vpath_idx = 0; vpath_idx <
  1018. vdev->no_of_vpath;
  1019. vpath_idx++) {
  1020. mac_info.vpath_no = vpath_idx;
  1021. status = vxge_del_mac_addr(
  1022. vdev,
  1023. &mac_info);
  1024. }
  1025. }
  1026. }
  1027. }
  1028. /* Add new ones */
  1029. netdev_for_each_mc_addr(mclist, dev) {
  1030. memcpy(mac_info.macaddr, mclist->dmi_addr, ETH_ALEN);
  1031. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
  1032. vpath_idx++) {
  1033. mac_info.vpath_no = vpath_idx;
  1034. mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1035. status = vxge_add_mac_addr(vdev, &mac_info);
  1036. if (status != VXGE_HW_OK) {
  1037. vxge_debug_init(VXGE_ERR,
  1038. "%s:%d Setting individual"
  1039. "multicast address failed",
  1040. __func__, __LINE__);
  1041. goto _set_all_mcast;
  1042. }
  1043. }
  1044. }
  1045. return;
  1046. _set_all_mcast:
  1047. mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
  1048. /* Delete previous MC's */
  1049. for (i = 0; i < mcast_cnt; i++) {
  1050. list_for_each_safe(entry, next, list_head) {
  1051. mac_entry = (struct vxge_mac_addrs *) entry;
  1052. /* Copy the mac address to delete */
  1053. mac_address = (u8 *)&mac_entry->macaddr;
  1054. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1055. /* Is this a multicast address */
  1056. if (0x01 & mac_info.macaddr[0])
  1057. break;
  1058. }
  1059. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
  1060. vpath_idx++) {
  1061. mac_info.vpath_no = vpath_idx;
  1062. status = vxge_del_mac_addr(vdev, &mac_info);
  1063. }
  1064. }
  1065. /* Enable all multicast */
  1066. for (i = 0; i < vdev->no_of_vpath; i++) {
  1067. vxge_assert(vdev->vpaths[i].is_open);
  1068. status = vxge_hw_vpath_mcast_enable(
  1069. vdev->vpaths[i].handle);
  1070. if (status != VXGE_HW_OK) {
  1071. vxge_debug_init(VXGE_ERR,
  1072. "%s:%d Enabling all multicasts failed",
  1073. __func__, __LINE__);
  1074. }
  1075. vdev->all_multi_flg = 1;
  1076. }
  1077. dev->flags |= IFF_ALLMULTI;
  1078. }
  1079. vxge_debug_entryexit(VXGE_TRACE,
  1080. "%s:%d Exiting...", __func__, __LINE__);
  1081. }
  1082. /**
  1083. * vxge_set_mac_addr
  1084. * @dev: pointer to the device structure
  1085. *
  1086. * Update entry "0" (default MAC addr)
  1087. */
  1088. static int vxge_set_mac_addr(struct net_device *dev, void *p)
  1089. {
  1090. struct sockaddr *addr = p;
  1091. struct vxgedev *vdev;
  1092. struct __vxge_hw_device *hldev;
  1093. enum vxge_hw_status status = VXGE_HW_OK;
  1094. struct macInfo mac_info_new, mac_info_old;
  1095. int vpath_idx = 0;
  1096. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1097. vdev = (struct vxgedev *)netdev_priv(dev);
  1098. hldev = vdev->devh;
  1099. if (!is_valid_ether_addr(addr->sa_data))
  1100. return -EINVAL;
  1101. memset(&mac_info_new, 0, sizeof(struct macInfo));
  1102. memset(&mac_info_old, 0, sizeof(struct macInfo));
  1103. vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
  1104. __func__, __LINE__);
  1105. /* Get the old address */
  1106. memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
  1107. /* Copy the new address */
  1108. memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
  1109. /* First delete the old mac address from all the vpaths
  1110. as we can't specify the index while adding new mac address */
  1111. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  1112. struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
  1113. if (!vpath->is_open) {
  1114. /* This can happen when this interface is added/removed
  1115. to the bonding interface. Delete this station address
  1116. from the linked list */
  1117. vxge_mac_list_del(vpath, &mac_info_old);
  1118. /* Add this new address to the linked list
  1119. for later restoring */
  1120. vxge_mac_list_add(vpath, &mac_info_new);
  1121. continue;
  1122. }
  1123. /* Delete the station address */
  1124. mac_info_old.vpath_no = vpath_idx;
  1125. status = vxge_del_mac_addr(vdev, &mac_info_old);
  1126. }
  1127. if (unlikely(!is_vxge_card_up(vdev))) {
  1128. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1129. return VXGE_HW_OK;
  1130. }
  1131. /* Set this mac address to all the vpaths */
  1132. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
  1133. mac_info_new.vpath_no = vpath_idx;
  1134. mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1135. status = vxge_add_mac_addr(vdev, &mac_info_new);
  1136. if (status != VXGE_HW_OK)
  1137. return -EINVAL;
  1138. }
  1139. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  1140. return status;
  1141. }
  1142. /*
  1143. * vxge_vpath_intr_enable
  1144. * @vdev: pointer to vdev
  1145. * @vp_id: vpath for which to enable the interrupts
  1146. *
  1147. * Enables the interrupts for the vpath
  1148. */
  1149. void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
  1150. {
  1151. struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
  1152. int msix_id, alarm_msix_id;
  1153. int tim_msix_id[4] = {[0 ...3] = 0};
  1154. vxge_hw_vpath_intr_enable(vpath->handle);
  1155. if (vdev->config.intr_type == INTA)
  1156. vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
  1157. else {
  1158. msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
  1159. alarm_msix_id =
  1160. VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
  1161. tim_msix_id[0] = msix_id;
  1162. tim_msix_id[1] = msix_id + 1;
  1163. vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
  1164. alarm_msix_id);
  1165. vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
  1166. vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
  1167. /* enable the alarm vector */
  1168. vxge_hw_vpath_msix_unmask(vpath->handle, alarm_msix_id);
  1169. }
  1170. }
  1171. /*
  1172. * vxge_vpath_intr_disable
  1173. * @vdev: pointer to vdev
  1174. * @vp_id: vpath for which to disable the interrupts
  1175. *
  1176. * Disables the interrupts for the vpath
  1177. */
  1178. void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
  1179. {
  1180. struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
  1181. int msix_id;
  1182. vxge_hw_vpath_intr_disable(vpath->handle);
  1183. if (vdev->config.intr_type == INTA)
  1184. vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
  1185. else {
  1186. msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
  1187. vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
  1188. vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
  1189. /* disable the alarm vector */
  1190. msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
  1191. vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
  1192. }
  1193. }
  1194. /*
  1195. * vxge_reset_vpath
  1196. * @vdev: pointer to vdev
  1197. * @vp_id: vpath to reset
  1198. *
  1199. * Resets the vpath
  1200. */
  1201. static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
  1202. {
  1203. enum vxge_hw_status status = VXGE_HW_OK;
  1204. int ret = 0;
  1205. /* check if device is down already */
  1206. if (unlikely(!is_vxge_card_up(vdev)))
  1207. return 0;
  1208. /* is device reset already scheduled */
  1209. if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  1210. return 0;
  1211. if (vdev->vpaths[vp_id].handle) {
  1212. if (vxge_hw_vpath_reset(vdev->vpaths[vp_id].handle)
  1213. == VXGE_HW_OK) {
  1214. if (is_vxge_card_up(vdev) &&
  1215. vxge_hw_vpath_recover_from_reset(
  1216. vdev->vpaths[vp_id].handle)
  1217. != VXGE_HW_OK) {
  1218. vxge_debug_init(VXGE_ERR,
  1219. "vxge_hw_vpath_recover_from_reset"
  1220. "failed for vpath:%d", vp_id);
  1221. return status;
  1222. }
  1223. } else {
  1224. vxge_debug_init(VXGE_ERR,
  1225. "vxge_hw_vpath_reset failed for"
  1226. "vpath:%d", vp_id);
  1227. return status;
  1228. }
  1229. } else
  1230. return VXGE_HW_FAIL;
  1231. vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
  1232. vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
  1233. /* Enable all broadcast */
  1234. vxge_hw_vpath_bcast_enable(vdev->vpaths[vp_id].handle);
  1235. /* Enable the interrupts */
  1236. vxge_vpath_intr_enable(vdev, vp_id);
  1237. smp_wmb();
  1238. /* Enable the flow of traffic through the vpath */
  1239. vxge_hw_vpath_enable(vdev->vpaths[vp_id].handle);
  1240. smp_wmb();
  1241. vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[vp_id].handle);
  1242. vdev->vpaths[vp_id].ring.last_status = VXGE_HW_OK;
  1243. /* Vpath reset done */
  1244. clear_bit(vp_id, &vdev->vp_reset);
  1245. /* Start the vpath queue */
  1246. vxge_wake_tx_queue(&vdev->vpaths[vp_id].fifo, NULL);
  1247. return ret;
  1248. }
  1249. static int do_vxge_reset(struct vxgedev *vdev, int event)
  1250. {
  1251. enum vxge_hw_status status;
  1252. int ret = 0, vp_id, i;
  1253. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1254. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
  1255. /* check if device is down already */
  1256. if (unlikely(!is_vxge_card_up(vdev)))
  1257. return 0;
  1258. /* is reset already scheduled */
  1259. if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  1260. return 0;
  1261. }
  1262. if (event == VXGE_LL_FULL_RESET) {
  1263. /* wait for all the vpath reset to complete */
  1264. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  1265. while (test_bit(vp_id, &vdev->vp_reset))
  1266. msleep(50);
  1267. }
  1268. /* if execution mode is set to debug, don't reset the adapter */
  1269. if (unlikely(vdev->exec_mode)) {
  1270. vxge_debug_init(VXGE_ERR,
  1271. "%s: execution mode is debug, returning..",
  1272. vdev->ndev->name);
  1273. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  1274. vxge_stop_all_tx_queue(vdev);
  1275. return 0;
  1276. }
  1277. }
  1278. if (event == VXGE_LL_FULL_RESET) {
  1279. vxge_hw_device_intr_disable(vdev->devh);
  1280. switch (vdev->cric_err_event) {
  1281. case VXGE_HW_EVENT_UNKNOWN:
  1282. vxge_stop_all_tx_queue(vdev);
  1283. vxge_debug_init(VXGE_ERR,
  1284. "fatal: %s: Disabling device due to"
  1285. "unknown error",
  1286. vdev->ndev->name);
  1287. ret = -EPERM;
  1288. goto out;
  1289. case VXGE_HW_EVENT_RESET_START:
  1290. break;
  1291. case VXGE_HW_EVENT_RESET_COMPLETE:
  1292. case VXGE_HW_EVENT_LINK_DOWN:
  1293. case VXGE_HW_EVENT_LINK_UP:
  1294. case VXGE_HW_EVENT_ALARM_CLEARED:
  1295. case VXGE_HW_EVENT_ECCERR:
  1296. case VXGE_HW_EVENT_MRPCIM_ECCERR:
  1297. ret = -EPERM;
  1298. goto out;
  1299. case VXGE_HW_EVENT_FIFO_ERR:
  1300. case VXGE_HW_EVENT_VPATH_ERR:
  1301. break;
  1302. case VXGE_HW_EVENT_CRITICAL_ERR:
  1303. vxge_stop_all_tx_queue(vdev);
  1304. vxge_debug_init(VXGE_ERR,
  1305. "fatal: %s: Disabling device due to"
  1306. "serious error",
  1307. vdev->ndev->name);
  1308. /* SOP or device reset required */
  1309. /* This event is not currently used */
  1310. ret = -EPERM;
  1311. goto out;
  1312. case VXGE_HW_EVENT_SERR:
  1313. vxge_stop_all_tx_queue(vdev);
  1314. vxge_debug_init(VXGE_ERR,
  1315. "fatal: %s: Disabling device due to"
  1316. "serious error",
  1317. vdev->ndev->name);
  1318. ret = -EPERM;
  1319. goto out;
  1320. case VXGE_HW_EVENT_SRPCIM_SERR:
  1321. case VXGE_HW_EVENT_MRPCIM_SERR:
  1322. ret = -EPERM;
  1323. goto out;
  1324. case VXGE_HW_EVENT_SLOT_FREEZE:
  1325. vxge_stop_all_tx_queue(vdev);
  1326. vxge_debug_init(VXGE_ERR,
  1327. "fatal: %s: Disabling device due to"
  1328. "slot freeze",
  1329. vdev->ndev->name);
  1330. ret = -EPERM;
  1331. goto out;
  1332. default:
  1333. break;
  1334. }
  1335. }
  1336. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
  1337. vxge_stop_all_tx_queue(vdev);
  1338. if (event == VXGE_LL_FULL_RESET) {
  1339. status = vxge_reset_all_vpaths(vdev);
  1340. if (status != VXGE_HW_OK) {
  1341. vxge_debug_init(VXGE_ERR,
  1342. "fatal: %s: can not reset vpaths",
  1343. vdev->ndev->name);
  1344. ret = -EPERM;
  1345. goto out;
  1346. }
  1347. }
  1348. if (event == VXGE_LL_COMPL_RESET) {
  1349. for (i = 0; i < vdev->no_of_vpath; i++)
  1350. if (vdev->vpaths[i].handle) {
  1351. if (vxge_hw_vpath_recover_from_reset(
  1352. vdev->vpaths[i].handle)
  1353. != VXGE_HW_OK) {
  1354. vxge_debug_init(VXGE_ERR,
  1355. "vxge_hw_vpath_recover_"
  1356. "from_reset failed for vpath: "
  1357. "%d", i);
  1358. ret = -EPERM;
  1359. goto out;
  1360. }
  1361. } else {
  1362. vxge_debug_init(VXGE_ERR,
  1363. "vxge_hw_vpath_reset failed for "
  1364. "vpath:%d", i);
  1365. ret = -EPERM;
  1366. goto out;
  1367. }
  1368. }
  1369. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
  1370. /* Reprogram the DA table with populated mac addresses */
  1371. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  1372. vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
  1373. vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
  1374. }
  1375. /* enable vpath interrupts */
  1376. for (i = 0; i < vdev->no_of_vpath; i++)
  1377. vxge_vpath_intr_enable(vdev, i);
  1378. vxge_hw_device_intr_enable(vdev->devh);
  1379. smp_wmb();
  1380. /* Indicate card up */
  1381. set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  1382. /* Get the traffic to flow through the vpaths */
  1383. for (i = 0; i < vdev->no_of_vpath; i++) {
  1384. vxge_hw_vpath_enable(vdev->vpaths[i].handle);
  1385. smp_wmb();
  1386. vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
  1387. }
  1388. vxge_wake_all_tx_queue(vdev);
  1389. }
  1390. out:
  1391. vxge_debug_entryexit(VXGE_TRACE,
  1392. "%s:%d Exiting...", __func__, __LINE__);
  1393. /* Indicate reset done */
  1394. if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
  1395. clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
  1396. return ret;
  1397. }
  1398. /*
  1399. * vxge_reset
  1400. * @vdev: pointer to ll device
  1401. *
  1402. * driver may reset the chip on events of serr, eccerr, etc
  1403. */
  1404. int vxge_reset(struct vxgedev *vdev)
  1405. {
  1406. do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
  1407. return 0;
  1408. }
  1409. /**
  1410. * vxge_poll - Receive handler when Receive Polling is used.
  1411. * @dev: pointer to the device structure.
  1412. * @budget: Number of packets budgeted to be processed in this iteration.
  1413. *
  1414. * This function comes into picture only if Receive side is being handled
  1415. * through polling (called NAPI in linux). It mostly does what the normal
  1416. * Rx interrupt handler does in terms of descriptor and packet processing
  1417. * but not in an interrupt context. Also it will process a specified number
  1418. * of packets at most in one iteration. This value is passed down by the
  1419. * kernel as the function argument 'budget'.
  1420. */
  1421. static int vxge_poll_msix(struct napi_struct *napi, int budget)
  1422. {
  1423. struct vxge_ring *ring =
  1424. container_of(napi, struct vxge_ring, napi);
  1425. int budget_org = budget;
  1426. ring->budget = budget;
  1427. vxge_hw_vpath_poll_rx(ring->handle);
  1428. if (ring->pkts_processed < budget_org) {
  1429. napi_complete(napi);
  1430. /* Re enable the Rx interrupts for the vpath */
  1431. vxge_hw_channel_msix_unmask(
  1432. (struct __vxge_hw_channel *)ring->handle,
  1433. ring->rx_vector_no);
  1434. }
  1435. return ring->pkts_processed;
  1436. }
  1437. static int vxge_poll_inta(struct napi_struct *napi, int budget)
  1438. {
  1439. struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
  1440. int pkts_processed = 0;
  1441. int i;
  1442. int budget_org = budget;
  1443. struct vxge_ring *ring;
  1444. struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
  1445. pci_get_drvdata(vdev->pdev);
  1446. for (i = 0; i < vdev->no_of_vpath; i++) {
  1447. ring = &vdev->vpaths[i].ring;
  1448. ring->budget = budget;
  1449. vxge_hw_vpath_poll_rx(ring->handle);
  1450. pkts_processed += ring->pkts_processed;
  1451. budget -= ring->pkts_processed;
  1452. if (budget <= 0)
  1453. break;
  1454. }
  1455. VXGE_COMPLETE_ALL_TX(vdev);
  1456. if (pkts_processed < budget_org) {
  1457. napi_complete(napi);
  1458. /* Re enable the Rx interrupts for the ring */
  1459. vxge_hw_device_unmask_all(hldev);
  1460. vxge_hw_device_flush_io(hldev);
  1461. }
  1462. return pkts_processed;
  1463. }
  1464. #ifdef CONFIG_NET_POLL_CONTROLLER
  1465. /**
  1466. * vxge_netpoll - netpoll event handler entry point
  1467. * @dev : pointer to the device structure.
  1468. * Description:
  1469. * This function will be called by upper layer to check for events on the
  1470. * interface in situations where interrupts are disabled. It is used for
  1471. * specific in-kernel networking tasks, such as remote consoles and kernel
  1472. * debugging over the network (example netdump in RedHat).
  1473. */
  1474. static void vxge_netpoll(struct net_device *dev)
  1475. {
  1476. struct __vxge_hw_device *hldev;
  1477. struct vxgedev *vdev;
  1478. vdev = (struct vxgedev *)netdev_priv(dev);
  1479. hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
  1480. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1481. if (pci_channel_offline(vdev->pdev))
  1482. return;
  1483. disable_irq(dev->irq);
  1484. vxge_hw_device_clear_tx_rx(hldev);
  1485. vxge_hw_device_clear_tx_rx(hldev);
  1486. VXGE_COMPLETE_ALL_RX(vdev);
  1487. VXGE_COMPLETE_ALL_TX(vdev);
  1488. enable_irq(dev->irq);
  1489. vxge_debug_entryexit(VXGE_TRACE,
  1490. "%s:%d Exiting...", __func__, __LINE__);
  1491. return;
  1492. }
  1493. #endif
  1494. /* RTH configuration */
  1495. static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
  1496. {
  1497. enum vxge_hw_status status = VXGE_HW_OK;
  1498. struct vxge_hw_rth_hash_types hash_types;
  1499. u8 itable[256] = {0}; /* indirection table */
  1500. u8 mtable[256] = {0}; /* CPU to vpath mapping */
  1501. int index;
  1502. /*
  1503. * Filling
  1504. * - itable with bucket numbers
  1505. * - mtable with bucket-to-vpath mapping
  1506. */
  1507. for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
  1508. itable[index] = index;
  1509. mtable[index] = index % vdev->no_of_vpath;
  1510. }
  1511. /* Fill RTH hash types */
  1512. hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
  1513. hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
  1514. hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
  1515. hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
  1516. hash_types.hash_type_tcpipv6ex_en =
  1517. vdev->config.rth_hash_type_tcpipv6ex;
  1518. hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
  1519. /* set indirection table, bucket-to-vpath mapping */
  1520. status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
  1521. vdev->no_of_vpath,
  1522. mtable, itable,
  1523. vdev->config.rth_bkt_sz);
  1524. if (status != VXGE_HW_OK) {
  1525. vxge_debug_init(VXGE_ERR,
  1526. "RTH indirection table configuration failed "
  1527. "for vpath:%d", vdev->vpaths[0].device_id);
  1528. return status;
  1529. }
  1530. /*
  1531. * Because the itable_set() method uses the active_table field
  1532. * for the target virtual path the RTH config should be updated
  1533. * for all VPATHs. The h/w only uses the lowest numbered VPATH
  1534. * when steering frames.
  1535. */
  1536. for (index = 0; index < vdev->no_of_vpath; index++) {
  1537. status = vxge_hw_vpath_rts_rth_set(
  1538. vdev->vpaths[index].handle,
  1539. vdev->config.rth_algorithm,
  1540. &hash_types,
  1541. vdev->config.rth_bkt_sz);
  1542. if (status != VXGE_HW_OK) {
  1543. vxge_debug_init(VXGE_ERR,
  1544. "RTH configuration failed for vpath:%d",
  1545. vdev->vpaths[index].device_id);
  1546. return status;
  1547. }
  1548. }
  1549. return status;
  1550. }
  1551. int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
  1552. {
  1553. struct vxge_mac_addrs *new_mac_entry;
  1554. u8 *mac_address = NULL;
  1555. if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
  1556. return TRUE;
  1557. new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
  1558. if (!new_mac_entry) {
  1559. vxge_debug_mem(VXGE_ERR,
  1560. "%s: memory allocation failed",
  1561. VXGE_DRIVER_NAME);
  1562. return FALSE;
  1563. }
  1564. list_add(&new_mac_entry->item, &vpath->mac_addr_list);
  1565. /* Copy the new mac address to the list */
  1566. mac_address = (u8 *)&new_mac_entry->macaddr;
  1567. memcpy(mac_address, mac->macaddr, ETH_ALEN);
  1568. new_mac_entry->state = mac->state;
  1569. vpath->mac_addr_cnt++;
  1570. /* Is this a multicast address */
  1571. if (0x01 & mac->macaddr[0])
  1572. vpath->mcast_addr_cnt++;
  1573. return TRUE;
  1574. }
  1575. /* Add a mac address to DA table */
  1576. enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
  1577. {
  1578. enum vxge_hw_status status = VXGE_HW_OK;
  1579. struct vxge_vpath *vpath;
  1580. enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
  1581. if (0x01 & mac->macaddr[0]) /* multicast address */
  1582. duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
  1583. else
  1584. duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
  1585. vpath = &vdev->vpaths[mac->vpath_no];
  1586. status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
  1587. mac->macmask, duplicate_mode);
  1588. if (status != VXGE_HW_OK) {
  1589. vxge_debug_init(VXGE_ERR,
  1590. "DA config add entry failed for vpath:%d",
  1591. vpath->device_id);
  1592. } else
  1593. if (FALSE == vxge_mac_list_add(vpath, mac))
  1594. status = -EPERM;
  1595. return status;
  1596. }
  1597. int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
  1598. {
  1599. struct list_head *entry, *next;
  1600. u64 del_mac = 0;
  1601. u8 *mac_address = (u8 *) (&del_mac);
  1602. /* Copy the mac address to delete from the list */
  1603. memcpy(mac_address, mac->macaddr, ETH_ALEN);
  1604. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  1605. if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
  1606. list_del(entry);
  1607. kfree((struct vxge_mac_addrs *)entry);
  1608. vpath->mac_addr_cnt--;
  1609. /* Is this a multicast address */
  1610. if (0x01 & mac->macaddr[0])
  1611. vpath->mcast_addr_cnt--;
  1612. return TRUE;
  1613. }
  1614. }
  1615. return FALSE;
  1616. }
  1617. /* delete a mac address from DA table */
  1618. enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
  1619. {
  1620. enum vxge_hw_status status = VXGE_HW_OK;
  1621. struct vxge_vpath *vpath;
  1622. vpath = &vdev->vpaths[mac->vpath_no];
  1623. status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
  1624. mac->macmask);
  1625. if (status != VXGE_HW_OK) {
  1626. vxge_debug_init(VXGE_ERR,
  1627. "DA config delete entry failed for vpath:%d",
  1628. vpath->device_id);
  1629. } else
  1630. vxge_mac_list_del(vpath, mac);
  1631. return status;
  1632. }
  1633. /* list all mac addresses from DA table */
  1634. enum vxge_hw_status
  1635. static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
  1636. struct macInfo *mac)
  1637. {
  1638. enum vxge_hw_status status = VXGE_HW_OK;
  1639. unsigned char macmask[ETH_ALEN];
  1640. unsigned char macaddr[ETH_ALEN];
  1641. status = vxge_hw_vpath_mac_addr_get(vpath->handle,
  1642. macaddr, macmask);
  1643. if (status != VXGE_HW_OK) {
  1644. vxge_debug_init(VXGE_ERR,
  1645. "DA config list entry failed for vpath:%d",
  1646. vpath->device_id);
  1647. return status;
  1648. }
  1649. while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
  1650. status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
  1651. macaddr, macmask);
  1652. if (status != VXGE_HW_OK)
  1653. break;
  1654. }
  1655. return status;
  1656. }
  1657. /* Store all vlan ids from the list to the vid table */
  1658. enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
  1659. {
  1660. enum vxge_hw_status status = VXGE_HW_OK;
  1661. struct vxgedev *vdev = vpath->vdev;
  1662. u16 vid;
  1663. if (vdev->vlgrp && vpath->is_open) {
  1664. for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
  1665. if (!vlan_group_get_device(vdev->vlgrp, vid))
  1666. continue;
  1667. /* Add these vlan to the vid table */
  1668. status = vxge_hw_vpath_vid_add(vpath->handle, vid);
  1669. }
  1670. }
  1671. return status;
  1672. }
  1673. /* Store all mac addresses from the list to the DA table */
  1674. enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
  1675. {
  1676. enum vxge_hw_status status = VXGE_HW_OK;
  1677. struct macInfo mac_info;
  1678. u8 *mac_address = NULL;
  1679. struct list_head *entry, *next;
  1680. memset(&mac_info, 0, sizeof(struct macInfo));
  1681. if (vpath->is_open) {
  1682. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  1683. mac_address =
  1684. (u8 *)&
  1685. ((struct vxge_mac_addrs *)entry)->macaddr;
  1686. memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
  1687. ((struct vxge_mac_addrs *)entry)->state =
  1688. VXGE_LL_MAC_ADDR_IN_DA_TABLE;
  1689. /* does this mac address already exist in da table? */
  1690. status = vxge_search_mac_addr_in_da_table(vpath,
  1691. &mac_info);
  1692. if (status != VXGE_HW_OK) {
  1693. /* Add this mac address to the DA table */
  1694. status = vxge_hw_vpath_mac_addr_add(
  1695. vpath->handle, mac_info.macaddr,
  1696. mac_info.macmask,
  1697. VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
  1698. if (status != VXGE_HW_OK) {
  1699. vxge_debug_init(VXGE_ERR,
  1700. "DA add entry failed for vpath:%d",
  1701. vpath->device_id);
  1702. ((struct vxge_mac_addrs *)entry)->state
  1703. = VXGE_LL_MAC_ADDR_IN_LIST;
  1704. }
  1705. }
  1706. }
  1707. }
  1708. return status;
  1709. }
  1710. /* reset vpaths */
  1711. enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
  1712. {
  1713. int i;
  1714. enum vxge_hw_status status = VXGE_HW_OK;
  1715. for (i = 0; i < vdev->no_of_vpath; i++)
  1716. if (vdev->vpaths[i].handle) {
  1717. if (vxge_hw_vpath_reset(vdev->vpaths[i].handle)
  1718. == VXGE_HW_OK) {
  1719. if (is_vxge_card_up(vdev) &&
  1720. vxge_hw_vpath_recover_from_reset(
  1721. vdev->vpaths[i].handle)
  1722. != VXGE_HW_OK) {
  1723. vxge_debug_init(VXGE_ERR,
  1724. "vxge_hw_vpath_recover_"
  1725. "from_reset failed for vpath: "
  1726. "%d", i);
  1727. return status;
  1728. }
  1729. } else {
  1730. vxge_debug_init(VXGE_ERR,
  1731. "vxge_hw_vpath_reset failed for "
  1732. "vpath:%d", i);
  1733. return status;
  1734. }
  1735. }
  1736. return status;
  1737. }
  1738. /* close vpaths */
  1739. void vxge_close_vpaths(struct vxgedev *vdev, int index)
  1740. {
  1741. int i;
  1742. for (i = index; i < vdev->no_of_vpath; i++) {
  1743. if (vdev->vpaths[i].handle && vdev->vpaths[i].is_open) {
  1744. vxge_hw_vpath_close(vdev->vpaths[i].handle);
  1745. vdev->stats.vpaths_open--;
  1746. }
  1747. vdev->vpaths[i].is_open = 0;
  1748. vdev->vpaths[i].handle = NULL;
  1749. }
  1750. }
  1751. /* open vpaths */
  1752. int vxge_open_vpaths(struct vxgedev *vdev)
  1753. {
  1754. enum vxge_hw_status status;
  1755. int i;
  1756. u32 vp_id = 0;
  1757. struct vxge_hw_vpath_attr attr;
  1758. for (i = 0; i < vdev->no_of_vpath; i++) {
  1759. vxge_assert(vdev->vpaths[i].is_configured);
  1760. attr.vp_id = vdev->vpaths[i].device_id;
  1761. attr.fifo_attr.callback = vxge_xmit_compl;
  1762. attr.fifo_attr.txdl_term = vxge_tx_term;
  1763. attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
  1764. attr.fifo_attr.userdata = (void *)&vdev->vpaths[i].fifo;
  1765. attr.ring_attr.callback = vxge_rx_1b_compl;
  1766. attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
  1767. attr.ring_attr.rxd_term = vxge_rx_term;
  1768. attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
  1769. attr.ring_attr.userdata = (void *)&vdev->vpaths[i].ring;
  1770. vdev->vpaths[i].ring.ndev = vdev->ndev;
  1771. vdev->vpaths[i].ring.pdev = vdev->pdev;
  1772. status = vxge_hw_vpath_open(vdev->devh, &attr,
  1773. &(vdev->vpaths[i].handle));
  1774. if (status == VXGE_HW_OK) {
  1775. vdev->vpaths[i].fifo.handle =
  1776. (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
  1777. vdev->vpaths[i].ring.handle =
  1778. (struct __vxge_hw_ring *)attr.ring_attr.userdata;
  1779. vdev->vpaths[i].fifo.tx_steering_type =
  1780. vdev->config.tx_steering_type;
  1781. vdev->vpaths[i].fifo.ndev = vdev->ndev;
  1782. vdev->vpaths[i].fifo.pdev = vdev->pdev;
  1783. vdev->vpaths[i].fifo.indicate_max_pkts =
  1784. vdev->config.fifo_indicate_max_pkts;
  1785. vdev->vpaths[i].ring.rx_vector_no = 0;
  1786. vdev->vpaths[i].ring.rx_csum = vdev->rx_csum;
  1787. vdev->vpaths[i].is_open = 1;
  1788. vdev->vp_handles[i] = vdev->vpaths[i].handle;
  1789. vdev->vpaths[i].ring.gro_enable =
  1790. vdev->config.gro_enable;
  1791. vdev->vpaths[i].ring.vlan_tag_strip =
  1792. vdev->vlan_tag_strip;
  1793. vdev->stats.vpaths_open++;
  1794. } else {
  1795. vdev->stats.vpath_open_fail++;
  1796. vxge_debug_init(VXGE_ERR,
  1797. "%s: vpath: %d failed to open "
  1798. "with status: %d",
  1799. vdev->ndev->name, vdev->vpaths[i].device_id,
  1800. status);
  1801. vxge_close_vpaths(vdev, 0);
  1802. return -EPERM;
  1803. }
  1804. vp_id =
  1805. ((struct __vxge_hw_vpath_handle *)vdev->vpaths[i].handle)->
  1806. vpath->vp_id;
  1807. vdev->vpaths_deployed |= vxge_mBIT(vp_id);
  1808. }
  1809. return VXGE_HW_OK;
  1810. }
  1811. /*
  1812. * vxge_isr_napi
  1813. * @irq: the irq of the device.
  1814. * @dev_id: a void pointer to the hldev structure of the Titan device
  1815. * @ptregs: pointer to the registers pushed on the stack.
  1816. *
  1817. * This function is the ISR handler of the device when napi is enabled. It
  1818. * identifies the reason for the interrupt and calls the relevant service
  1819. * routines.
  1820. */
  1821. static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
  1822. {
  1823. struct net_device *dev;
  1824. struct __vxge_hw_device *hldev;
  1825. u64 reason;
  1826. enum vxge_hw_status status;
  1827. struct vxgedev *vdev = (struct vxgedev *) dev_id;;
  1828. vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  1829. dev = vdev->ndev;
  1830. hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
  1831. if (pci_channel_offline(vdev->pdev))
  1832. return IRQ_NONE;
  1833. if (unlikely(!is_vxge_card_up(vdev)))
  1834. return IRQ_NONE;
  1835. status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
  1836. &reason);
  1837. if (status == VXGE_HW_OK) {
  1838. vxge_hw_device_mask_all(hldev);
  1839. if (reason &
  1840. VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
  1841. vdev->vpaths_deployed >>
  1842. (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
  1843. vxge_hw_device_clear_tx_rx(hldev);
  1844. napi_schedule(&vdev->napi);
  1845. vxge_debug_intr(VXGE_TRACE,
  1846. "%s:%d Exiting...", __func__, __LINE__);
  1847. return IRQ_HANDLED;
  1848. } else
  1849. vxge_hw_device_unmask_all(hldev);
  1850. } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
  1851. (status == VXGE_HW_ERR_CRITICAL) ||
  1852. (status == VXGE_HW_ERR_FIFO))) {
  1853. vxge_hw_device_mask_all(hldev);
  1854. vxge_hw_device_flush_io(hldev);
  1855. return IRQ_HANDLED;
  1856. } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
  1857. return IRQ_HANDLED;
  1858. vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
  1859. return IRQ_NONE;
  1860. }
  1861. #ifdef CONFIG_PCI_MSI
  1862. static irqreturn_t
  1863. vxge_tx_msix_handle(int irq, void *dev_id)
  1864. {
  1865. struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
  1866. VXGE_COMPLETE_VPATH_TX(fifo);
  1867. return IRQ_HANDLED;
  1868. }
  1869. static irqreturn_t
  1870. vxge_rx_msix_napi_handle(int irq, void *dev_id)
  1871. {
  1872. struct vxge_ring *ring = (struct vxge_ring *)dev_id;
  1873. /* MSIX_IDX for Rx is 1 */
  1874. vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
  1875. ring->rx_vector_no);
  1876. napi_schedule(&ring->napi);
  1877. return IRQ_HANDLED;
  1878. }
  1879. static irqreturn_t
  1880. vxge_alarm_msix_handle(int irq, void *dev_id)
  1881. {
  1882. int i;
  1883. enum vxge_hw_status status;
  1884. struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
  1885. struct vxgedev *vdev = vpath->vdev;
  1886. int alarm_msix_id =
  1887. VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
  1888. for (i = 0; i < vdev->no_of_vpath; i++) {
  1889. vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle,
  1890. alarm_msix_id);
  1891. status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
  1892. vdev->exec_mode);
  1893. if (status == VXGE_HW_OK) {
  1894. vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
  1895. alarm_msix_id);
  1896. continue;
  1897. }
  1898. vxge_debug_intr(VXGE_ERR,
  1899. "%s: vxge_hw_vpath_alarm_process failed %x ",
  1900. VXGE_DRIVER_NAME, status);
  1901. }
  1902. return IRQ_HANDLED;
  1903. }
  1904. static int vxge_alloc_msix(struct vxgedev *vdev)
  1905. {
  1906. int j, i, ret = 0;
  1907. int intr_cnt = 0;
  1908. int alarm_msix_id = 0, msix_intr_vect = 0;
  1909. vdev->intr_cnt = 0;
  1910. /* Tx/Rx MSIX Vectors count */
  1911. vdev->intr_cnt = vdev->no_of_vpath * 2;
  1912. /* Alarm MSIX Vectors count */
  1913. vdev->intr_cnt++;
  1914. intr_cnt = (vdev->max_vpath_supported * 2) + 1;
  1915. vdev->entries = kzalloc(intr_cnt * sizeof(struct msix_entry),
  1916. GFP_KERNEL);
  1917. if (!vdev->entries) {
  1918. vxge_debug_init(VXGE_ERR,
  1919. "%s: memory allocation failed",
  1920. VXGE_DRIVER_NAME);
  1921. return -ENOMEM;
  1922. }
  1923. vdev->vxge_entries = kzalloc(intr_cnt * sizeof(struct vxge_msix_entry),
  1924. GFP_KERNEL);
  1925. if (!vdev->vxge_entries) {
  1926. vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
  1927. VXGE_DRIVER_NAME);
  1928. kfree(vdev->entries);
  1929. return -ENOMEM;
  1930. }
  1931. /* Last vector in the list is used for alarm */
  1932. alarm_msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
  1933. for (i = 0, j = 0; i < vdev->max_vpath_supported; i++) {
  1934. msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
  1935. /* Initialize the fifo vector */
  1936. vdev->entries[j].entry = msix_intr_vect;
  1937. vdev->vxge_entries[j].entry = msix_intr_vect;
  1938. vdev->vxge_entries[j].in_use = 0;
  1939. j++;
  1940. /* Initialize the ring vector */
  1941. vdev->entries[j].entry = msix_intr_vect + 1;
  1942. vdev->vxge_entries[j].entry = msix_intr_vect + 1;
  1943. vdev->vxge_entries[j].in_use = 0;
  1944. j++;
  1945. }
  1946. /* Initialize the alarm vector */
  1947. vdev->entries[j].entry = alarm_msix_id;
  1948. vdev->vxge_entries[j].entry = alarm_msix_id;
  1949. vdev->vxge_entries[j].in_use = 0;
  1950. ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
  1951. /* if driver request exceeeds available irq's, request with a small
  1952. * number.
  1953. */
  1954. if (ret > 0) {
  1955. vxge_debug_init(VXGE_ERR,
  1956. "%s: MSI-X enable failed for %d vectors, available: %d",
  1957. VXGE_DRIVER_NAME, intr_cnt, ret);
  1958. vdev->max_vpath_supported = vdev->no_of_vpath;
  1959. intr_cnt = (vdev->max_vpath_supported * 2) + 1;
  1960. /* Reset the alarm vector setting */
  1961. vdev->entries[j].entry = 0;
  1962. vdev->vxge_entries[j].entry = 0;
  1963. /* Initialize the alarm vector with new setting */
  1964. vdev->entries[intr_cnt - 1].entry = alarm_msix_id;
  1965. vdev->vxge_entries[intr_cnt - 1].entry = alarm_msix_id;
  1966. vdev->vxge_entries[intr_cnt - 1].in_use = 0;
  1967. ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
  1968. if (!ret)
  1969. vxge_debug_init(VXGE_ERR,
  1970. "%s: MSI-X enabled for %d vectors",
  1971. VXGE_DRIVER_NAME, intr_cnt);
  1972. }
  1973. if (ret) {
  1974. vxge_debug_init(VXGE_ERR,
  1975. "%s: MSI-X enable failed for %d vectors, ret: %d",
  1976. VXGE_DRIVER_NAME, intr_cnt, ret);
  1977. kfree(vdev->entries);
  1978. kfree(vdev->vxge_entries);
  1979. vdev->entries = NULL;
  1980. vdev->vxge_entries = NULL;
  1981. return -ENODEV;
  1982. }
  1983. return 0;
  1984. }
  1985. static int vxge_enable_msix(struct vxgedev *vdev)
  1986. {
  1987. int i, ret = 0;
  1988. enum vxge_hw_status status;
  1989. /* 0 - Tx, 1 - Rx */
  1990. int tim_msix_id[4];
  1991. int alarm_msix_id = 0, msix_intr_vect = 0;
  1992. vdev->intr_cnt = 0;
  1993. /* allocate msix vectors */
  1994. ret = vxge_alloc_msix(vdev);
  1995. if (!ret) {
  1996. /* Last vector in the list is used for alarm */
  1997. alarm_msix_id =
  1998. VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
  1999. for (i = 0; i < vdev->no_of_vpath; i++) {
  2000. /* If fifo or ring are not enabled
  2001. the MSIX vector for that should be set to 0
  2002. Hence initializeing this array to all 0s.
  2003. */
  2004. memset(tim_msix_id, 0, sizeof(tim_msix_id));
  2005. msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
  2006. tim_msix_id[0] = msix_intr_vect;
  2007. tim_msix_id[1] = msix_intr_vect + 1;
  2008. vdev->vpaths[i].ring.rx_vector_no = tim_msix_id[1];
  2009. status = vxge_hw_vpath_msix_set(
  2010. vdev->vpaths[i].handle,
  2011. tim_msix_id, alarm_msix_id);
  2012. if (status != VXGE_HW_OK) {
  2013. vxge_debug_init(VXGE_ERR,
  2014. "vxge_hw_vpath_msix_set "
  2015. "failed with status : %x", status);
  2016. kfree(vdev->entries);
  2017. kfree(vdev->vxge_entries);
  2018. pci_disable_msix(vdev->pdev);
  2019. return -ENODEV;
  2020. }
  2021. }
  2022. }
  2023. return ret;
  2024. }
  2025. static void vxge_rem_msix_isr(struct vxgedev *vdev)
  2026. {
  2027. int intr_cnt;
  2028. for (intr_cnt = 0; intr_cnt < (vdev->max_vpath_supported * 2 + 1);
  2029. intr_cnt++) {
  2030. if (vdev->vxge_entries[intr_cnt].in_use) {
  2031. synchronize_irq(vdev->entries[intr_cnt].vector);
  2032. free_irq(vdev->entries[intr_cnt].vector,
  2033. vdev->vxge_entries[intr_cnt].arg);
  2034. vdev->vxge_entries[intr_cnt].in_use = 0;
  2035. }
  2036. }
  2037. kfree(vdev->entries);
  2038. kfree(vdev->vxge_entries);
  2039. vdev->entries = NULL;
  2040. vdev->vxge_entries = NULL;
  2041. if (vdev->config.intr_type == MSI_X)
  2042. pci_disable_msix(vdev->pdev);
  2043. }
  2044. #endif
  2045. static void vxge_rem_isr(struct vxgedev *vdev)
  2046. {
  2047. struct __vxge_hw_device *hldev;
  2048. hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
  2049. #ifdef CONFIG_PCI_MSI
  2050. if (vdev->config.intr_type == MSI_X) {
  2051. vxge_rem_msix_isr(vdev);
  2052. } else
  2053. #endif
  2054. if (vdev->config.intr_type == INTA) {
  2055. synchronize_irq(vdev->pdev->irq);
  2056. free_irq(vdev->pdev->irq, vdev);
  2057. }
  2058. }
  2059. static int vxge_add_isr(struct vxgedev *vdev)
  2060. {
  2061. int ret = 0;
  2062. #ifdef CONFIG_PCI_MSI
  2063. int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
  2064. int pci_fun = PCI_FUNC(vdev->pdev->devfn);
  2065. if (vdev->config.intr_type == MSI_X)
  2066. ret = vxge_enable_msix(vdev);
  2067. if (ret) {
  2068. vxge_debug_init(VXGE_ERR,
  2069. "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
  2070. vxge_debug_init(VXGE_ERR,
  2071. "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
  2072. vdev->config.intr_type = INTA;
  2073. }
  2074. if (vdev->config.intr_type == MSI_X) {
  2075. for (intr_idx = 0;
  2076. intr_idx < (vdev->no_of_vpath *
  2077. VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
  2078. msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
  2079. irq_req = 0;
  2080. switch (msix_idx) {
  2081. case 0:
  2082. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2083. "%s:vxge fn: %d vpath: %d Tx MSI-X: %d",
  2084. vdev->ndev->name, pci_fun, vp_idx,
  2085. vdev->entries[intr_cnt].entry);
  2086. ret = request_irq(
  2087. vdev->entries[intr_cnt].vector,
  2088. vxge_tx_msix_handle, 0,
  2089. vdev->desc[intr_cnt],
  2090. &vdev->vpaths[vp_idx].fifo);
  2091. vdev->vxge_entries[intr_cnt].arg =
  2092. &vdev->vpaths[vp_idx].fifo;
  2093. irq_req = 1;
  2094. break;
  2095. case 1:
  2096. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2097. "%s:vxge fn: %d vpath: %d Rx MSI-X: %d",
  2098. vdev->ndev->name, pci_fun, vp_idx,
  2099. vdev->entries[intr_cnt].entry);
  2100. ret = request_irq(
  2101. vdev->entries[intr_cnt].vector,
  2102. vxge_rx_msix_napi_handle,
  2103. 0,
  2104. vdev->desc[intr_cnt],
  2105. &vdev->vpaths[vp_idx].ring);
  2106. vdev->vxge_entries[intr_cnt].arg =
  2107. &vdev->vpaths[vp_idx].ring;
  2108. irq_req = 1;
  2109. break;
  2110. }
  2111. if (ret) {
  2112. vxge_debug_init(VXGE_ERR,
  2113. "%s: MSIX - %d Registration failed",
  2114. vdev->ndev->name, intr_cnt);
  2115. vxge_rem_msix_isr(vdev);
  2116. vdev->config.intr_type = INTA;
  2117. vxge_debug_init(VXGE_ERR,
  2118. "%s: Defaulting to INTA"
  2119. , vdev->ndev->name);
  2120. goto INTA_MODE;
  2121. }
  2122. if (irq_req) {
  2123. /* We requested for this msix interrupt */
  2124. vdev->vxge_entries[intr_cnt].in_use = 1;
  2125. vxge_hw_vpath_msix_unmask(
  2126. vdev->vpaths[vp_idx].handle,
  2127. intr_idx);
  2128. intr_cnt++;
  2129. }
  2130. /* Point to next vpath handler */
  2131. if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
  2132. (vp_idx < (vdev->no_of_vpath - 1)))
  2133. vp_idx++;
  2134. }
  2135. intr_cnt = vdev->max_vpath_supported * 2;
  2136. snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
  2137. "%s:vxge Alarm fn: %d MSI-X: %d",
  2138. vdev->ndev->name, pci_fun,
  2139. vdev->entries[intr_cnt].entry);
  2140. /* For Alarm interrupts */
  2141. ret = request_irq(vdev->entries[intr_cnt].vector,
  2142. vxge_alarm_msix_handle, 0,
  2143. vdev->desc[intr_cnt],
  2144. &vdev->vpaths[vp_idx]);
  2145. if (ret) {
  2146. vxge_debug_init(VXGE_ERR,
  2147. "%s: MSIX - %d Registration failed",
  2148. vdev->ndev->name, intr_cnt);
  2149. vxge_rem_msix_isr(vdev);
  2150. vdev->config.intr_type = INTA;
  2151. vxge_debug_init(VXGE_ERR,
  2152. "%s: Defaulting to INTA",
  2153. vdev->ndev->name);
  2154. goto INTA_MODE;
  2155. }
  2156. vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
  2157. intr_idx - 2);
  2158. vdev->vxge_entries[intr_cnt].in_use = 1;
  2159. vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[vp_idx];
  2160. }
  2161. INTA_MODE:
  2162. #endif
  2163. snprintf(vdev->desc[0], VXGE_INTR_STRLEN, "%s:vxge", vdev->ndev->name);
  2164. if (vdev->config.intr_type == INTA) {
  2165. vxge_hw_device_set_intr_type(vdev->devh,
  2166. VXGE_HW_INTR_MODE_IRQLINE);
  2167. vxge_hw_vpath_tti_ci_set(vdev->devh,
  2168. vdev->vpaths[0].device_id);
  2169. ret = request_irq((int) vdev->pdev->irq,
  2170. vxge_isr_napi,
  2171. IRQF_SHARED, vdev->desc[0], vdev);
  2172. if (ret) {
  2173. vxge_debug_init(VXGE_ERR,
  2174. "%s %s-%d: ISR registration failed",
  2175. VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
  2176. return -ENODEV;
  2177. }
  2178. vxge_debug_init(VXGE_TRACE,
  2179. "new %s-%d line allocated",
  2180. "IRQ", vdev->pdev->irq);
  2181. }
  2182. return VXGE_HW_OK;
  2183. }
  2184. static void vxge_poll_vp_reset(unsigned long data)
  2185. {
  2186. struct vxgedev *vdev = (struct vxgedev *)data;
  2187. int i, j = 0;
  2188. for (i = 0; i < vdev->no_of_vpath; i++) {
  2189. if (test_bit(i, &vdev->vp_reset)) {
  2190. vxge_reset_vpath(vdev, i);
  2191. j++;
  2192. }
  2193. }
  2194. if (j && (vdev->config.intr_type != MSI_X)) {
  2195. vxge_hw_device_unmask_all(vdev->devh);
  2196. vxge_hw_device_flush_io(vdev->devh);
  2197. }
  2198. mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
  2199. }
  2200. static void vxge_poll_vp_lockup(unsigned long data)
  2201. {
  2202. struct vxgedev *vdev = (struct vxgedev *)data;
  2203. int i;
  2204. struct vxge_ring *ring;
  2205. enum vxge_hw_status status = VXGE_HW_OK;
  2206. for (i = 0; i < vdev->no_of_vpath; i++) {
  2207. ring = &vdev->vpaths[i].ring;
  2208. /* Did this vpath received any packets */
  2209. if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
  2210. status = vxge_hw_vpath_check_leak(ring->handle);
  2211. /* Did it received any packets last time */
  2212. if ((VXGE_HW_FAIL == status) &&
  2213. (VXGE_HW_FAIL == ring->last_status)) {
  2214. /* schedule vpath reset */
  2215. if (!test_and_set_bit(i, &vdev->vp_reset)) {
  2216. /* disable interrupts for this vpath */
  2217. vxge_vpath_intr_disable(vdev, i);
  2218. /* stop the queue for this vpath */
  2219. vxge_stop_tx_queue(&vdev->vpaths[i].
  2220. fifo);
  2221. continue;
  2222. }
  2223. }
  2224. }
  2225. ring->stats.prev_rx_frms = ring->stats.rx_frms;
  2226. ring->last_status = status;
  2227. }
  2228. /* Check every 1 milli second */
  2229. mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
  2230. }
  2231. /**
  2232. * vxge_open
  2233. * @dev: pointer to the device structure.
  2234. *
  2235. * This function is the open entry point of the driver. It mainly calls a
  2236. * function to allocate Rx buffers and inserts them into the buffer
  2237. * descriptors and then enables the Rx part of the NIC.
  2238. * Return value: '0' on success and an appropriate (-)ve integer as
  2239. * defined in errno.h file on failure.
  2240. */
  2241. int
  2242. vxge_open(struct net_device *dev)
  2243. {
  2244. enum vxge_hw_status status;
  2245. struct vxgedev *vdev;
  2246. struct __vxge_hw_device *hldev;
  2247. int ret = 0;
  2248. int i;
  2249. u64 val64, function_mode;
  2250. vxge_debug_entryexit(VXGE_TRACE,
  2251. "%s: %s:%d", dev->name, __func__, __LINE__);
  2252. vdev = (struct vxgedev *)netdev_priv(dev);
  2253. hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
  2254. function_mode = vdev->config.device_hw_info.function_mode;
  2255. /* make sure you have link off by default every time Nic is
  2256. * initialized */
  2257. netif_carrier_off(dev);
  2258. /* Open VPATHs */
  2259. status = vxge_open_vpaths(vdev);
  2260. if (status != VXGE_HW_OK) {
  2261. vxge_debug_init(VXGE_ERR,
  2262. "%s: fatal: Vpath open failed", vdev->ndev->name);
  2263. ret = -EPERM;
  2264. goto out0;
  2265. }
  2266. vdev->mtu = dev->mtu;
  2267. status = vxge_add_isr(vdev);
  2268. if (status != VXGE_HW_OK) {
  2269. vxge_debug_init(VXGE_ERR,
  2270. "%s: fatal: ISR add failed", dev->name);
  2271. ret = -EPERM;
  2272. goto out1;
  2273. }
  2274. if (vdev->config.intr_type != MSI_X) {
  2275. netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
  2276. vdev->config.napi_weight);
  2277. napi_enable(&vdev->napi);
  2278. for (i = 0; i < vdev->no_of_vpath; i++)
  2279. vdev->vpaths[i].ring.napi_p = &vdev->napi;
  2280. } else {
  2281. for (i = 0; i < vdev->no_of_vpath; i++) {
  2282. netif_napi_add(dev, &vdev->vpaths[i].ring.napi,
  2283. vxge_poll_msix, vdev->config.napi_weight);
  2284. napi_enable(&vdev->vpaths[i].ring.napi);
  2285. vdev->vpaths[i].ring.napi_p =
  2286. &vdev->vpaths[i].ring.napi;
  2287. }
  2288. }
  2289. /* configure RTH */
  2290. if (vdev->config.rth_steering) {
  2291. status = vxge_rth_configure(vdev);
  2292. if (status != VXGE_HW_OK) {
  2293. vxge_debug_init(VXGE_ERR,
  2294. "%s: fatal: RTH configuration failed",
  2295. dev->name);
  2296. ret = -EPERM;
  2297. goto out2;
  2298. }
  2299. }
  2300. for (i = 0; i < vdev->no_of_vpath; i++) {
  2301. /* set initial mtu before enabling the device */
  2302. status = vxge_hw_vpath_mtu_set(vdev->vpaths[i].handle,
  2303. vdev->mtu);
  2304. if (status != VXGE_HW_OK) {
  2305. vxge_debug_init(VXGE_ERR,
  2306. "%s: fatal: can not set new MTU", dev->name);
  2307. ret = -EPERM;
  2308. goto out2;
  2309. }
  2310. }
  2311. VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
  2312. vxge_debug_init(vdev->level_trace,
  2313. "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
  2314. VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
  2315. /* Reprogram the DA table with populated mac addresses */
  2316. for (i = 0; i < vdev->no_of_vpath; i++) {
  2317. vxge_restore_vpath_mac_addr(&vdev->vpaths[i]);
  2318. vxge_restore_vpath_vid_table(&vdev->vpaths[i]);
  2319. }
  2320. /* Enable vpath to sniff all unicast/multicast traffic that not
  2321. * addressed to them. We allow promiscous mode for PF only
  2322. */
  2323. val64 = 0;
  2324. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  2325. val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
  2326. vxge_hw_mgmt_reg_write(vdev->devh,
  2327. vxge_hw_mgmt_reg_type_mrpcim,
  2328. 0,
  2329. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2330. rxmac_authorize_all_addr),
  2331. val64);
  2332. vxge_hw_mgmt_reg_write(vdev->devh,
  2333. vxge_hw_mgmt_reg_type_mrpcim,
  2334. 0,
  2335. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2336. rxmac_authorize_all_vid),
  2337. val64);
  2338. vxge_set_multicast(dev);
  2339. /* Enabling Bcast and mcast for all vpath */
  2340. for (i = 0; i < vdev->no_of_vpath; i++) {
  2341. status = vxge_hw_vpath_bcast_enable(vdev->vpaths[i].handle);
  2342. if (status != VXGE_HW_OK)
  2343. vxge_debug_init(VXGE_ERR,
  2344. "%s : Can not enable bcast for vpath "
  2345. "id %d", dev->name, i);
  2346. if (vdev->config.addr_learn_en) {
  2347. status =
  2348. vxge_hw_vpath_mcast_enable(vdev->vpaths[i].handle);
  2349. if (status != VXGE_HW_OK)
  2350. vxge_debug_init(VXGE_ERR,
  2351. "%s : Can not enable mcast for vpath "
  2352. "id %d", dev->name, i);
  2353. }
  2354. }
  2355. vxge_hw_device_setpause_data(vdev->devh, 0,
  2356. vdev->config.tx_pause_enable,
  2357. vdev->config.rx_pause_enable);
  2358. if (vdev->vp_reset_timer.function == NULL)
  2359. vxge_os_timer(vdev->vp_reset_timer,
  2360. vxge_poll_vp_reset, vdev, (HZ/2));
  2361. if (vdev->vp_lockup_timer.function == NULL)
  2362. vxge_os_timer(vdev->vp_lockup_timer,
  2363. vxge_poll_vp_lockup, vdev, (HZ/2));
  2364. set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2365. smp_wmb();
  2366. if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
  2367. netif_carrier_on(vdev->ndev);
  2368. printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
  2369. vdev->stats.link_up++;
  2370. }
  2371. vxge_hw_device_intr_enable(vdev->devh);
  2372. smp_wmb();
  2373. for (i = 0; i < vdev->no_of_vpath; i++) {
  2374. vxge_hw_vpath_enable(vdev->vpaths[i].handle);
  2375. smp_wmb();
  2376. vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
  2377. }
  2378. vxge_start_all_tx_queue(vdev);
  2379. goto out0;
  2380. out2:
  2381. vxge_rem_isr(vdev);
  2382. /* Disable napi */
  2383. if (vdev->config.intr_type != MSI_X)
  2384. napi_disable(&vdev->napi);
  2385. else {
  2386. for (i = 0; i < vdev->no_of_vpath; i++)
  2387. napi_disable(&vdev->vpaths[i].ring.napi);
  2388. }
  2389. out1:
  2390. vxge_close_vpaths(vdev, 0);
  2391. out0:
  2392. vxge_debug_entryexit(VXGE_TRACE,
  2393. "%s: %s:%d Exiting...",
  2394. dev->name, __func__, __LINE__);
  2395. return ret;
  2396. }
  2397. /* Loop throught the mac address list and delete all the entries */
  2398. void vxge_free_mac_add_list(struct vxge_vpath *vpath)
  2399. {
  2400. struct list_head *entry, *next;
  2401. if (list_empty(&vpath->mac_addr_list))
  2402. return;
  2403. list_for_each_safe(entry, next, &vpath->mac_addr_list) {
  2404. list_del(entry);
  2405. kfree((struct vxge_mac_addrs *)entry);
  2406. }
  2407. }
  2408. static void vxge_napi_del_all(struct vxgedev *vdev)
  2409. {
  2410. int i;
  2411. if (vdev->config.intr_type != MSI_X)
  2412. netif_napi_del(&vdev->napi);
  2413. else {
  2414. for (i = 0; i < vdev->no_of_vpath; i++)
  2415. netif_napi_del(&vdev->vpaths[i].ring.napi);
  2416. }
  2417. return;
  2418. }
  2419. int do_vxge_close(struct net_device *dev, int do_io)
  2420. {
  2421. enum vxge_hw_status status;
  2422. struct vxgedev *vdev;
  2423. struct __vxge_hw_device *hldev;
  2424. int i;
  2425. u64 val64, vpath_vector;
  2426. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
  2427. dev->name, __func__, __LINE__);
  2428. vdev = (struct vxgedev *)netdev_priv(dev);
  2429. hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
  2430. if (unlikely(!is_vxge_card_up(vdev)))
  2431. return 0;
  2432. /* If vxge_handle_crit_err task is executing,
  2433. * wait till it completes. */
  2434. while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
  2435. msleep(50);
  2436. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2437. if (do_io) {
  2438. /* Put the vpath back in normal mode */
  2439. vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
  2440. status = vxge_hw_mgmt_reg_read(vdev->devh,
  2441. vxge_hw_mgmt_reg_type_mrpcim,
  2442. 0,
  2443. (ulong)offsetof(
  2444. struct vxge_hw_mrpcim_reg,
  2445. rts_mgr_cbasin_cfg),
  2446. &val64);
  2447. if (status == VXGE_HW_OK) {
  2448. val64 &= ~vpath_vector;
  2449. status = vxge_hw_mgmt_reg_write(vdev->devh,
  2450. vxge_hw_mgmt_reg_type_mrpcim,
  2451. 0,
  2452. (ulong)offsetof(
  2453. struct vxge_hw_mrpcim_reg,
  2454. rts_mgr_cbasin_cfg),
  2455. val64);
  2456. }
  2457. /* Remove the function 0 from promiscous mode */
  2458. vxge_hw_mgmt_reg_write(vdev->devh,
  2459. vxge_hw_mgmt_reg_type_mrpcim,
  2460. 0,
  2461. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2462. rxmac_authorize_all_addr),
  2463. 0);
  2464. vxge_hw_mgmt_reg_write(vdev->devh,
  2465. vxge_hw_mgmt_reg_type_mrpcim,
  2466. 0,
  2467. (ulong)offsetof(struct vxge_hw_mrpcim_reg,
  2468. rxmac_authorize_all_vid),
  2469. 0);
  2470. smp_wmb();
  2471. }
  2472. del_timer_sync(&vdev->vp_lockup_timer);
  2473. del_timer_sync(&vdev->vp_reset_timer);
  2474. /* Disable napi */
  2475. if (vdev->config.intr_type != MSI_X)
  2476. napi_disable(&vdev->napi);
  2477. else {
  2478. for (i = 0; i < vdev->no_of_vpath; i++)
  2479. napi_disable(&vdev->vpaths[i].ring.napi);
  2480. }
  2481. netif_carrier_off(vdev->ndev);
  2482. printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
  2483. vxge_stop_all_tx_queue(vdev);
  2484. /* Note that at this point xmit() is stopped by upper layer */
  2485. if (do_io)
  2486. vxge_hw_device_intr_disable(vdev->devh);
  2487. mdelay(1000);
  2488. vxge_rem_isr(vdev);
  2489. vxge_napi_del_all(vdev);
  2490. if (do_io)
  2491. vxge_reset_all_vpaths(vdev);
  2492. vxge_close_vpaths(vdev, 0);
  2493. vxge_debug_entryexit(VXGE_TRACE,
  2494. "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
  2495. clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
  2496. return 0;
  2497. }
  2498. /**
  2499. * vxge_close
  2500. * @dev: device pointer.
  2501. *
  2502. * This is the stop entry point of the driver. It needs to undo exactly
  2503. * whatever was done by the open entry point, thus it's usually referred to
  2504. * as the close function.Among other things this function mainly stops the
  2505. * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
  2506. * Return value: '0' on success and an appropriate (-)ve integer as
  2507. * defined in errno.h file on failure.
  2508. */
  2509. int
  2510. vxge_close(struct net_device *dev)
  2511. {
  2512. do_vxge_close(dev, 1);
  2513. return 0;
  2514. }
  2515. /**
  2516. * vxge_change_mtu
  2517. * @dev: net device pointer.
  2518. * @new_mtu :the new MTU size for the device.
  2519. *
  2520. * A driver entry point to change MTU size for the device. Before changing
  2521. * the MTU the device must be stopped.
  2522. */
  2523. static int vxge_change_mtu(struct net_device *dev, int new_mtu)
  2524. {
  2525. struct vxgedev *vdev = netdev_priv(dev);
  2526. vxge_debug_entryexit(vdev->level_trace,
  2527. "%s:%d", __func__, __LINE__);
  2528. if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
  2529. vxge_debug_init(vdev->level_err,
  2530. "%s: mtu size is invalid", dev->name);
  2531. return -EPERM;
  2532. }
  2533. /* check if device is down already */
  2534. if (unlikely(!is_vxge_card_up(vdev))) {
  2535. /* just store new value, will use later on open() */
  2536. dev->mtu = new_mtu;
  2537. vxge_debug_init(vdev->level_err,
  2538. "%s", "device is down on MTU change");
  2539. return 0;
  2540. }
  2541. vxge_debug_init(vdev->level_trace,
  2542. "trying to apply new MTU %d", new_mtu);
  2543. if (vxge_close(dev))
  2544. return -EIO;
  2545. dev->mtu = new_mtu;
  2546. vdev->mtu = new_mtu;
  2547. if (vxge_open(dev))
  2548. return -EIO;
  2549. vxge_debug_init(vdev->level_trace,
  2550. "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
  2551. vxge_debug_entryexit(vdev->level_trace,
  2552. "%s:%d Exiting...", __func__, __LINE__);
  2553. return 0;
  2554. }
  2555. /**
  2556. * vxge_get_stats
  2557. * @dev: pointer to the device structure
  2558. *
  2559. * Updates the device statistics structure. This function updates the device
  2560. * statistics structure in the net_device structure and returns a pointer
  2561. * to the same.
  2562. */
  2563. static struct net_device_stats *
  2564. vxge_get_stats(struct net_device *dev)
  2565. {
  2566. struct vxgedev *vdev;
  2567. struct net_device_stats *net_stats;
  2568. int k;
  2569. vdev = netdev_priv(dev);
  2570. net_stats = &vdev->stats.net_stats;
  2571. memset(net_stats, 0, sizeof(struct net_device_stats));
  2572. for (k = 0; k < vdev->no_of_vpath; k++) {
  2573. net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
  2574. net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
  2575. net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
  2576. net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
  2577. net_stats->rx_dropped +=
  2578. vdev->vpaths[k].ring.stats.rx_dropped;
  2579. net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
  2580. net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
  2581. net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
  2582. }
  2583. return net_stats;
  2584. }
  2585. /**
  2586. * vxge_ioctl
  2587. * @dev: Device pointer.
  2588. * @ifr: An IOCTL specific structure, that can contain a pointer to
  2589. * a proprietary structure used to pass information to the driver.
  2590. * @cmd: This is used to distinguish between the different commands that
  2591. * can be passed to the IOCTL functions.
  2592. *
  2593. * Entry point for the Ioctl.
  2594. */
  2595. static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  2596. {
  2597. return -EOPNOTSUPP;
  2598. }
  2599. /**
  2600. * vxge_tx_watchdog
  2601. * @dev: pointer to net device structure
  2602. *
  2603. * Watchdog for transmit side.
  2604. * This function is triggered if the Tx Queue is stopped
  2605. * for a pre-defined amount of time when the Interface is still up.
  2606. */
  2607. static void
  2608. vxge_tx_watchdog(struct net_device *dev)
  2609. {
  2610. struct vxgedev *vdev;
  2611. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  2612. vdev = (struct vxgedev *)netdev_priv(dev);
  2613. vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
  2614. vxge_reset(vdev);
  2615. vxge_debug_entryexit(VXGE_TRACE,
  2616. "%s:%d Exiting...", __func__, __LINE__);
  2617. }
  2618. /**
  2619. * vxge_vlan_rx_register
  2620. * @dev: net device pointer.
  2621. * @grp: vlan group
  2622. *
  2623. * Vlan group registration
  2624. */
  2625. static void
  2626. vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
  2627. {
  2628. struct vxgedev *vdev;
  2629. struct vxge_vpath *vpath;
  2630. int vp;
  2631. u64 vid;
  2632. enum vxge_hw_status status;
  2633. int i;
  2634. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  2635. vdev = (struct vxgedev *)netdev_priv(dev);
  2636. vpath = &vdev->vpaths[0];
  2637. if ((NULL == grp) && (vpath->is_open)) {
  2638. /* Get the first vlan */
  2639. status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
  2640. while (status == VXGE_HW_OK) {
  2641. /* Delete this vlan from the vid table */
  2642. for (vp = 0; vp < vdev->no_of_vpath; vp++) {
  2643. vpath = &vdev->vpaths[vp];
  2644. if (!vpath->is_open)
  2645. continue;
  2646. vxge_hw_vpath_vid_delete(vpath->handle, vid);
  2647. }
  2648. /* Get the next vlan to be deleted */
  2649. vpath = &vdev->vpaths[0];
  2650. status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
  2651. }
  2652. }
  2653. vdev->vlgrp = grp;
  2654. for (i = 0; i < vdev->no_of_vpath; i++) {
  2655. if (vdev->vpaths[i].is_configured)
  2656. vdev->vpaths[i].ring.vlgrp = grp;
  2657. }
  2658. vxge_debug_entryexit(VXGE_TRACE,
  2659. "%s:%d Exiting...", __func__, __LINE__);
  2660. }
  2661. /**
  2662. * vxge_vlan_rx_add_vid
  2663. * @dev: net device pointer.
  2664. * @vid: vid
  2665. *
  2666. * Add the vlan id to the devices vlan id table
  2667. */
  2668. static void
  2669. vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
  2670. {
  2671. struct vxgedev *vdev;
  2672. struct vxge_vpath *vpath;
  2673. int vp_id;
  2674. vdev = (struct vxgedev *)netdev_priv(dev);
  2675. /* Add these vlan to the vid table */
  2676. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  2677. vpath = &vdev->vpaths[vp_id];
  2678. if (!vpath->is_open)
  2679. continue;
  2680. vxge_hw_vpath_vid_add(vpath->handle, vid);
  2681. }
  2682. }
  2683. /**
  2684. * vxge_vlan_rx_add_vid
  2685. * @dev: net device pointer.
  2686. * @vid: vid
  2687. *
  2688. * Remove the vlan id from the device's vlan id table
  2689. */
  2690. static void
  2691. vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  2692. {
  2693. struct vxgedev *vdev;
  2694. struct vxge_vpath *vpath;
  2695. int vp_id;
  2696. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  2697. vdev = (struct vxgedev *)netdev_priv(dev);
  2698. vlan_group_set_device(vdev->vlgrp, vid, NULL);
  2699. /* Delete this vlan from the vid table */
  2700. for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
  2701. vpath = &vdev->vpaths[vp_id];
  2702. if (!vpath->is_open)
  2703. continue;
  2704. vxge_hw_vpath_vid_delete(vpath->handle, vid);
  2705. }
  2706. vxge_debug_entryexit(VXGE_TRACE,
  2707. "%s:%d Exiting...", __func__, __LINE__);
  2708. }
  2709. static const struct net_device_ops vxge_netdev_ops = {
  2710. .ndo_open = vxge_open,
  2711. .ndo_stop = vxge_close,
  2712. .ndo_get_stats = vxge_get_stats,
  2713. .ndo_start_xmit = vxge_xmit,
  2714. .ndo_validate_addr = eth_validate_addr,
  2715. .ndo_set_multicast_list = vxge_set_multicast,
  2716. .ndo_do_ioctl = vxge_ioctl,
  2717. .ndo_set_mac_address = vxge_set_mac_addr,
  2718. .ndo_change_mtu = vxge_change_mtu,
  2719. .ndo_vlan_rx_register = vxge_vlan_rx_register,
  2720. .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
  2721. .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
  2722. .ndo_tx_timeout = vxge_tx_watchdog,
  2723. #ifdef CONFIG_NET_POLL_CONTROLLER
  2724. .ndo_poll_controller = vxge_netpoll,
  2725. #endif
  2726. };
  2727. int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
  2728. struct vxge_config *config,
  2729. int high_dma, int no_of_vpath,
  2730. struct vxgedev **vdev_out)
  2731. {
  2732. struct net_device *ndev;
  2733. enum vxge_hw_status status = VXGE_HW_OK;
  2734. struct vxgedev *vdev;
  2735. int i, ret = 0, no_of_queue = 1;
  2736. u64 stat;
  2737. *vdev_out = NULL;
  2738. if (config->tx_steering_type == TX_MULTIQ_STEERING)
  2739. no_of_queue = no_of_vpath;
  2740. ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
  2741. no_of_queue);
  2742. if (ndev == NULL) {
  2743. vxge_debug_init(
  2744. vxge_hw_device_trace_level_get(hldev),
  2745. "%s : device allocation failed", __func__);
  2746. ret = -ENODEV;
  2747. goto _out0;
  2748. }
  2749. vxge_debug_entryexit(
  2750. vxge_hw_device_trace_level_get(hldev),
  2751. "%s: %s:%d Entering...",
  2752. ndev->name, __func__, __LINE__);
  2753. vdev = netdev_priv(ndev);
  2754. memset(vdev, 0, sizeof(struct vxgedev));
  2755. vdev->ndev = ndev;
  2756. vdev->devh = hldev;
  2757. vdev->pdev = hldev->pdev;
  2758. memcpy(&vdev->config, config, sizeof(struct vxge_config));
  2759. vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
  2760. SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
  2761. ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
  2762. NETIF_F_HW_VLAN_FILTER;
  2763. /* Driver entry points */
  2764. ndev->irq = vdev->pdev->irq;
  2765. ndev->base_addr = (unsigned long) hldev->bar0;
  2766. ndev->netdev_ops = &vxge_netdev_ops;
  2767. ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
  2768. initialize_ethtool_ops(ndev);
  2769. /* Allocate memory for vpath */
  2770. vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
  2771. no_of_vpath, GFP_KERNEL);
  2772. if (!vdev->vpaths) {
  2773. vxge_debug_init(VXGE_ERR,
  2774. "%s: vpath memory allocation failed",
  2775. vdev->ndev->name);
  2776. ret = -ENODEV;
  2777. goto _out1;
  2778. }
  2779. ndev->features |= NETIF_F_SG;
  2780. ndev->features |= NETIF_F_HW_CSUM;
  2781. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2782. "%s : checksuming enabled", __func__);
  2783. if (high_dma) {
  2784. ndev->features |= NETIF_F_HIGHDMA;
  2785. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2786. "%s : using High DMA", __func__);
  2787. }
  2788. ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
  2789. if (vdev->config.gro_enable)
  2790. ndev->features |= NETIF_F_GRO;
  2791. if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
  2792. ndev->real_num_tx_queues = no_of_vpath;
  2793. #ifdef NETIF_F_LLTX
  2794. ndev->features |= NETIF_F_LLTX;
  2795. #endif
  2796. for (i = 0; i < no_of_vpath; i++)
  2797. spin_lock_init(&vdev->vpaths[i].fifo.tx_lock);
  2798. if (register_netdev(ndev)) {
  2799. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2800. "%s: %s : device registration failed!",
  2801. ndev->name, __func__);
  2802. ret = -ENODEV;
  2803. goto _out2;
  2804. }
  2805. /* Set the factory defined MAC address initially */
  2806. ndev->addr_len = ETH_ALEN;
  2807. /* Make Link state as off at this point, when the Link change
  2808. * interrupt comes the state will be automatically changed to
  2809. * the right state.
  2810. */
  2811. netif_carrier_off(ndev);
  2812. vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
  2813. "%s: Ethernet device registered",
  2814. ndev->name);
  2815. *vdev_out = vdev;
  2816. /* Resetting the Device stats */
  2817. status = vxge_hw_mrpcim_stats_access(
  2818. hldev,
  2819. VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
  2820. 0,
  2821. 0,
  2822. &stat);
  2823. if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
  2824. vxge_debug_init(
  2825. vxge_hw_device_trace_level_get(hldev),
  2826. "%s: device stats clear returns"
  2827. "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
  2828. vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
  2829. "%s: %s:%d Exiting...",
  2830. ndev->name, __func__, __LINE__);
  2831. return ret;
  2832. _out2:
  2833. kfree(vdev->vpaths);
  2834. _out1:
  2835. free_netdev(ndev);
  2836. _out0:
  2837. return ret;
  2838. }
  2839. /*
  2840. * vxge_device_unregister
  2841. *
  2842. * This function will unregister and free network device
  2843. */
  2844. void
  2845. vxge_device_unregister(struct __vxge_hw_device *hldev)
  2846. {
  2847. struct vxgedev *vdev;
  2848. struct net_device *dev;
  2849. char buf[IFNAMSIZ];
  2850. #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
  2851. (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
  2852. u32 level_trace;
  2853. #endif
  2854. dev = hldev->ndev;
  2855. vdev = netdev_priv(dev);
  2856. #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
  2857. (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
  2858. level_trace = vdev->level_trace;
  2859. #endif
  2860. vxge_debug_entryexit(level_trace,
  2861. "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
  2862. memcpy(buf, vdev->ndev->name, IFNAMSIZ);
  2863. /* in 2.6 will call stop() if device is up */
  2864. unregister_netdev(dev);
  2865. flush_scheduled_work();
  2866. vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
  2867. vxge_debug_entryexit(level_trace,
  2868. "%s: %s:%d Exiting...", buf, __func__, __LINE__);
  2869. }
  2870. /*
  2871. * vxge_callback_crit_err
  2872. *
  2873. * This function is called by the alarm handler in interrupt context.
  2874. * Driver must analyze it based on the event type.
  2875. */
  2876. static void
  2877. vxge_callback_crit_err(struct __vxge_hw_device *hldev,
  2878. enum vxge_hw_event type, u64 vp_id)
  2879. {
  2880. struct net_device *dev = hldev->ndev;
  2881. struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
  2882. int vpath_idx;
  2883. vxge_debug_entryexit(vdev->level_trace,
  2884. "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
  2885. /* Note: This event type should be used for device wide
  2886. * indications only - Serious errors, Slot freeze and critical errors
  2887. */
  2888. vdev->cric_err_event = type;
  2889. for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++)
  2890. if (vdev->vpaths[vpath_idx].device_id == vp_id)
  2891. break;
  2892. if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
  2893. if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
  2894. vxge_debug_init(VXGE_ERR,
  2895. "%s: Slot is frozen", vdev->ndev->name);
  2896. } else if (type == VXGE_HW_EVENT_SERR) {
  2897. vxge_debug_init(VXGE_ERR,
  2898. "%s: Encountered Serious Error",
  2899. vdev->ndev->name);
  2900. } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
  2901. vxge_debug_init(VXGE_ERR,
  2902. "%s: Encountered Critical Error",
  2903. vdev->ndev->name);
  2904. }
  2905. if ((type == VXGE_HW_EVENT_SERR) ||
  2906. (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
  2907. if (unlikely(vdev->exec_mode))
  2908. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2909. } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
  2910. vxge_hw_device_mask_all(hldev);
  2911. if (unlikely(vdev->exec_mode))
  2912. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2913. } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
  2914. (type == VXGE_HW_EVENT_VPATH_ERR)) {
  2915. if (unlikely(vdev->exec_mode))
  2916. clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
  2917. else {
  2918. /* check if this vpath is already set for reset */
  2919. if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
  2920. /* disable interrupts for this vpath */
  2921. vxge_vpath_intr_disable(vdev, vpath_idx);
  2922. /* stop the queue for this vpath */
  2923. vxge_stop_tx_queue(&vdev->vpaths[vpath_idx].
  2924. fifo);
  2925. }
  2926. }
  2927. }
  2928. vxge_debug_entryexit(vdev->level_trace,
  2929. "%s: %s:%d Exiting...",
  2930. vdev->ndev->name, __func__, __LINE__);
  2931. }
  2932. static void verify_bandwidth(void)
  2933. {
  2934. int i, band_width, total = 0, equal_priority = 0;
  2935. /* 1. If user enters 0 for some fifo, give equal priority to all */
  2936. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  2937. if (bw_percentage[i] == 0) {
  2938. equal_priority = 1;
  2939. break;
  2940. }
  2941. }
  2942. if (!equal_priority) {
  2943. /* 2. If sum exceeds 100, give equal priority to all */
  2944. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  2945. if (bw_percentage[i] == 0xFF)
  2946. break;
  2947. total += bw_percentage[i];
  2948. if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
  2949. equal_priority = 1;
  2950. break;
  2951. }
  2952. }
  2953. }
  2954. if (!equal_priority) {
  2955. /* Is all the bandwidth consumed? */
  2956. if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
  2957. if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
  2958. /* Split rest of bw equally among next VPs*/
  2959. band_width =
  2960. (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
  2961. (VXGE_HW_MAX_VIRTUAL_PATHS - i);
  2962. if (band_width < 2) /* min of 2% */
  2963. equal_priority = 1;
  2964. else {
  2965. for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
  2966. i++)
  2967. bw_percentage[i] =
  2968. band_width;
  2969. }
  2970. }
  2971. } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
  2972. equal_priority = 1;
  2973. }
  2974. if (equal_priority) {
  2975. vxge_debug_init(VXGE_ERR,
  2976. "%s: Assigning equal bandwidth to all the vpaths",
  2977. VXGE_DRIVER_NAME);
  2978. bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
  2979. VXGE_HW_MAX_VIRTUAL_PATHS;
  2980. for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  2981. bw_percentage[i] = bw_percentage[0];
  2982. }
  2983. return;
  2984. }
  2985. /*
  2986. * Vpath configuration
  2987. */
  2988. static int __devinit vxge_config_vpaths(
  2989. struct vxge_hw_device_config *device_config,
  2990. u64 vpath_mask, struct vxge_config *config_param)
  2991. {
  2992. int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
  2993. u32 txdl_size, txdl_per_memblock;
  2994. temp = driver_config->vpath_per_dev;
  2995. if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
  2996. (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
  2997. /* No more CPU. Return vpath number as zero.*/
  2998. if (driver_config->g_no_cpus == -1)
  2999. return 0;
  3000. if (!driver_config->g_no_cpus)
  3001. driver_config->g_no_cpus = num_online_cpus();
  3002. driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
  3003. if (!driver_config->vpath_per_dev)
  3004. driver_config->vpath_per_dev = 1;
  3005. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  3006. if (!vxge_bVALn(vpath_mask, i, 1))
  3007. continue;
  3008. else
  3009. default_no_vpath++;
  3010. if (default_no_vpath < driver_config->vpath_per_dev)
  3011. driver_config->vpath_per_dev = default_no_vpath;
  3012. driver_config->g_no_cpus = driver_config->g_no_cpus -
  3013. (driver_config->vpath_per_dev * 2);
  3014. if (driver_config->g_no_cpus <= 0)
  3015. driver_config->g_no_cpus = -1;
  3016. }
  3017. if (driver_config->vpath_per_dev == 1) {
  3018. vxge_debug_ll_config(VXGE_TRACE,
  3019. "%s: Disable tx and rx steering, "
  3020. "as single vpath is configured", VXGE_DRIVER_NAME);
  3021. config_param->rth_steering = NO_STEERING;
  3022. config_param->tx_steering_type = NO_STEERING;
  3023. device_config->rth_en = 0;
  3024. }
  3025. /* configure bandwidth */
  3026. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
  3027. device_config->vp_config[i].min_bandwidth = bw_percentage[i];
  3028. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3029. device_config->vp_config[i].vp_id = i;
  3030. device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
  3031. if (no_of_vpaths < driver_config->vpath_per_dev) {
  3032. if (!vxge_bVALn(vpath_mask, i, 1)) {
  3033. vxge_debug_ll_config(VXGE_TRACE,
  3034. "%s: vpath: %d is not available",
  3035. VXGE_DRIVER_NAME, i);
  3036. continue;
  3037. } else {
  3038. vxge_debug_ll_config(VXGE_TRACE,
  3039. "%s: vpath: %d available",
  3040. VXGE_DRIVER_NAME, i);
  3041. no_of_vpaths++;
  3042. }
  3043. } else {
  3044. vxge_debug_ll_config(VXGE_TRACE,
  3045. "%s: vpath: %d is not configured, "
  3046. "max_config_vpath exceeded",
  3047. VXGE_DRIVER_NAME, i);
  3048. break;
  3049. }
  3050. /* Configure Tx fifo's */
  3051. device_config->vp_config[i].fifo.enable =
  3052. VXGE_HW_FIFO_ENABLE;
  3053. device_config->vp_config[i].fifo.max_frags =
  3054. MAX_SKB_FRAGS + 1;
  3055. device_config->vp_config[i].fifo.memblock_size =
  3056. VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
  3057. txdl_size = device_config->vp_config[i].fifo.max_frags *
  3058. sizeof(struct vxge_hw_fifo_txd);
  3059. txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
  3060. device_config->vp_config[i].fifo.fifo_blocks =
  3061. ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
  3062. device_config->vp_config[i].fifo.intr =
  3063. VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
  3064. /* Configure tti properties */
  3065. device_config->vp_config[i].tti.intr_enable =
  3066. VXGE_HW_TIM_INTR_ENABLE;
  3067. device_config->vp_config[i].tti.btimer_val =
  3068. (VXGE_TTI_BTIMER_VAL * 1000) / 272;
  3069. device_config->vp_config[i].tti.timer_ac_en =
  3070. VXGE_HW_TIM_TIMER_AC_ENABLE;
  3071. /* For msi-x with napi (each vector
  3072. has a handler of its own) -
  3073. Set CI to OFF for all vpaths */
  3074. device_config->vp_config[i].tti.timer_ci_en =
  3075. VXGE_HW_TIM_TIMER_CI_DISABLE;
  3076. device_config->vp_config[i].tti.timer_ri_en =
  3077. VXGE_HW_TIM_TIMER_RI_DISABLE;
  3078. device_config->vp_config[i].tti.util_sel =
  3079. VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
  3080. device_config->vp_config[i].tti.ltimer_val =
  3081. (VXGE_TTI_LTIMER_VAL * 1000) / 272;
  3082. device_config->vp_config[i].tti.rtimer_val =
  3083. (VXGE_TTI_RTIMER_VAL * 1000) / 272;
  3084. device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
  3085. device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
  3086. device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
  3087. device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
  3088. device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
  3089. device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
  3090. device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
  3091. /* Configure Rx rings */
  3092. device_config->vp_config[i].ring.enable =
  3093. VXGE_HW_RING_ENABLE;
  3094. device_config->vp_config[i].ring.ring_blocks =
  3095. VXGE_HW_DEF_RING_BLOCKS;
  3096. device_config->vp_config[i].ring.buffer_mode =
  3097. VXGE_HW_RING_RXD_BUFFER_MODE_1;
  3098. device_config->vp_config[i].ring.rxds_limit =
  3099. VXGE_HW_DEF_RING_RXDS_LIMIT;
  3100. device_config->vp_config[i].ring.scatter_mode =
  3101. VXGE_HW_RING_SCATTER_MODE_A;
  3102. /* Configure rti properties */
  3103. device_config->vp_config[i].rti.intr_enable =
  3104. VXGE_HW_TIM_INTR_ENABLE;
  3105. device_config->vp_config[i].rti.btimer_val =
  3106. (VXGE_RTI_BTIMER_VAL * 1000)/272;
  3107. device_config->vp_config[i].rti.timer_ac_en =
  3108. VXGE_HW_TIM_TIMER_AC_ENABLE;
  3109. device_config->vp_config[i].rti.timer_ci_en =
  3110. VXGE_HW_TIM_TIMER_CI_DISABLE;
  3111. device_config->vp_config[i].rti.timer_ri_en =
  3112. VXGE_HW_TIM_TIMER_RI_DISABLE;
  3113. device_config->vp_config[i].rti.util_sel =
  3114. VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
  3115. device_config->vp_config[i].rti.urange_a =
  3116. RTI_RX_URANGE_A;
  3117. device_config->vp_config[i].rti.urange_b =
  3118. RTI_RX_URANGE_B;
  3119. device_config->vp_config[i].rti.urange_c =
  3120. RTI_RX_URANGE_C;
  3121. device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
  3122. device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
  3123. device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
  3124. device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
  3125. device_config->vp_config[i].rti.rtimer_val =
  3126. (VXGE_RTI_RTIMER_VAL * 1000) / 272;
  3127. device_config->vp_config[i].rti.ltimer_val =
  3128. (VXGE_RTI_LTIMER_VAL * 1000) / 272;
  3129. device_config->vp_config[i].rpa_strip_vlan_tag =
  3130. vlan_tag_strip;
  3131. }
  3132. driver_config->vpath_per_dev = temp;
  3133. return no_of_vpaths;
  3134. }
  3135. /* initialize device configuratrions */
  3136. static void __devinit vxge_device_config_init(
  3137. struct vxge_hw_device_config *device_config,
  3138. int *intr_type)
  3139. {
  3140. /* Used for CQRQ/SRQ. */
  3141. device_config->dma_blockpool_initial =
  3142. VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
  3143. device_config->dma_blockpool_max =
  3144. VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
  3145. if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
  3146. max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
  3147. #ifndef CONFIG_PCI_MSI
  3148. vxge_debug_init(VXGE_ERR,
  3149. "%s: This Kernel does not support "
  3150. "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
  3151. *intr_type = INTA;
  3152. #endif
  3153. /* Configure whether MSI-X or IRQL. */
  3154. switch (*intr_type) {
  3155. case INTA:
  3156. device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
  3157. break;
  3158. case MSI_X:
  3159. device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
  3160. break;
  3161. }
  3162. /* Timer period between device poll */
  3163. device_config->device_poll_millis = VXGE_TIMER_DELAY;
  3164. /* Configure mac based steering. */
  3165. device_config->rts_mac_en = addr_learn_en;
  3166. /* Configure Vpaths */
  3167. device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
  3168. vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
  3169. __func__);
  3170. vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
  3171. device_config->dma_blockpool_initial);
  3172. vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
  3173. device_config->dma_blockpool_max);
  3174. vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
  3175. device_config->intr_mode);
  3176. vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
  3177. device_config->device_poll_millis);
  3178. vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
  3179. device_config->rts_mac_en);
  3180. vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
  3181. device_config->rth_en);
  3182. vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
  3183. device_config->rth_it_type);
  3184. }
  3185. static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
  3186. {
  3187. int i;
  3188. vxge_debug_init(VXGE_TRACE,
  3189. "%s: %d Vpath(s) opened",
  3190. vdev->ndev->name, vdev->no_of_vpath);
  3191. switch (vdev->config.intr_type) {
  3192. case INTA:
  3193. vxge_debug_init(VXGE_TRACE,
  3194. "%s: Interrupt type INTA", vdev->ndev->name);
  3195. break;
  3196. case MSI_X:
  3197. vxge_debug_init(VXGE_TRACE,
  3198. "%s: Interrupt type MSI-X", vdev->ndev->name);
  3199. break;
  3200. }
  3201. if (vdev->config.rth_steering) {
  3202. vxge_debug_init(VXGE_TRACE,
  3203. "%s: RTH steering enabled for TCP_IPV4",
  3204. vdev->ndev->name);
  3205. } else {
  3206. vxge_debug_init(VXGE_TRACE,
  3207. "%s: RTH steering disabled", vdev->ndev->name);
  3208. }
  3209. switch (vdev->config.tx_steering_type) {
  3210. case NO_STEERING:
  3211. vxge_debug_init(VXGE_TRACE,
  3212. "%s: Tx steering disabled", vdev->ndev->name);
  3213. break;
  3214. case TX_PRIORITY_STEERING:
  3215. vxge_debug_init(VXGE_TRACE,
  3216. "%s: Unsupported tx steering option",
  3217. vdev->ndev->name);
  3218. vxge_debug_init(VXGE_TRACE,
  3219. "%s: Tx steering disabled", vdev->ndev->name);
  3220. vdev->config.tx_steering_type = 0;
  3221. break;
  3222. case TX_VLAN_STEERING:
  3223. vxge_debug_init(VXGE_TRACE,
  3224. "%s: Unsupported tx steering option",
  3225. vdev->ndev->name);
  3226. vxge_debug_init(VXGE_TRACE,
  3227. "%s: Tx steering disabled", vdev->ndev->name);
  3228. vdev->config.tx_steering_type = 0;
  3229. break;
  3230. case TX_MULTIQ_STEERING:
  3231. vxge_debug_init(VXGE_TRACE,
  3232. "%s: Tx multiqueue steering enabled",
  3233. vdev->ndev->name);
  3234. break;
  3235. case TX_PORT_STEERING:
  3236. vxge_debug_init(VXGE_TRACE,
  3237. "%s: Tx port steering enabled",
  3238. vdev->ndev->name);
  3239. break;
  3240. default:
  3241. vxge_debug_init(VXGE_ERR,
  3242. "%s: Unsupported tx steering type",
  3243. vdev->ndev->name);
  3244. vxge_debug_init(VXGE_TRACE,
  3245. "%s: Tx steering disabled", vdev->ndev->name);
  3246. vdev->config.tx_steering_type = 0;
  3247. }
  3248. if (vdev->config.gro_enable) {
  3249. vxge_debug_init(VXGE_ERR,
  3250. "%s: Generic receive offload enabled",
  3251. vdev->ndev->name);
  3252. } else
  3253. vxge_debug_init(VXGE_TRACE,
  3254. "%s: Generic receive offload disabled",
  3255. vdev->ndev->name);
  3256. if (vdev->config.addr_learn_en)
  3257. vxge_debug_init(VXGE_TRACE,
  3258. "%s: MAC Address learning enabled", vdev->ndev->name);
  3259. vxge_debug_init(VXGE_TRACE,
  3260. "%s: Rx doorbell mode enabled", vdev->ndev->name);
  3261. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3262. if (!vxge_bVALn(vpath_mask, i, 1))
  3263. continue;
  3264. vxge_debug_ll_config(VXGE_TRACE,
  3265. "%s: MTU size - %d", vdev->ndev->name,
  3266. ((struct __vxge_hw_device *)(vdev->devh))->
  3267. config.vp_config[i].mtu);
  3268. vxge_debug_init(VXGE_TRACE,
  3269. "%s: VLAN tag stripping %s", vdev->ndev->name,
  3270. ((struct __vxge_hw_device *)(vdev->devh))->
  3271. config.vp_config[i].rpa_strip_vlan_tag
  3272. ? "Enabled" : "Disabled");
  3273. vxge_debug_init(VXGE_TRACE,
  3274. "%s: Ring blocks : %d", vdev->ndev->name,
  3275. ((struct __vxge_hw_device *)(vdev->devh))->
  3276. config.vp_config[i].ring.ring_blocks);
  3277. vxge_debug_init(VXGE_TRACE,
  3278. "%s: Fifo blocks : %d", vdev->ndev->name,
  3279. ((struct __vxge_hw_device *)(vdev->devh))->
  3280. config.vp_config[i].fifo.fifo_blocks);
  3281. vxge_debug_ll_config(VXGE_TRACE,
  3282. "%s: Max frags : %d", vdev->ndev->name,
  3283. ((struct __vxge_hw_device *)(vdev->devh))->
  3284. config.vp_config[i].fifo.max_frags);
  3285. break;
  3286. }
  3287. }
  3288. #ifdef CONFIG_PM
  3289. /**
  3290. * vxge_pm_suspend - vxge power management suspend entry point
  3291. *
  3292. */
  3293. static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
  3294. {
  3295. return -ENOSYS;
  3296. }
  3297. /**
  3298. * vxge_pm_resume - vxge power management resume entry point
  3299. *
  3300. */
  3301. static int vxge_pm_resume(struct pci_dev *pdev)
  3302. {
  3303. return -ENOSYS;
  3304. }
  3305. #endif
  3306. /**
  3307. * vxge_io_error_detected - called when PCI error is detected
  3308. * @pdev: Pointer to PCI device
  3309. * @state: The current pci connection state
  3310. *
  3311. * This function is called after a PCI bus error affecting
  3312. * this device has been detected.
  3313. */
  3314. static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
  3315. pci_channel_state_t state)
  3316. {
  3317. struct __vxge_hw_device *hldev =
  3318. (struct __vxge_hw_device *) pci_get_drvdata(pdev);
  3319. struct net_device *netdev = hldev->ndev;
  3320. netif_device_detach(netdev);
  3321. if (state == pci_channel_io_perm_failure)
  3322. return PCI_ERS_RESULT_DISCONNECT;
  3323. if (netif_running(netdev)) {
  3324. /* Bring down the card, while avoiding PCI I/O */
  3325. do_vxge_close(netdev, 0);
  3326. }
  3327. pci_disable_device(pdev);
  3328. return PCI_ERS_RESULT_NEED_RESET;
  3329. }
  3330. /**
  3331. * vxge_io_slot_reset - called after the pci bus has been reset.
  3332. * @pdev: Pointer to PCI device
  3333. *
  3334. * Restart the card from scratch, as if from a cold-boot.
  3335. * At this point, the card has exprienced a hard reset,
  3336. * followed by fixups by BIOS, and has its config space
  3337. * set up identically to what it was at cold boot.
  3338. */
  3339. static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
  3340. {
  3341. struct __vxge_hw_device *hldev =
  3342. (struct __vxge_hw_device *) pci_get_drvdata(pdev);
  3343. struct net_device *netdev = hldev->ndev;
  3344. struct vxgedev *vdev = netdev_priv(netdev);
  3345. if (pci_enable_device(pdev)) {
  3346. printk(KERN_ERR "%s: "
  3347. "Cannot re-enable device after reset\n",
  3348. VXGE_DRIVER_NAME);
  3349. return PCI_ERS_RESULT_DISCONNECT;
  3350. }
  3351. pci_set_master(pdev);
  3352. vxge_reset(vdev);
  3353. return PCI_ERS_RESULT_RECOVERED;
  3354. }
  3355. /**
  3356. * vxge_io_resume - called when traffic can start flowing again.
  3357. * @pdev: Pointer to PCI device
  3358. *
  3359. * This callback is called when the error recovery driver tells
  3360. * us that its OK to resume normal operation.
  3361. */
  3362. static void vxge_io_resume(struct pci_dev *pdev)
  3363. {
  3364. struct __vxge_hw_device *hldev =
  3365. (struct __vxge_hw_device *) pci_get_drvdata(pdev);
  3366. struct net_device *netdev = hldev->ndev;
  3367. if (netif_running(netdev)) {
  3368. if (vxge_open(netdev)) {
  3369. printk(KERN_ERR "%s: "
  3370. "Can't bring device back up after reset\n",
  3371. VXGE_DRIVER_NAME);
  3372. return;
  3373. }
  3374. }
  3375. netif_device_attach(netdev);
  3376. }
  3377. /**
  3378. * vxge_probe
  3379. * @pdev : structure containing the PCI related information of the device.
  3380. * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
  3381. * Description:
  3382. * This function is called when a new PCI device gets detected and initializes
  3383. * it.
  3384. * Return value:
  3385. * returns 0 on success and negative on failure.
  3386. *
  3387. */
  3388. static int __devinit
  3389. vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
  3390. {
  3391. struct __vxge_hw_device *hldev;
  3392. enum vxge_hw_status status;
  3393. int ret;
  3394. int high_dma = 0;
  3395. u64 vpath_mask = 0;
  3396. struct vxgedev *vdev;
  3397. struct vxge_config ll_config;
  3398. struct vxge_hw_device_config *device_config = NULL;
  3399. struct vxge_hw_device_attr attr;
  3400. int i, j, no_of_vpath = 0, max_vpath_supported = 0;
  3401. u8 *macaddr;
  3402. struct vxge_mac_addrs *entry;
  3403. static int bus = -1, device = -1;
  3404. u8 new_device = 0;
  3405. vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
  3406. attr.pdev = pdev;
  3407. if (bus != pdev->bus->number)
  3408. new_device = 1;
  3409. if (device != PCI_SLOT(pdev->devfn))
  3410. new_device = 1;
  3411. bus = pdev->bus->number;
  3412. device = PCI_SLOT(pdev->devfn);
  3413. if (new_device) {
  3414. if (driver_config->config_dev_cnt &&
  3415. (driver_config->config_dev_cnt !=
  3416. driver_config->total_dev_cnt))
  3417. vxge_debug_init(VXGE_ERR,
  3418. "%s: Configured %d of %d devices",
  3419. VXGE_DRIVER_NAME,
  3420. driver_config->config_dev_cnt,
  3421. driver_config->total_dev_cnt);
  3422. driver_config->config_dev_cnt = 0;
  3423. driver_config->total_dev_cnt = 0;
  3424. driver_config->g_no_cpus = 0;
  3425. }
  3426. driver_config->vpath_per_dev = max_config_vpath;
  3427. driver_config->total_dev_cnt++;
  3428. if (++driver_config->config_dev_cnt > max_config_dev) {
  3429. ret = 0;
  3430. goto _exit0;
  3431. }
  3432. device_config = kzalloc(sizeof(struct vxge_hw_device_config),
  3433. GFP_KERNEL);
  3434. if (!device_config) {
  3435. ret = -ENOMEM;
  3436. vxge_debug_init(VXGE_ERR,
  3437. "device_config : malloc failed %s %d",
  3438. __FILE__, __LINE__);
  3439. goto _exit0;
  3440. }
  3441. memset(&ll_config, 0, sizeof(struct vxge_config));
  3442. ll_config.tx_steering_type = TX_MULTIQ_STEERING;
  3443. ll_config.intr_type = MSI_X;
  3444. ll_config.napi_weight = NEW_NAPI_WEIGHT;
  3445. ll_config.rth_steering = RTH_STEERING;
  3446. /* get the default configuration parameters */
  3447. vxge_hw_device_config_default_get(device_config);
  3448. /* initialize configuration parameters */
  3449. vxge_device_config_init(device_config, &ll_config.intr_type);
  3450. ret = pci_enable_device(pdev);
  3451. if (ret) {
  3452. vxge_debug_init(VXGE_ERR,
  3453. "%s : can not enable PCI device", __func__);
  3454. goto _exit0;
  3455. }
  3456. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  3457. vxge_debug_ll_config(VXGE_TRACE,
  3458. "%s : using 64bit DMA", __func__);
  3459. high_dma = 1;
  3460. if (pci_set_consistent_dma_mask(pdev,
  3461. DMA_BIT_MASK(64))) {
  3462. vxge_debug_init(VXGE_ERR,
  3463. "%s : unable to obtain 64bit DMA for "
  3464. "consistent allocations", __func__);
  3465. ret = -ENOMEM;
  3466. goto _exit1;
  3467. }
  3468. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  3469. vxge_debug_ll_config(VXGE_TRACE,
  3470. "%s : using 32bit DMA", __func__);
  3471. } else {
  3472. ret = -ENOMEM;
  3473. goto _exit1;
  3474. }
  3475. if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
  3476. vxge_debug_init(VXGE_ERR,
  3477. "%s : request regions failed", __func__);
  3478. ret = -ENODEV;
  3479. goto _exit1;
  3480. }
  3481. pci_set_master(pdev);
  3482. attr.bar0 = pci_ioremap_bar(pdev, 0);
  3483. if (!attr.bar0) {
  3484. vxge_debug_init(VXGE_ERR,
  3485. "%s : cannot remap io memory bar0", __func__);
  3486. ret = -ENODEV;
  3487. goto _exit2;
  3488. }
  3489. vxge_debug_ll_config(VXGE_TRACE,
  3490. "pci ioremap bar0: %p:0x%llx",
  3491. attr.bar0,
  3492. (unsigned long long)pci_resource_start(pdev, 0));
  3493. status = vxge_hw_device_hw_info_get(attr.bar0,
  3494. &ll_config.device_hw_info);
  3495. if (status != VXGE_HW_OK) {
  3496. vxge_debug_init(VXGE_ERR,
  3497. "%s: Reading of hardware info failed."
  3498. "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
  3499. ret = -EINVAL;
  3500. goto _exit3;
  3501. }
  3502. if (ll_config.device_hw_info.fw_version.major !=
  3503. VXGE_DRIVER_FW_VERSION_MAJOR) {
  3504. vxge_debug_init(VXGE_ERR,
  3505. "%s: Incorrect firmware version."
  3506. "Please upgrade the firmware to version 1.x.x",
  3507. VXGE_DRIVER_NAME);
  3508. ret = -EINVAL;
  3509. goto _exit3;
  3510. }
  3511. vpath_mask = ll_config.device_hw_info.vpath_mask;
  3512. if (vpath_mask == 0) {
  3513. vxge_debug_ll_config(VXGE_TRACE,
  3514. "%s: No vpaths available in device", VXGE_DRIVER_NAME);
  3515. ret = -EINVAL;
  3516. goto _exit3;
  3517. }
  3518. vxge_debug_ll_config(VXGE_TRACE,
  3519. "%s:%d Vpath mask = %llx", __func__, __LINE__,
  3520. (unsigned long long)vpath_mask);
  3521. /* Check how many vpaths are available */
  3522. for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3523. if (!((vpath_mask) & vxge_mBIT(i)))
  3524. continue;
  3525. max_vpath_supported++;
  3526. }
  3527. /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
  3528. if ((VXGE_HW_FUNCTION_MODE_SRIOV ==
  3529. ll_config.device_hw_info.function_mode) &&
  3530. (max_config_dev > 1) && (pdev->is_physfn)) {
  3531. ret = pci_enable_sriov(pdev, max_config_dev - 1);
  3532. if (ret)
  3533. vxge_debug_ll_config(VXGE_ERR,
  3534. "Failed to enable SRIOV: %d \n", ret);
  3535. }
  3536. /*
  3537. * Configure vpaths and get driver configured number of vpaths
  3538. * which is less than or equal to the maximum vpaths per function.
  3539. */
  3540. no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, &ll_config);
  3541. if (!no_of_vpath) {
  3542. vxge_debug_ll_config(VXGE_ERR,
  3543. "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
  3544. ret = 0;
  3545. goto _exit3;
  3546. }
  3547. /* Setting driver callbacks */
  3548. attr.uld_callbacks.link_up = vxge_callback_link_up;
  3549. attr.uld_callbacks.link_down = vxge_callback_link_down;
  3550. attr.uld_callbacks.crit_err = vxge_callback_crit_err;
  3551. status = vxge_hw_device_initialize(&hldev, &attr, device_config);
  3552. if (status != VXGE_HW_OK) {
  3553. vxge_debug_init(VXGE_ERR,
  3554. "Failed to initialize device (%d)", status);
  3555. ret = -EINVAL;
  3556. goto _exit3;
  3557. }
  3558. /* if FCS stripping is not disabled in MAC fail driver load */
  3559. if (vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask) != VXGE_HW_OK) {
  3560. vxge_debug_init(VXGE_ERR,
  3561. "%s: FCS stripping is not disabled in MAC"
  3562. " failing driver load", VXGE_DRIVER_NAME);
  3563. ret = -EINVAL;
  3564. goto _exit4;
  3565. }
  3566. vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
  3567. /* set private device info */
  3568. pci_set_drvdata(pdev, hldev);
  3569. ll_config.gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
  3570. ll_config.fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
  3571. ll_config.addr_learn_en = addr_learn_en;
  3572. ll_config.rth_algorithm = RTH_ALG_JENKINS;
  3573. ll_config.rth_hash_type_tcpipv4 = VXGE_HW_RING_HASH_TYPE_TCP_IPV4;
  3574. ll_config.rth_hash_type_ipv4 = VXGE_HW_RING_HASH_TYPE_NONE;
  3575. ll_config.rth_hash_type_tcpipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
  3576. ll_config.rth_hash_type_ipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
  3577. ll_config.rth_hash_type_tcpipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
  3578. ll_config.rth_hash_type_ipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
  3579. ll_config.rth_bkt_sz = RTH_BUCKET_SIZE;
  3580. ll_config.tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
  3581. ll_config.rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
  3582. if (vxge_device_register(hldev, &ll_config, high_dma, no_of_vpath,
  3583. &vdev)) {
  3584. ret = -EINVAL;
  3585. goto _exit4;
  3586. }
  3587. vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
  3588. VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
  3589. vxge_hw_device_trace_level_get(hldev));
  3590. /* set private HW device info */
  3591. hldev->ndev = vdev->ndev;
  3592. vdev->mtu = VXGE_HW_DEFAULT_MTU;
  3593. vdev->bar0 = attr.bar0;
  3594. vdev->max_vpath_supported = max_vpath_supported;
  3595. vdev->no_of_vpath = no_of_vpath;
  3596. /* Virtual Path count */
  3597. for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
  3598. if (!vxge_bVALn(vpath_mask, i, 1))
  3599. continue;
  3600. if (j >= vdev->no_of_vpath)
  3601. break;
  3602. vdev->vpaths[j].is_configured = 1;
  3603. vdev->vpaths[j].device_id = i;
  3604. vdev->vpaths[j].fifo.driver_id = j;
  3605. vdev->vpaths[j].ring.driver_id = j;
  3606. vdev->vpaths[j].vdev = vdev;
  3607. vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
  3608. memcpy((u8 *)vdev->vpaths[j].macaddr,
  3609. (u8 *)ll_config.device_hw_info.mac_addrs[i],
  3610. ETH_ALEN);
  3611. /* Initialize the mac address list header */
  3612. INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
  3613. vdev->vpaths[j].mac_addr_cnt = 0;
  3614. vdev->vpaths[j].mcast_addr_cnt = 0;
  3615. j++;
  3616. }
  3617. vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
  3618. vdev->max_config_port = max_config_port;
  3619. vdev->vlan_tag_strip = vlan_tag_strip;
  3620. /* map the hashing selector table to the configured vpaths */
  3621. for (i = 0; i < vdev->no_of_vpath; i++)
  3622. vdev->vpath_selector[i] = vpath_selector[i];
  3623. macaddr = (u8 *)vdev->vpaths[0].macaddr;
  3624. ll_config.device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
  3625. ll_config.device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
  3626. ll_config.device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
  3627. vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
  3628. vdev->ndev->name, ll_config.device_hw_info.serial_number);
  3629. vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
  3630. vdev->ndev->name, ll_config.device_hw_info.part_number);
  3631. vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
  3632. vdev->ndev->name, ll_config.device_hw_info.product_desc);
  3633. vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
  3634. vdev->ndev->name, macaddr);
  3635. vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
  3636. vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
  3637. vxge_debug_init(VXGE_TRACE,
  3638. "%s: Firmware version : %s Date : %s", vdev->ndev->name,
  3639. ll_config.device_hw_info.fw_version.version,
  3640. ll_config.device_hw_info.fw_date.date);
  3641. if (new_device) {
  3642. switch (ll_config.device_hw_info.function_mode) {
  3643. case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
  3644. vxge_debug_init(VXGE_TRACE,
  3645. "%s: Single Function Mode Enabled", vdev->ndev->name);
  3646. break;
  3647. case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
  3648. vxge_debug_init(VXGE_TRACE,
  3649. "%s: Multi Function Mode Enabled", vdev->ndev->name);
  3650. break;
  3651. case VXGE_HW_FUNCTION_MODE_SRIOV:
  3652. vxge_debug_init(VXGE_TRACE,
  3653. "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
  3654. break;
  3655. case VXGE_HW_FUNCTION_MODE_MRIOV:
  3656. vxge_debug_init(VXGE_TRACE,
  3657. "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
  3658. break;
  3659. }
  3660. }
  3661. vxge_print_parm(vdev, vpath_mask);
  3662. /* Store the fw version for ethttool option */
  3663. strcpy(vdev->fw_version, ll_config.device_hw_info.fw_version.version);
  3664. memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
  3665. memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
  3666. /* Copy the station mac address to the list */
  3667. for (i = 0; i < vdev->no_of_vpath; i++) {
  3668. entry = (struct vxge_mac_addrs *)
  3669. kzalloc(sizeof(struct vxge_mac_addrs),
  3670. GFP_KERNEL);
  3671. if (NULL == entry) {
  3672. vxge_debug_init(VXGE_ERR,
  3673. "%s: mac_addr_list : memory allocation failed",
  3674. vdev->ndev->name);
  3675. ret = -EPERM;
  3676. goto _exit5;
  3677. }
  3678. macaddr = (u8 *)&entry->macaddr;
  3679. memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
  3680. list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
  3681. vdev->vpaths[i].mac_addr_cnt = 1;
  3682. }
  3683. kfree(device_config);
  3684. /*
  3685. * INTA is shared in multi-function mode. This is unlike the INTA
  3686. * implementation in MR mode, where each VH has its own INTA message.
  3687. * - INTA is masked (disabled) as long as at least one function sets
  3688. * its TITAN_MASK_ALL_INT.ALARM bit.
  3689. * - INTA is unmasked (enabled) when all enabled functions have cleared
  3690. * their own TITAN_MASK_ALL_INT.ALARM bit.
  3691. * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
  3692. * Though this driver leaves the top level interrupts unmasked while
  3693. * leaving the required module interrupt bits masked on exit, there
  3694. * could be a rougue driver around that does not follow this procedure
  3695. * resulting in a failure to generate interrupts. The following code is
  3696. * present to prevent such a failure.
  3697. */
  3698. if (ll_config.device_hw_info.function_mode ==
  3699. VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
  3700. if (vdev->config.intr_type == INTA)
  3701. vxge_hw_device_unmask_all(hldev);
  3702. vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
  3703. vdev->ndev->name, __func__, __LINE__);
  3704. vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
  3705. VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
  3706. vxge_hw_device_trace_level_get(hldev));
  3707. return 0;
  3708. _exit5:
  3709. for (i = 0; i < vdev->no_of_vpath; i++)
  3710. vxge_free_mac_add_list(&vdev->vpaths[i]);
  3711. vxge_device_unregister(hldev);
  3712. _exit4:
  3713. pci_disable_sriov(pdev);
  3714. vxge_hw_device_terminate(hldev);
  3715. _exit3:
  3716. iounmap(attr.bar0);
  3717. _exit2:
  3718. pci_release_regions(pdev);
  3719. _exit1:
  3720. pci_disable_device(pdev);
  3721. _exit0:
  3722. kfree(device_config);
  3723. driver_config->config_dev_cnt--;
  3724. pci_set_drvdata(pdev, NULL);
  3725. return ret;
  3726. }
  3727. /**
  3728. * vxge_rem_nic - Free the PCI device
  3729. * @pdev: structure containing the PCI related information of the device.
  3730. * Description: This function is called by the Pci subsystem to release a
  3731. * PCI device and free up all resource held up by the device.
  3732. */
  3733. static void __devexit
  3734. vxge_remove(struct pci_dev *pdev)
  3735. {
  3736. struct __vxge_hw_device *hldev;
  3737. struct vxgedev *vdev = NULL;
  3738. struct net_device *dev;
  3739. int i = 0;
  3740. #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
  3741. (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
  3742. u32 level_trace;
  3743. #endif
  3744. hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
  3745. if (hldev == NULL)
  3746. return;
  3747. dev = hldev->ndev;
  3748. vdev = netdev_priv(dev);
  3749. #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
  3750. (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
  3751. level_trace = vdev->level_trace;
  3752. #endif
  3753. vxge_debug_entryexit(level_trace,
  3754. "%s:%d", __func__, __LINE__);
  3755. vxge_debug_init(level_trace,
  3756. "%s : removing PCI device...", __func__);
  3757. vxge_device_unregister(hldev);
  3758. for (i = 0; i < vdev->no_of_vpath; i++) {
  3759. vxge_free_mac_add_list(&vdev->vpaths[i]);
  3760. vdev->vpaths[i].mcast_addr_cnt = 0;
  3761. vdev->vpaths[i].mac_addr_cnt = 0;
  3762. }
  3763. kfree(vdev->vpaths);
  3764. iounmap(vdev->bar0);
  3765. pci_disable_sriov(pdev);
  3766. /* we are safe to free it now */
  3767. free_netdev(dev);
  3768. vxge_debug_init(level_trace,
  3769. "%s:%d Device unregistered", __func__, __LINE__);
  3770. vxge_hw_device_terminate(hldev);
  3771. pci_disable_device(pdev);
  3772. pci_release_regions(pdev);
  3773. pci_set_drvdata(pdev, NULL);
  3774. vxge_debug_entryexit(level_trace,
  3775. "%s:%d Exiting...", __func__, __LINE__);
  3776. }
  3777. static struct pci_error_handlers vxge_err_handler = {
  3778. .error_detected = vxge_io_error_detected,
  3779. .slot_reset = vxge_io_slot_reset,
  3780. .resume = vxge_io_resume,
  3781. };
  3782. static struct pci_driver vxge_driver = {
  3783. .name = VXGE_DRIVER_NAME,
  3784. .id_table = vxge_id_table,
  3785. .probe = vxge_probe,
  3786. .remove = __devexit_p(vxge_remove),
  3787. #ifdef CONFIG_PM
  3788. .suspend = vxge_pm_suspend,
  3789. .resume = vxge_pm_resume,
  3790. #endif
  3791. .err_handler = &vxge_err_handler,
  3792. };
  3793. static int __init
  3794. vxge_starter(void)
  3795. {
  3796. int ret = 0;
  3797. char version[32];
  3798. snprintf(version, 32, "%s", DRV_VERSION);
  3799. printk(KERN_CRIT "%s: Copyright(c) 2002-2009 Neterion Inc\n",
  3800. VXGE_DRIVER_NAME);
  3801. printk(KERN_CRIT "%s: Driver version: %s\n",
  3802. VXGE_DRIVER_NAME, version);
  3803. verify_bandwidth();
  3804. driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
  3805. if (!driver_config)
  3806. return -ENOMEM;
  3807. ret = pci_register_driver(&vxge_driver);
  3808. if (driver_config->config_dev_cnt &&
  3809. (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
  3810. vxge_debug_init(VXGE_ERR,
  3811. "%s: Configured %d of %d devices",
  3812. VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
  3813. driver_config->total_dev_cnt);
  3814. if (ret)
  3815. kfree(driver_config);
  3816. return ret;
  3817. }
  3818. static void __exit
  3819. vxge_closer(void)
  3820. {
  3821. pci_unregister_driver(&vxge_driver);
  3822. kfree(driver_config);
  3823. }
  3824. module_init(vxge_starter);
  3825. module_exit(vxge_closer);