cxgb4_main.c 139 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233
  1. /*
  2. * This file is part of the Chelsio T4 Ethernet driver for Linux.
  3. *
  4. * Copyright (c) 2003-2016 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  35. #include <linux/bitmap.h>
  36. #include <linux/crc32.h>
  37. #include <linux/ctype.h>
  38. #include <linux/debugfs.h>
  39. #include <linux/err.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/firmware.h>
  42. #include <linux/if.h>
  43. #include <linux/if_vlan.h>
  44. #include <linux/init.h>
  45. #include <linux/log2.h>
  46. #include <linux/mdio.h>
  47. #include <linux/module.h>
  48. #include <linux/moduleparam.h>
  49. #include <linux/mutex.h>
  50. #include <linux/netdevice.h>
  51. #include <linux/pci.h>
  52. #include <linux/aer.h>
  53. #include <linux/rtnetlink.h>
  54. #include <linux/sched.h>
  55. #include <linux/seq_file.h>
  56. #include <linux/sockios.h>
  57. #include <linux/vmalloc.h>
  58. #include <linux/workqueue.h>
  59. #include <net/neighbour.h>
  60. #include <net/netevent.h>
  61. #include <net/addrconf.h>
  62. #include <net/bonding.h>
  63. #include <net/addrconf.h>
  64. #include <linux/uaccess.h>
  65. #include <linux/crash_dump.h>
  66. #include "cxgb4.h"
  67. #include "cxgb4_filter.h"
  68. #include "t4_regs.h"
  69. #include "t4_values.h"
  70. #include "t4_msg.h"
  71. #include "t4fw_api.h"
  72. #include "t4fw_version.h"
  73. #include "cxgb4_dcb.h"
  74. #include "cxgb4_debugfs.h"
  75. #include "clip_tbl.h"
  76. #include "l2t.h"
  77. #include "sched.h"
  78. #include "cxgb4_tc_u32.h"
  79. char cxgb4_driver_name[] = KBUILD_MODNAME;
  80. #ifdef DRV_VERSION
  81. #undef DRV_VERSION
  82. #endif
  83. #define DRV_VERSION "2.0.0-ko"
  84. const char cxgb4_driver_version[] = DRV_VERSION;
  85. #define DRV_DESC "Chelsio T4/T5/T6 Network Driver"
  86. #define DFLT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK | \
  87. NETIF_MSG_TIMER | NETIF_MSG_IFDOWN | NETIF_MSG_IFUP |\
  88. NETIF_MSG_RX_ERR | NETIF_MSG_TX_ERR)
  89. /* Macros needed to support the PCI Device ID Table ...
  90. */
  91. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_BEGIN \
  92. static const struct pci_device_id cxgb4_pci_tbl[] = {
  93. #define CH_PCI_DEVICE_ID_FUNCTION 0x4
  94. /* Include PCI Device IDs for both PF4 and PF0-3 so our PCI probe() routine is
  95. * called for both.
  96. */
  97. #define CH_PCI_DEVICE_ID_FUNCTION2 0x0
  98. #define CH_PCI_ID_TABLE_ENTRY(devid) \
  99. {PCI_VDEVICE(CHELSIO, (devid)), 4}
  100. #define CH_PCI_DEVICE_ID_TABLE_DEFINE_END \
  101. { 0, } \
  102. }
  103. #include "t4_pci_id_tbl.h"
  104. #define FW4_FNAME "cxgb4/t4fw.bin"
  105. #define FW5_FNAME "cxgb4/t5fw.bin"
  106. #define FW6_FNAME "cxgb4/t6fw.bin"
  107. #define FW4_CFNAME "cxgb4/t4-config.txt"
  108. #define FW5_CFNAME "cxgb4/t5-config.txt"
  109. #define FW6_CFNAME "cxgb4/t6-config.txt"
  110. #define PHY_AQ1202_FIRMWARE "cxgb4/aq1202_fw.cld"
  111. #define PHY_BCM84834_FIRMWARE "cxgb4/bcm8483.bin"
  112. #define PHY_AQ1202_DEVICEID 0x4409
  113. #define PHY_BCM84834_DEVICEID 0x4486
  114. MODULE_DESCRIPTION(DRV_DESC);
  115. MODULE_AUTHOR("Chelsio Communications");
  116. MODULE_LICENSE("Dual BSD/GPL");
  117. MODULE_VERSION(DRV_VERSION);
  118. MODULE_DEVICE_TABLE(pci, cxgb4_pci_tbl);
  119. MODULE_FIRMWARE(FW4_FNAME);
  120. MODULE_FIRMWARE(FW5_FNAME);
  121. MODULE_FIRMWARE(FW6_FNAME);
  122. /*
  123. * The driver uses the best interrupt scheme available on a platform in the
  124. * order MSI-X, MSI, legacy INTx interrupts. This parameter determines which
  125. * of these schemes the driver may consider as follows:
  126. *
  127. * msi = 2: choose from among all three options
  128. * msi = 1: only consider MSI and INTx interrupts
  129. * msi = 0: force INTx interrupts
  130. */
  131. static int msi = 2;
  132. module_param(msi, int, 0644);
  133. MODULE_PARM_DESC(msi, "whether to use INTx (0), MSI (1) or MSI-X (2)");
  134. /*
  135. * Normally we tell the chip to deliver Ingress Packets into our DMA buffers
  136. * offset by 2 bytes in order to have the IP headers line up on 4-byte
  137. * boundaries. This is a requirement for many architectures which will throw
  138. * a machine check fault if an attempt is made to access one of the 4-byte IP
  139. * header fields on a non-4-byte boundary. And it's a major performance issue
  140. * even on some architectures which allow it like some implementations of the
  141. * x86 ISA. However, some architectures don't mind this and for some very
  142. * edge-case performance sensitive applications (like forwarding large volumes
  143. * of small packets), setting this DMA offset to 0 will decrease the number of
  144. * PCI-E Bus transfers enough to measurably affect performance.
  145. */
  146. static int rx_dma_offset = 2;
  147. /* TX Queue select used to determine what algorithm to use for selecting TX
  148. * queue. Select between the kernel provided function (select_queue=0) or user
  149. * cxgb_select_queue function (select_queue=1)
  150. *
  151. * Default: select_queue=0
  152. */
  153. static int select_queue;
  154. module_param(select_queue, int, 0644);
  155. MODULE_PARM_DESC(select_queue,
  156. "Select between kernel provided method of selecting or driver method of selecting TX queue. Default is kernel method.");
  157. static struct dentry *cxgb4_debugfs_root;
  158. LIST_HEAD(adapter_list);
  159. DEFINE_MUTEX(uld_mutex);
  160. static void link_report(struct net_device *dev)
  161. {
  162. if (!netif_carrier_ok(dev))
  163. netdev_info(dev, "link down\n");
  164. else {
  165. static const char *fc[] = { "no", "Rx", "Tx", "Tx/Rx" };
  166. const char *s;
  167. const struct port_info *p = netdev_priv(dev);
  168. switch (p->link_cfg.speed) {
  169. case 100:
  170. s = "100Mbps";
  171. break;
  172. case 1000:
  173. s = "1Gbps";
  174. break;
  175. case 10000:
  176. s = "10Gbps";
  177. break;
  178. case 25000:
  179. s = "25Gbps";
  180. break;
  181. case 40000:
  182. s = "40Gbps";
  183. break;
  184. case 100000:
  185. s = "100Gbps";
  186. break;
  187. default:
  188. pr_info("%s: unsupported speed: %d\n",
  189. dev->name, p->link_cfg.speed);
  190. return;
  191. }
  192. netdev_info(dev, "link up, %s, full-duplex, %s PAUSE\n", s,
  193. fc[p->link_cfg.fc]);
  194. }
  195. }
  196. #ifdef CONFIG_CHELSIO_T4_DCB
  197. /* Set up/tear down Data Center Bridging Priority mapping for a net device. */
  198. static void dcb_tx_queue_prio_enable(struct net_device *dev, int enable)
  199. {
  200. struct port_info *pi = netdev_priv(dev);
  201. struct adapter *adap = pi->adapter;
  202. struct sge_eth_txq *txq = &adap->sge.ethtxq[pi->first_qset];
  203. int i;
  204. /* We use a simple mapping of Port TX Queue Index to DCB
  205. * Priority when we're enabling DCB.
  206. */
  207. for (i = 0; i < pi->nqsets; i++, txq++) {
  208. u32 name, value;
  209. int err;
  210. name = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  211. FW_PARAMS_PARAM_X_V(
  212. FW_PARAMS_PARAM_DMAQ_EQ_DCBPRIO_ETH) |
  213. FW_PARAMS_PARAM_YZ_V(txq->q.cntxt_id));
  214. value = enable ? i : 0xffffffff;
  215. /* Since we can be called while atomic (from "interrupt
  216. * level") we need to issue the Set Parameters Commannd
  217. * without sleeping (timeout < 0).
  218. */
  219. err = t4_set_params_timeout(adap, adap->mbox, adap->pf, 0, 1,
  220. &name, &value,
  221. -FW_CMD_MAX_TIMEOUT);
  222. if (err)
  223. dev_err(adap->pdev_dev,
  224. "Can't %s DCB Priority on port %d, TX Queue %d: err=%d\n",
  225. enable ? "set" : "unset", pi->port_id, i, -err);
  226. else
  227. txq->dcb_prio = value;
  228. }
  229. }
  230. static int cxgb4_dcb_enabled(const struct net_device *dev)
  231. {
  232. struct port_info *pi = netdev_priv(dev);
  233. if (!pi->dcb.enabled)
  234. return 0;
  235. return ((pi->dcb.state == CXGB4_DCB_STATE_FW_ALLSYNCED) ||
  236. (pi->dcb.state == CXGB4_DCB_STATE_HOST));
  237. }
  238. #endif /* CONFIG_CHELSIO_T4_DCB */
  239. void t4_os_link_changed(struct adapter *adapter, int port_id, int link_stat)
  240. {
  241. struct net_device *dev = adapter->port[port_id];
  242. /* Skip changes from disabled ports. */
  243. if (netif_running(dev) && link_stat != netif_carrier_ok(dev)) {
  244. if (link_stat)
  245. netif_carrier_on(dev);
  246. else {
  247. #ifdef CONFIG_CHELSIO_T4_DCB
  248. if (cxgb4_dcb_enabled(dev)) {
  249. cxgb4_dcb_state_init(dev);
  250. dcb_tx_queue_prio_enable(dev, false);
  251. }
  252. #endif /* CONFIG_CHELSIO_T4_DCB */
  253. netif_carrier_off(dev);
  254. }
  255. link_report(dev);
  256. }
  257. }
  258. void t4_os_portmod_changed(const struct adapter *adap, int port_id)
  259. {
  260. static const char *mod_str[] = {
  261. NULL, "LR", "SR", "ER", "passive DA", "active DA", "LRM"
  262. };
  263. const struct net_device *dev = adap->port[port_id];
  264. const struct port_info *pi = netdev_priv(dev);
  265. if (pi->mod_type == FW_PORT_MOD_TYPE_NONE)
  266. netdev_info(dev, "port module unplugged\n");
  267. else if (pi->mod_type < ARRAY_SIZE(mod_str))
  268. netdev_info(dev, "%s module inserted\n", mod_str[pi->mod_type]);
  269. else if (pi->mod_type == FW_PORT_MOD_TYPE_NOTSUPPORTED)
  270. netdev_info(dev, "%s: unsupported port module inserted\n",
  271. dev->name);
  272. else if (pi->mod_type == FW_PORT_MOD_TYPE_UNKNOWN)
  273. netdev_info(dev, "%s: unknown port module inserted\n",
  274. dev->name);
  275. else if (pi->mod_type == FW_PORT_MOD_TYPE_ERROR)
  276. netdev_info(dev, "%s: transceiver module error\n", dev->name);
  277. else
  278. netdev_info(dev, "%s: unknown module type %d inserted\n",
  279. dev->name, pi->mod_type);
  280. }
  281. int dbfifo_int_thresh = 10; /* 10 == 640 entry threshold */
  282. module_param(dbfifo_int_thresh, int, 0644);
  283. MODULE_PARM_DESC(dbfifo_int_thresh, "doorbell fifo interrupt threshold");
  284. /*
  285. * usecs to sleep while draining the dbfifo
  286. */
  287. static int dbfifo_drain_delay = 1000;
  288. module_param(dbfifo_drain_delay, int, 0644);
  289. MODULE_PARM_DESC(dbfifo_drain_delay,
  290. "usecs to sleep while draining the dbfifo");
  291. static inline int cxgb4_set_addr_hash(struct port_info *pi)
  292. {
  293. struct adapter *adap = pi->adapter;
  294. u64 vec = 0;
  295. bool ucast = false;
  296. struct hash_mac_addr *entry;
  297. /* Calculate the hash vector for the updated list and program it */
  298. list_for_each_entry(entry, &adap->mac_hlist, list) {
  299. ucast |= is_unicast_ether_addr(entry->addr);
  300. vec |= (1ULL << hash_mac_addr(entry->addr));
  301. }
  302. return t4_set_addr_hash(adap, adap->mbox, pi->viid, ucast,
  303. vec, false);
  304. }
  305. static int cxgb4_mac_sync(struct net_device *netdev, const u8 *mac_addr)
  306. {
  307. struct port_info *pi = netdev_priv(netdev);
  308. struct adapter *adap = pi->adapter;
  309. int ret;
  310. u64 mhash = 0;
  311. u64 uhash = 0;
  312. bool free = false;
  313. bool ucast = is_unicast_ether_addr(mac_addr);
  314. const u8 *maclist[1] = {mac_addr};
  315. struct hash_mac_addr *new_entry;
  316. ret = t4_alloc_mac_filt(adap, adap->mbox, pi->viid, free, 1, maclist,
  317. NULL, ucast ? &uhash : &mhash, false);
  318. if (ret < 0)
  319. goto out;
  320. /* if hash != 0, then add the addr to hash addr list
  321. * so on the end we will calculate the hash for the
  322. * list and program it
  323. */
  324. if (uhash || mhash) {
  325. new_entry = kzalloc(sizeof(*new_entry), GFP_ATOMIC);
  326. if (!new_entry)
  327. return -ENOMEM;
  328. ether_addr_copy(new_entry->addr, mac_addr);
  329. list_add_tail(&new_entry->list, &adap->mac_hlist);
  330. ret = cxgb4_set_addr_hash(pi);
  331. }
  332. out:
  333. return ret < 0 ? ret : 0;
  334. }
  335. static int cxgb4_mac_unsync(struct net_device *netdev, const u8 *mac_addr)
  336. {
  337. struct port_info *pi = netdev_priv(netdev);
  338. struct adapter *adap = pi->adapter;
  339. int ret;
  340. const u8 *maclist[1] = {mac_addr};
  341. struct hash_mac_addr *entry, *tmp;
  342. /* If the MAC address to be removed is in the hash addr
  343. * list, delete it from the list and update hash vector
  344. */
  345. list_for_each_entry_safe(entry, tmp, &adap->mac_hlist, list) {
  346. if (ether_addr_equal(entry->addr, mac_addr)) {
  347. list_del(&entry->list);
  348. kfree(entry);
  349. return cxgb4_set_addr_hash(pi);
  350. }
  351. }
  352. ret = t4_free_mac_filt(adap, adap->mbox, pi->viid, 1, maclist, false);
  353. return ret < 0 ? -EINVAL : 0;
  354. }
  355. /*
  356. * Set Rx properties of a port, such as promiscruity, address filters, and MTU.
  357. * If @mtu is -1 it is left unchanged.
  358. */
  359. static int set_rxmode(struct net_device *dev, int mtu, bool sleep_ok)
  360. {
  361. struct port_info *pi = netdev_priv(dev);
  362. struct adapter *adapter = pi->adapter;
  363. __dev_uc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
  364. __dev_mc_sync(dev, cxgb4_mac_sync, cxgb4_mac_unsync);
  365. return t4_set_rxmode(adapter, adapter->mbox, pi->viid, mtu,
  366. (dev->flags & IFF_PROMISC) ? 1 : 0,
  367. (dev->flags & IFF_ALLMULTI) ? 1 : 0, 1, -1,
  368. sleep_ok);
  369. }
  370. /**
  371. * link_start - enable a port
  372. * @dev: the port to enable
  373. *
  374. * Performs the MAC and PHY actions needed to enable a port.
  375. */
  376. static int link_start(struct net_device *dev)
  377. {
  378. int ret;
  379. struct port_info *pi = netdev_priv(dev);
  380. unsigned int mb = pi->adapter->pf;
  381. /*
  382. * We do not set address filters and promiscuity here, the stack does
  383. * that step explicitly.
  384. */
  385. ret = t4_set_rxmode(pi->adapter, mb, pi->viid, dev->mtu, -1, -1, -1,
  386. !!(dev->features & NETIF_F_HW_VLAN_CTAG_RX), true);
  387. if (ret == 0) {
  388. ret = t4_change_mac(pi->adapter, mb, pi->viid,
  389. pi->xact_addr_filt, dev->dev_addr, true,
  390. true);
  391. if (ret >= 0) {
  392. pi->xact_addr_filt = ret;
  393. ret = 0;
  394. }
  395. }
  396. if (ret == 0)
  397. ret = t4_link_l1cfg(pi->adapter, mb, pi->tx_chan,
  398. &pi->link_cfg);
  399. if (ret == 0) {
  400. local_bh_disable();
  401. ret = t4_enable_vi_params(pi->adapter, mb, pi->viid, true,
  402. true, CXGB4_DCB_ENABLED);
  403. local_bh_enable();
  404. }
  405. return ret;
  406. }
  407. #ifdef CONFIG_CHELSIO_T4_DCB
  408. /* Handle a Data Center Bridging update message from the firmware. */
  409. static void dcb_rpl(struct adapter *adap, const struct fw_port_cmd *pcmd)
  410. {
  411. int port = FW_PORT_CMD_PORTID_G(ntohl(pcmd->op_to_portid));
  412. struct net_device *dev = adap->port[adap->chan_map[port]];
  413. int old_dcb_enabled = cxgb4_dcb_enabled(dev);
  414. int new_dcb_enabled;
  415. cxgb4_dcb_handle_fw_update(adap, pcmd);
  416. new_dcb_enabled = cxgb4_dcb_enabled(dev);
  417. /* If the DCB has become enabled or disabled on the port then we're
  418. * going to need to set up/tear down DCB Priority parameters for the
  419. * TX Queues associated with the port.
  420. */
  421. if (new_dcb_enabled != old_dcb_enabled)
  422. dcb_tx_queue_prio_enable(dev, new_dcb_enabled);
  423. }
  424. #endif /* CONFIG_CHELSIO_T4_DCB */
  425. /* Response queue handler for the FW event queue.
  426. */
  427. static int fwevtq_handler(struct sge_rspq *q, const __be64 *rsp,
  428. const struct pkt_gl *gl)
  429. {
  430. u8 opcode = ((const struct rss_header *)rsp)->opcode;
  431. rsp++; /* skip RSS header */
  432. /* FW can send EGR_UPDATEs encapsulated in a CPL_FW4_MSG.
  433. */
  434. if (unlikely(opcode == CPL_FW4_MSG &&
  435. ((const struct cpl_fw4_msg *)rsp)->type == FW_TYPE_RSSCPL)) {
  436. rsp++;
  437. opcode = ((const struct rss_header *)rsp)->opcode;
  438. rsp++;
  439. if (opcode != CPL_SGE_EGR_UPDATE) {
  440. dev_err(q->adap->pdev_dev, "unexpected FW4/CPL %#x on FW event queue\n"
  441. , opcode);
  442. goto out;
  443. }
  444. }
  445. if (likely(opcode == CPL_SGE_EGR_UPDATE)) {
  446. const struct cpl_sge_egr_update *p = (void *)rsp;
  447. unsigned int qid = EGR_QID_G(ntohl(p->opcode_qid));
  448. struct sge_txq *txq;
  449. txq = q->adap->sge.egr_map[qid - q->adap->sge.egr_start];
  450. txq->restarts++;
  451. if (txq->q_type == CXGB4_TXQ_ETH) {
  452. struct sge_eth_txq *eq;
  453. eq = container_of(txq, struct sge_eth_txq, q);
  454. netif_tx_wake_queue(eq->txq);
  455. } else {
  456. struct sge_uld_txq *oq;
  457. oq = container_of(txq, struct sge_uld_txq, q);
  458. tasklet_schedule(&oq->qresume_tsk);
  459. }
  460. } else if (opcode == CPL_FW6_MSG || opcode == CPL_FW4_MSG) {
  461. const struct cpl_fw6_msg *p = (void *)rsp;
  462. #ifdef CONFIG_CHELSIO_T4_DCB
  463. const struct fw_port_cmd *pcmd = (const void *)p->data;
  464. unsigned int cmd = FW_CMD_OP_G(ntohl(pcmd->op_to_portid));
  465. unsigned int action =
  466. FW_PORT_CMD_ACTION_G(ntohl(pcmd->action_to_len16));
  467. if (cmd == FW_PORT_CMD &&
  468. action == FW_PORT_ACTION_GET_PORT_INFO) {
  469. int port = FW_PORT_CMD_PORTID_G(
  470. be32_to_cpu(pcmd->op_to_portid));
  471. struct net_device *dev =
  472. q->adap->port[q->adap->chan_map[port]];
  473. int state_input = ((pcmd->u.info.dcbxdis_pkd &
  474. FW_PORT_CMD_DCBXDIS_F)
  475. ? CXGB4_DCB_INPUT_FW_DISABLED
  476. : CXGB4_DCB_INPUT_FW_ENABLED);
  477. cxgb4_dcb_state_fsm(dev, state_input);
  478. }
  479. if (cmd == FW_PORT_CMD &&
  480. action == FW_PORT_ACTION_L2_DCB_CFG)
  481. dcb_rpl(q->adap, pcmd);
  482. else
  483. #endif
  484. if (p->type == 0)
  485. t4_handle_fw_rpl(q->adap, p->data);
  486. } else if (opcode == CPL_L2T_WRITE_RPL) {
  487. const struct cpl_l2t_write_rpl *p = (void *)rsp;
  488. do_l2t_write_rpl(q->adap, p);
  489. } else if (opcode == CPL_SET_TCB_RPL) {
  490. const struct cpl_set_tcb_rpl *p = (void *)rsp;
  491. filter_rpl(q->adap, p);
  492. } else
  493. dev_err(q->adap->pdev_dev,
  494. "unexpected CPL %#x on FW event queue\n", opcode);
  495. out:
  496. return 0;
  497. }
  498. static void disable_msi(struct adapter *adapter)
  499. {
  500. if (adapter->flags & USING_MSIX) {
  501. pci_disable_msix(adapter->pdev);
  502. adapter->flags &= ~USING_MSIX;
  503. } else if (adapter->flags & USING_MSI) {
  504. pci_disable_msi(adapter->pdev);
  505. adapter->flags &= ~USING_MSI;
  506. }
  507. }
  508. /*
  509. * Interrupt handler for non-data events used with MSI-X.
  510. */
  511. static irqreturn_t t4_nondata_intr(int irq, void *cookie)
  512. {
  513. struct adapter *adap = cookie;
  514. u32 v = t4_read_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A));
  515. if (v & PFSW_F) {
  516. adap->swintr = 1;
  517. t4_write_reg(adap, MYPF_REG(PL_PF_INT_CAUSE_A), v);
  518. }
  519. if (adap->flags & MASTER_PF)
  520. t4_slow_intr_handler(adap);
  521. return IRQ_HANDLED;
  522. }
  523. /*
  524. * Name the MSI-X interrupts.
  525. */
  526. static void name_msix_vecs(struct adapter *adap)
  527. {
  528. int i, j, msi_idx = 2, n = sizeof(adap->msix_info[0].desc);
  529. /* non-data interrupts */
  530. snprintf(adap->msix_info[0].desc, n, "%s", adap->port[0]->name);
  531. /* FW events */
  532. snprintf(adap->msix_info[1].desc, n, "%s-FWeventq",
  533. adap->port[0]->name);
  534. /* Ethernet queues */
  535. for_each_port(adap, j) {
  536. struct net_device *d = adap->port[j];
  537. const struct port_info *pi = netdev_priv(d);
  538. for (i = 0; i < pi->nqsets; i++, msi_idx++)
  539. snprintf(adap->msix_info[msi_idx].desc, n, "%s-Rx%d",
  540. d->name, i);
  541. }
  542. }
  543. static int request_msix_queue_irqs(struct adapter *adap)
  544. {
  545. struct sge *s = &adap->sge;
  546. int err, ethqidx;
  547. int msi_index = 2;
  548. err = request_irq(adap->msix_info[1].vec, t4_sge_intr_msix, 0,
  549. adap->msix_info[1].desc, &s->fw_evtq);
  550. if (err)
  551. return err;
  552. for_each_ethrxq(s, ethqidx) {
  553. err = request_irq(adap->msix_info[msi_index].vec,
  554. t4_sge_intr_msix, 0,
  555. adap->msix_info[msi_index].desc,
  556. &s->ethrxq[ethqidx].rspq);
  557. if (err)
  558. goto unwind;
  559. msi_index++;
  560. }
  561. return 0;
  562. unwind:
  563. while (--ethqidx >= 0)
  564. free_irq(adap->msix_info[--msi_index].vec,
  565. &s->ethrxq[ethqidx].rspq);
  566. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  567. return err;
  568. }
  569. static void free_msix_queue_irqs(struct adapter *adap)
  570. {
  571. int i, msi_index = 2;
  572. struct sge *s = &adap->sge;
  573. free_irq(adap->msix_info[1].vec, &s->fw_evtq);
  574. for_each_ethrxq(s, i)
  575. free_irq(adap->msix_info[msi_index++].vec, &s->ethrxq[i].rspq);
  576. }
  577. /**
  578. * cxgb4_write_rss - write the RSS table for a given port
  579. * @pi: the port
  580. * @queues: array of queue indices for RSS
  581. *
  582. * Sets up the portion of the HW RSS table for the port's VI to distribute
  583. * packets to the Rx queues in @queues.
  584. * Should never be called before setting up sge eth rx queues
  585. */
  586. int cxgb4_write_rss(const struct port_info *pi, const u16 *queues)
  587. {
  588. u16 *rss;
  589. int i, err;
  590. struct adapter *adapter = pi->adapter;
  591. const struct sge_eth_rxq *rxq;
  592. rxq = &adapter->sge.ethrxq[pi->first_qset];
  593. rss = kmalloc(pi->rss_size * sizeof(u16), GFP_KERNEL);
  594. if (!rss)
  595. return -ENOMEM;
  596. /* map the queue indices to queue ids */
  597. for (i = 0; i < pi->rss_size; i++, queues++)
  598. rss[i] = rxq[*queues].rspq.abs_id;
  599. err = t4_config_rss_range(adapter, adapter->pf, pi->viid, 0,
  600. pi->rss_size, rss, pi->rss_size);
  601. /* If Tunnel All Lookup isn't specified in the global RSS
  602. * Configuration, then we need to specify a default Ingress
  603. * Queue for any ingress packets which aren't hashed. We'll
  604. * use our first ingress queue ...
  605. */
  606. if (!err)
  607. err = t4_config_vi_rss(adapter, adapter->mbox, pi->viid,
  608. FW_RSS_VI_CONFIG_CMD_IP6FOURTUPEN_F |
  609. FW_RSS_VI_CONFIG_CMD_IP6TWOTUPEN_F |
  610. FW_RSS_VI_CONFIG_CMD_IP4FOURTUPEN_F |
  611. FW_RSS_VI_CONFIG_CMD_IP4TWOTUPEN_F |
  612. FW_RSS_VI_CONFIG_CMD_UDPEN_F,
  613. rss[0]);
  614. kfree(rss);
  615. return err;
  616. }
  617. /**
  618. * setup_rss - configure RSS
  619. * @adap: the adapter
  620. *
  621. * Sets up RSS for each port.
  622. */
  623. static int setup_rss(struct adapter *adap)
  624. {
  625. int i, j, err;
  626. for_each_port(adap, i) {
  627. const struct port_info *pi = adap2pinfo(adap, i);
  628. /* Fill default values with equal distribution */
  629. for (j = 0; j < pi->rss_size; j++)
  630. pi->rss[j] = j % pi->nqsets;
  631. err = cxgb4_write_rss(pi, pi->rss);
  632. if (err)
  633. return err;
  634. }
  635. return 0;
  636. }
  637. /*
  638. * Return the channel of the ingress queue with the given qid.
  639. */
  640. static unsigned int rxq_to_chan(const struct sge *p, unsigned int qid)
  641. {
  642. qid -= p->ingr_start;
  643. return netdev2pinfo(p->ingr_map[qid]->netdev)->tx_chan;
  644. }
  645. /*
  646. * Wait until all NAPI handlers are descheduled.
  647. */
  648. static void quiesce_rx(struct adapter *adap)
  649. {
  650. int i;
  651. for (i = 0; i < adap->sge.ingr_sz; i++) {
  652. struct sge_rspq *q = adap->sge.ingr_map[i];
  653. if (q && q->handler)
  654. napi_disable(&q->napi);
  655. }
  656. }
  657. /* Disable interrupt and napi handler */
  658. static void disable_interrupts(struct adapter *adap)
  659. {
  660. if (adap->flags & FULL_INIT_DONE) {
  661. t4_intr_disable(adap);
  662. if (adap->flags & USING_MSIX) {
  663. free_msix_queue_irqs(adap);
  664. free_irq(adap->msix_info[0].vec, adap);
  665. } else {
  666. free_irq(adap->pdev->irq, adap);
  667. }
  668. quiesce_rx(adap);
  669. }
  670. }
  671. /*
  672. * Enable NAPI scheduling and interrupt generation for all Rx queues.
  673. */
  674. static void enable_rx(struct adapter *adap)
  675. {
  676. int i;
  677. for (i = 0; i < adap->sge.ingr_sz; i++) {
  678. struct sge_rspq *q = adap->sge.ingr_map[i];
  679. if (!q)
  680. continue;
  681. if (q->handler)
  682. napi_enable(&q->napi);
  683. /* 0-increment GTS to start the timer and enable interrupts */
  684. t4_write_reg(adap, MYPF_REG(SGE_PF_GTS_A),
  685. SEINTARM_V(q->intr_params) |
  686. INGRESSQID_V(q->cntxt_id));
  687. }
  688. }
  689. static int setup_fw_sge_queues(struct adapter *adap)
  690. {
  691. struct sge *s = &adap->sge;
  692. int err = 0;
  693. bitmap_zero(s->starving_fl, s->egr_sz);
  694. bitmap_zero(s->txq_maperr, s->egr_sz);
  695. if (adap->flags & USING_MSIX)
  696. adap->msi_idx = 1; /* vector 0 is for non-queue interrupts */
  697. else {
  698. err = t4_sge_alloc_rxq(adap, &s->intrq, false, adap->port[0], 0,
  699. NULL, NULL, NULL, -1);
  700. if (err)
  701. return err;
  702. adap->msi_idx = -((int)s->intrq.abs_id + 1);
  703. }
  704. err = t4_sge_alloc_rxq(adap, &s->fw_evtq, true, adap->port[0],
  705. adap->msi_idx, NULL, fwevtq_handler, NULL, -1);
  706. if (err)
  707. t4_free_sge_resources(adap);
  708. return err;
  709. }
  710. /**
  711. * setup_sge_queues - configure SGE Tx/Rx/response queues
  712. * @adap: the adapter
  713. *
  714. * Determines how many sets of SGE queues to use and initializes them.
  715. * We support multiple queue sets per port if we have MSI-X, otherwise
  716. * just one queue set per port.
  717. */
  718. static int setup_sge_queues(struct adapter *adap)
  719. {
  720. int err, i, j;
  721. struct sge *s = &adap->sge;
  722. struct sge_uld_rxq_info *rxq_info = s->uld_rxq_info[CXGB4_ULD_RDMA];
  723. unsigned int cmplqid = 0;
  724. for_each_port(adap, i) {
  725. struct net_device *dev = adap->port[i];
  726. struct port_info *pi = netdev_priv(dev);
  727. struct sge_eth_rxq *q = &s->ethrxq[pi->first_qset];
  728. struct sge_eth_txq *t = &s->ethtxq[pi->first_qset];
  729. for (j = 0; j < pi->nqsets; j++, q++) {
  730. if (adap->msi_idx > 0)
  731. adap->msi_idx++;
  732. err = t4_sge_alloc_rxq(adap, &q->rspq, false, dev,
  733. adap->msi_idx, &q->fl,
  734. t4_ethrx_handler,
  735. NULL,
  736. t4_get_mps_bg_map(adap,
  737. pi->tx_chan));
  738. if (err)
  739. goto freeout;
  740. q->rspq.idx = j;
  741. memset(&q->stats, 0, sizeof(q->stats));
  742. }
  743. for (j = 0; j < pi->nqsets; j++, t++) {
  744. err = t4_sge_alloc_eth_txq(adap, t, dev,
  745. netdev_get_tx_queue(dev, j),
  746. s->fw_evtq.cntxt_id);
  747. if (err)
  748. goto freeout;
  749. }
  750. }
  751. for_each_port(adap, i) {
  752. /* Note that cmplqid below is 0 if we don't
  753. * have RDMA queues, and that's the right value.
  754. */
  755. if (rxq_info)
  756. cmplqid = rxq_info->uldrxq[i].rspq.cntxt_id;
  757. err = t4_sge_alloc_ctrl_txq(adap, &s->ctrlq[i], adap->port[i],
  758. s->fw_evtq.cntxt_id, cmplqid);
  759. if (err)
  760. goto freeout;
  761. }
  762. t4_write_reg(adap, is_t4(adap->params.chip) ?
  763. MPS_TRC_RSS_CONTROL_A :
  764. MPS_T5_TRC_RSS_CONTROL_A,
  765. RSSCONTROL_V(netdev2pinfo(adap->port[0])->tx_chan) |
  766. QUEUENUMBER_V(s->ethrxq[0].rspq.abs_id));
  767. return 0;
  768. freeout:
  769. t4_free_sge_resources(adap);
  770. return err;
  771. }
  772. /*
  773. * Allocate a chunk of memory using kmalloc or, if that fails, vmalloc.
  774. * The allocated memory is cleared.
  775. */
  776. void *t4_alloc_mem(size_t size)
  777. {
  778. void *p = kzalloc(size, GFP_KERNEL | __GFP_NOWARN);
  779. if (!p)
  780. p = vzalloc(size);
  781. return p;
  782. }
  783. /*
  784. * Free memory allocated through alloc_mem().
  785. */
  786. void t4_free_mem(void *addr)
  787. {
  788. kvfree(addr);
  789. }
  790. static u16 cxgb_select_queue(struct net_device *dev, struct sk_buff *skb,
  791. void *accel_priv, select_queue_fallback_t fallback)
  792. {
  793. int txq;
  794. #ifdef CONFIG_CHELSIO_T4_DCB
  795. /* If a Data Center Bridging has been successfully negotiated on this
  796. * link then we'll use the skb's priority to map it to a TX Queue.
  797. * The skb's priority is determined via the VLAN Tag Priority Code
  798. * Point field.
  799. */
  800. if (cxgb4_dcb_enabled(dev)) {
  801. u16 vlan_tci;
  802. int err;
  803. err = vlan_get_tag(skb, &vlan_tci);
  804. if (unlikely(err)) {
  805. if (net_ratelimit())
  806. netdev_warn(dev,
  807. "TX Packet without VLAN Tag on DCB Link\n");
  808. txq = 0;
  809. } else {
  810. txq = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
  811. #ifdef CONFIG_CHELSIO_T4_FCOE
  812. if (skb->protocol == htons(ETH_P_FCOE))
  813. txq = skb->priority & 0x7;
  814. #endif /* CONFIG_CHELSIO_T4_FCOE */
  815. }
  816. return txq;
  817. }
  818. #endif /* CONFIG_CHELSIO_T4_DCB */
  819. if (select_queue) {
  820. txq = (skb_rx_queue_recorded(skb)
  821. ? skb_get_rx_queue(skb)
  822. : smp_processor_id());
  823. while (unlikely(txq >= dev->real_num_tx_queues))
  824. txq -= dev->real_num_tx_queues;
  825. return txq;
  826. }
  827. return fallback(dev, skb) % dev->real_num_tx_queues;
  828. }
  829. static int closest_timer(const struct sge *s, int time)
  830. {
  831. int i, delta, match = 0, min_delta = INT_MAX;
  832. for (i = 0; i < ARRAY_SIZE(s->timer_val); i++) {
  833. delta = time - s->timer_val[i];
  834. if (delta < 0)
  835. delta = -delta;
  836. if (delta < min_delta) {
  837. min_delta = delta;
  838. match = i;
  839. }
  840. }
  841. return match;
  842. }
  843. static int closest_thres(const struct sge *s, int thres)
  844. {
  845. int i, delta, match = 0, min_delta = INT_MAX;
  846. for (i = 0; i < ARRAY_SIZE(s->counter_val); i++) {
  847. delta = thres - s->counter_val[i];
  848. if (delta < 0)
  849. delta = -delta;
  850. if (delta < min_delta) {
  851. min_delta = delta;
  852. match = i;
  853. }
  854. }
  855. return match;
  856. }
  857. /**
  858. * cxgb4_set_rspq_intr_params - set a queue's interrupt holdoff parameters
  859. * @q: the Rx queue
  860. * @us: the hold-off time in us, or 0 to disable timer
  861. * @cnt: the hold-off packet count, or 0 to disable counter
  862. *
  863. * Sets an Rx queue's interrupt hold-off time and packet count. At least
  864. * one of the two needs to be enabled for the queue to generate interrupts.
  865. */
  866. int cxgb4_set_rspq_intr_params(struct sge_rspq *q,
  867. unsigned int us, unsigned int cnt)
  868. {
  869. struct adapter *adap = q->adap;
  870. if ((us | cnt) == 0)
  871. cnt = 1;
  872. if (cnt) {
  873. int err;
  874. u32 v, new_idx;
  875. new_idx = closest_thres(&adap->sge, cnt);
  876. if (q->desc && q->pktcnt_idx != new_idx) {
  877. /* the queue has already been created, update it */
  878. v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DMAQ) |
  879. FW_PARAMS_PARAM_X_V(
  880. FW_PARAMS_PARAM_DMAQ_IQ_INTCNTTHRESH) |
  881. FW_PARAMS_PARAM_YZ_V(q->cntxt_id);
  882. err = t4_set_params(adap, adap->mbox, adap->pf, 0, 1,
  883. &v, &new_idx);
  884. if (err)
  885. return err;
  886. }
  887. q->pktcnt_idx = new_idx;
  888. }
  889. us = us == 0 ? 6 : closest_timer(&adap->sge, us);
  890. q->intr_params = QINTR_TIMER_IDX_V(us) | QINTR_CNT_EN_V(cnt > 0);
  891. return 0;
  892. }
  893. static int cxgb_set_features(struct net_device *dev, netdev_features_t features)
  894. {
  895. const struct port_info *pi = netdev_priv(dev);
  896. netdev_features_t changed = dev->features ^ features;
  897. int err;
  898. if (!(changed & NETIF_F_HW_VLAN_CTAG_RX))
  899. return 0;
  900. err = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, -1,
  901. -1, -1, -1,
  902. !!(features & NETIF_F_HW_VLAN_CTAG_RX), true);
  903. if (unlikely(err))
  904. dev->features = features ^ NETIF_F_HW_VLAN_CTAG_RX;
  905. return err;
  906. }
  907. static int setup_debugfs(struct adapter *adap)
  908. {
  909. if (IS_ERR_OR_NULL(adap->debugfs_root))
  910. return -1;
  911. #ifdef CONFIG_DEBUG_FS
  912. t4_setup_debugfs(adap);
  913. #endif
  914. return 0;
  915. }
  916. /*
  917. * upper-layer driver support
  918. */
  919. /*
  920. * Allocate an active-open TID and set it to the supplied value.
  921. */
  922. int cxgb4_alloc_atid(struct tid_info *t, void *data)
  923. {
  924. int atid = -1;
  925. spin_lock_bh(&t->atid_lock);
  926. if (t->afree) {
  927. union aopen_entry *p = t->afree;
  928. atid = (p - t->atid_tab) + t->atid_base;
  929. t->afree = p->next;
  930. p->data = data;
  931. t->atids_in_use++;
  932. }
  933. spin_unlock_bh(&t->atid_lock);
  934. return atid;
  935. }
  936. EXPORT_SYMBOL(cxgb4_alloc_atid);
  937. /*
  938. * Release an active-open TID.
  939. */
  940. void cxgb4_free_atid(struct tid_info *t, unsigned int atid)
  941. {
  942. union aopen_entry *p = &t->atid_tab[atid - t->atid_base];
  943. spin_lock_bh(&t->atid_lock);
  944. p->next = t->afree;
  945. t->afree = p;
  946. t->atids_in_use--;
  947. spin_unlock_bh(&t->atid_lock);
  948. }
  949. EXPORT_SYMBOL(cxgb4_free_atid);
  950. /*
  951. * Allocate a server TID and set it to the supplied value.
  952. */
  953. int cxgb4_alloc_stid(struct tid_info *t, int family, void *data)
  954. {
  955. int stid;
  956. spin_lock_bh(&t->stid_lock);
  957. if (family == PF_INET) {
  958. stid = find_first_zero_bit(t->stid_bmap, t->nstids);
  959. if (stid < t->nstids)
  960. __set_bit(stid, t->stid_bmap);
  961. else
  962. stid = -1;
  963. } else {
  964. stid = bitmap_find_free_region(t->stid_bmap, t->nstids, 1);
  965. if (stid < 0)
  966. stid = -1;
  967. }
  968. if (stid >= 0) {
  969. t->stid_tab[stid].data = data;
  970. stid += t->stid_base;
  971. /* IPv6 requires max of 520 bits or 16 cells in TCAM
  972. * This is equivalent to 4 TIDs. With CLIP enabled it
  973. * needs 2 TIDs.
  974. */
  975. if (family == PF_INET)
  976. t->stids_in_use++;
  977. else
  978. t->stids_in_use += 2;
  979. }
  980. spin_unlock_bh(&t->stid_lock);
  981. return stid;
  982. }
  983. EXPORT_SYMBOL(cxgb4_alloc_stid);
  984. /* Allocate a server filter TID and set it to the supplied value.
  985. */
  986. int cxgb4_alloc_sftid(struct tid_info *t, int family, void *data)
  987. {
  988. int stid;
  989. spin_lock_bh(&t->stid_lock);
  990. if (family == PF_INET) {
  991. stid = find_next_zero_bit(t->stid_bmap,
  992. t->nstids + t->nsftids, t->nstids);
  993. if (stid < (t->nstids + t->nsftids))
  994. __set_bit(stid, t->stid_bmap);
  995. else
  996. stid = -1;
  997. } else {
  998. stid = -1;
  999. }
  1000. if (stid >= 0) {
  1001. t->stid_tab[stid].data = data;
  1002. stid -= t->nstids;
  1003. stid += t->sftid_base;
  1004. t->sftids_in_use++;
  1005. }
  1006. spin_unlock_bh(&t->stid_lock);
  1007. return stid;
  1008. }
  1009. EXPORT_SYMBOL(cxgb4_alloc_sftid);
  1010. /* Release a server TID.
  1011. */
  1012. void cxgb4_free_stid(struct tid_info *t, unsigned int stid, int family)
  1013. {
  1014. /* Is it a server filter TID? */
  1015. if (t->nsftids && (stid >= t->sftid_base)) {
  1016. stid -= t->sftid_base;
  1017. stid += t->nstids;
  1018. } else {
  1019. stid -= t->stid_base;
  1020. }
  1021. spin_lock_bh(&t->stid_lock);
  1022. if (family == PF_INET)
  1023. __clear_bit(stid, t->stid_bmap);
  1024. else
  1025. bitmap_release_region(t->stid_bmap, stid, 1);
  1026. t->stid_tab[stid].data = NULL;
  1027. if (stid < t->nstids) {
  1028. if (family == PF_INET)
  1029. t->stids_in_use--;
  1030. else
  1031. t->stids_in_use -= 2;
  1032. } else {
  1033. t->sftids_in_use--;
  1034. }
  1035. spin_unlock_bh(&t->stid_lock);
  1036. }
  1037. EXPORT_SYMBOL(cxgb4_free_stid);
  1038. /*
  1039. * Populate a TID_RELEASE WR. Caller must properly size the skb.
  1040. */
  1041. static void mk_tid_release(struct sk_buff *skb, unsigned int chan,
  1042. unsigned int tid)
  1043. {
  1044. struct cpl_tid_release *req;
  1045. set_wr_txq(skb, CPL_PRIORITY_SETUP, chan);
  1046. req = (struct cpl_tid_release *)__skb_put(skb, sizeof(*req));
  1047. INIT_TP_WR(req, tid);
  1048. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, tid));
  1049. }
  1050. /*
  1051. * Queue a TID release request and if necessary schedule a work queue to
  1052. * process it.
  1053. */
  1054. static void cxgb4_queue_tid_release(struct tid_info *t, unsigned int chan,
  1055. unsigned int tid)
  1056. {
  1057. void **p = &t->tid_tab[tid];
  1058. struct adapter *adap = container_of(t, struct adapter, tids);
  1059. spin_lock_bh(&adap->tid_release_lock);
  1060. *p = adap->tid_release_head;
  1061. /* Low 2 bits encode the Tx channel number */
  1062. adap->tid_release_head = (void **)((uintptr_t)p | chan);
  1063. if (!adap->tid_release_task_busy) {
  1064. adap->tid_release_task_busy = true;
  1065. queue_work(adap->workq, &adap->tid_release_task);
  1066. }
  1067. spin_unlock_bh(&adap->tid_release_lock);
  1068. }
  1069. /*
  1070. * Process the list of pending TID release requests.
  1071. */
  1072. static void process_tid_release_list(struct work_struct *work)
  1073. {
  1074. struct sk_buff *skb;
  1075. struct adapter *adap;
  1076. adap = container_of(work, struct adapter, tid_release_task);
  1077. spin_lock_bh(&adap->tid_release_lock);
  1078. while (adap->tid_release_head) {
  1079. void **p = adap->tid_release_head;
  1080. unsigned int chan = (uintptr_t)p & 3;
  1081. p = (void *)p - chan;
  1082. adap->tid_release_head = *p;
  1083. *p = NULL;
  1084. spin_unlock_bh(&adap->tid_release_lock);
  1085. while (!(skb = alloc_skb(sizeof(struct cpl_tid_release),
  1086. GFP_KERNEL)))
  1087. schedule_timeout_uninterruptible(1);
  1088. mk_tid_release(skb, chan, p - adap->tids.tid_tab);
  1089. t4_ofld_send(adap, skb);
  1090. spin_lock_bh(&adap->tid_release_lock);
  1091. }
  1092. adap->tid_release_task_busy = false;
  1093. spin_unlock_bh(&adap->tid_release_lock);
  1094. }
  1095. /*
  1096. * Release a TID and inform HW. If we are unable to allocate the release
  1097. * message we defer to a work queue.
  1098. */
  1099. void cxgb4_remove_tid(struct tid_info *t, unsigned int chan, unsigned int tid)
  1100. {
  1101. struct sk_buff *skb;
  1102. struct adapter *adap = container_of(t, struct adapter, tids);
  1103. WARN_ON(tid >= t->ntids);
  1104. if (t->tid_tab[tid]) {
  1105. t->tid_tab[tid] = NULL;
  1106. if (t->hash_base && (tid >= t->hash_base))
  1107. atomic_dec(&t->hash_tids_in_use);
  1108. else
  1109. atomic_dec(&t->tids_in_use);
  1110. }
  1111. skb = alloc_skb(sizeof(struct cpl_tid_release), GFP_ATOMIC);
  1112. if (likely(skb)) {
  1113. mk_tid_release(skb, chan, tid);
  1114. t4_ofld_send(adap, skb);
  1115. } else
  1116. cxgb4_queue_tid_release(t, chan, tid);
  1117. }
  1118. EXPORT_SYMBOL(cxgb4_remove_tid);
  1119. /*
  1120. * Allocate and initialize the TID tables. Returns 0 on success.
  1121. */
  1122. static int tid_init(struct tid_info *t)
  1123. {
  1124. struct adapter *adap = container_of(t, struct adapter, tids);
  1125. unsigned int max_ftids = t->nftids + t->nsftids;
  1126. unsigned int natids = t->natids;
  1127. unsigned int stid_bmap_size;
  1128. unsigned int ftid_bmap_size;
  1129. size_t size;
  1130. stid_bmap_size = BITS_TO_LONGS(t->nstids + t->nsftids);
  1131. ftid_bmap_size = BITS_TO_LONGS(t->nftids);
  1132. size = t->ntids * sizeof(*t->tid_tab) +
  1133. natids * sizeof(*t->atid_tab) +
  1134. t->nstids * sizeof(*t->stid_tab) +
  1135. t->nsftids * sizeof(*t->stid_tab) +
  1136. stid_bmap_size * sizeof(long) +
  1137. max_ftids * sizeof(*t->ftid_tab) +
  1138. ftid_bmap_size * sizeof(long);
  1139. t->tid_tab = t4_alloc_mem(size);
  1140. if (!t->tid_tab)
  1141. return -ENOMEM;
  1142. t->atid_tab = (union aopen_entry *)&t->tid_tab[t->ntids];
  1143. t->stid_tab = (struct serv_entry *)&t->atid_tab[natids];
  1144. t->stid_bmap = (unsigned long *)&t->stid_tab[t->nstids + t->nsftids];
  1145. t->ftid_tab = (struct filter_entry *)&t->stid_bmap[stid_bmap_size];
  1146. t->ftid_bmap = (unsigned long *)&t->ftid_tab[max_ftids];
  1147. spin_lock_init(&t->stid_lock);
  1148. spin_lock_init(&t->atid_lock);
  1149. spin_lock_init(&t->ftid_lock);
  1150. t->stids_in_use = 0;
  1151. t->sftids_in_use = 0;
  1152. t->afree = NULL;
  1153. t->atids_in_use = 0;
  1154. atomic_set(&t->tids_in_use, 0);
  1155. atomic_set(&t->hash_tids_in_use, 0);
  1156. /* Setup the free list for atid_tab and clear the stid bitmap. */
  1157. if (natids) {
  1158. while (--natids)
  1159. t->atid_tab[natids - 1].next = &t->atid_tab[natids];
  1160. t->afree = t->atid_tab;
  1161. }
  1162. if (is_offload(adap)) {
  1163. bitmap_zero(t->stid_bmap, t->nstids + t->nsftids);
  1164. /* Reserve stid 0 for T4/T5 adapters */
  1165. if (!t->stid_base &&
  1166. CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1167. __set_bit(0, t->stid_bmap);
  1168. }
  1169. bitmap_zero(t->ftid_bmap, t->nftids);
  1170. return 0;
  1171. }
  1172. /**
  1173. * cxgb4_create_server - create an IP server
  1174. * @dev: the device
  1175. * @stid: the server TID
  1176. * @sip: local IP address to bind server to
  1177. * @sport: the server's TCP port
  1178. * @queue: queue to direct messages from this server to
  1179. *
  1180. * Create an IP server for the given port and address.
  1181. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  1182. */
  1183. int cxgb4_create_server(const struct net_device *dev, unsigned int stid,
  1184. __be32 sip, __be16 sport, __be16 vlan,
  1185. unsigned int queue)
  1186. {
  1187. unsigned int chan;
  1188. struct sk_buff *skb;
  1189. struct adapter *adap;
  1190. struct cpl_pass_open_req *req;
  1191. int ret;
  1192. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1193. if (!skb)
  1194. return -ENOMEM;
  1195. adap = netdev2adap(dev);
  1196. req = (struct cpl_pass_open_req *)__skb_put(skb, sizeof(*req));
  1197. INIT_TP_WR(req, 0);
  1198. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, stid));
  1199. req->local_port = sport;
  1200. req->peer_port = htons(0);
  1201. req->local_ip = sip;
  1202. req->peer_ip = htonl(0);
  1203. chan = rxq_to_chan(&adap->sge, queue);
  1204. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  1205. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  1206. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  1207. ret = t4_mgmt_tx(adap, skb);
  1208. return net_xmit_eval(ret);
  1209. }
  1210. EXPORT_SYMBOL(cxgb4_create_server);
  1211. /* cxgb4_create_server6 - create an IPv6 server
  1212. * @dev: the device
  1213. * @stid: the server TID
  1214. * @sip: local IPv6 address to bind server to
  1215. * @sport: the server's TCP port
  1216. * @queue: queue to direct messages from this server to
  1217. *
  1218. * Create an IPv6 server for the given port and address.
  1219. * Returns <0 on error and one of the %NET_XMIT_* values on success.
  1220. */
  1221. int cxgb4_create_server6(const struct net_device *dev, unsigned int stid,
  1222. const struct in6_addr *sip, __be16 sport,
  1223. unsigned int queue)
  1224. {
  1225. unsigned int chan;
  1226. struct sk_buff *skb;
  1227. struct adapter *adap;
  1228. struct cpl_pass_open_req6 *req;
  1229. int ret;
  1230. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1231. if (!skb)
  1232. return -ENOMEM;
  1233. adap = netdev2adap(dev);
  1234. req = (struct cpl_pass_open_req6 *)__skb_put(skb, sizeof(*req));
  1235. INIT_TP_WR(req, 0);
  1236. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ6, stid));
  1237. req->local_port = sport;
  1238. req->peer_port = htons(0);
  1239. req->local_ip_hi = *(__be64 *)(sip->s6_addr);
  1240. req->local_ip_lo = *(__be64 *)(sip->s6_addr + 8);
  1241. req->peer_ip_hi = cpu_to_be64(0);
  1242. req->peer_ip_lo = cpu_to_be64(0);
  1243. chan = rxq_to_chan(&adap->sge, queue);
  1244. req->opt0 = cpu_to_be64(TX_CHAN_V(chan));
  1245. req->opt1 = cpu_to_be64(CONN_POLICY_V(CPL_CONN_POLICY_ASK) |
  1246. SYN_RSS_ENABLE_F | SYN_RSS_QUEUE_V(queue));
  1247. ret = t4_mgmt_tx(adap, skb);
  1248. return net_xmit_eval(ret);
  1249. }
  1250. EXPORT_SYMBOL(cxgb4_create_server6);
  1251. int cxgb4_remove_server(const struct net_device *dev, unsigned int stid,
  1252. unsigned int queue, bool ipv6)
  1253. {
  1254. struct sk_buff *skb;
  1255. struct adapter *adap;
  1256. struct cpl_close_listsvr_req *req;
  1257. int ret;
  1258. adap = netdev2adap(dev);
  1259. skb = alloc_skb(sizeof(*req), GFP_KERNEL);
  1260. if (!skb)
  1261. return -ENOMEM;
  1262. req = (struct cpl_close_listsvr_req *)__skb_put(skb, sizeof(*req));
  1263. INIT_TP_WR(req, 0);
  1264. OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, stid));
  1265. req->reply_ctrl = htons(NO_REPLY_V(0) | (ipv6 ? LISTSVR_IPV6_V(1) :
  1266. LISTSVR_IPV6_V(0)) | QUEUENO_V(queue));
  1267. ret = t4_mgmt_tx(adap, skb);
  1268. return net_xmit_eval(ret);
  1269. }
  1270. EXPORT_SYMBOL(cxgb4_remove_server);
  1271. /**
  1272. * cxgb4_best_mtu - find the entry in the MTU table closest to an MTU
  1273. * @mtus: the HW MTU table
  1274. * @mtu: the target MTU
  1275. * @idx: index of selected entry in the MTU table
  1276. *
  1277. * Returns the index and the value in the HW MTU table that is closest to
  1278. * but does not exceed @mtu, unless @mtu is smaller than any value in the
  1279. * table, in which case that smallest available value is selected.
  1280. */
  1281. unsigned int cxgb4_best_mtu(const unsigned short *mtus, unsigned short mtu,
  1282. unsigned int *idx)
  1283. {
  1284. unsigned int i = 0;
  1285. while (i < NMTUS - 1 && mtus[i + 1] <= mtu)
  1286. ++i;
  1287. if (idx)
  1288. *idx = i;
  1289. return mtus[i];
  1290. }
  1291. EXPORT_SYMBOL(cxgb4_best_mtu);
  1292. /**
  1293. * cxgb4_best_aligned_mtu - find best MTU, [hopefully] data size aligned
  1294. * @mtus: the HW MTU table
  1295. * @header_size: Header Size
  1296. * @data_size_max: maximum Data Segment Size
  1297. * @data_size_align: desired Data Segment Size Alignment (2^N)
  1298. * @mtu_idxp: HW MTU Table Index return value pointer (possibly NULL)
  1299. *
  1300. * Similar to cxgb4_best_mtu() but instead of searching the Hardware
  1301. * MTU Table based solely on a Maximum MTU parameter, we break that
  1302. * parameter up into a Header Size and Maximum Data Segment Size, and
  1303. * provide a desired Data Segment Size Alignment. If we find an MTU in
  1304. * the Hardware MTU Table which will result in a Data Segment Size with
  1305. * the requested alignment _and_ that MTU isn't "too far" from the
  1306. * closest MTU, then we'll return that rather than the closest MTU.
  1307. */
  1308. unsigned int cxgb4_best_aligned_mtu(const unsigned short *mtus,
  1309. unsigned short header_size,
  1310. unsigned short data_size_max,
  1311. unsigned short data_size_align,
  1312. unsigned int *mtu_idxp)
  1313. {
  1314. unsigned short max_mtu = header_size + data_size_max;
  1315. unsigned short data_size_align_mask = data_size_align - 1;
  1316. int mtu_idx, aligned_mtu_idx;
  1317. /* Scan the MTU Table till we find an MTU which is larger than our
  1318. * Maximum MTU or we reach the end of the table. Along the way,
  1319. * record the last MTU found, if any, which will result in a Data
  1320. * Segment Length matching the requested alignment.
  1321. */
  1322. for (mtu_idx = 0, aligned_mtu_idx = -1; mtu_idx < NMTUS; mtu_idx++) {
  1323. unsigned short data_size = mtus[mtu_idx] - header_size;
  1324. /* If this MTU minus the Header Size would result in a
  1325. * Data Segment Size of the desired alignment, remember it.
  1326. */
  1327. if ((data_size & data_size_align_mask) == 0)
  1328. aligned_mtu_idx = mtu_idx;
  1329. /* If we're not at the end of the Hardware MTU Table and the
  1330. * next element is larger than our Maximum MTU, drop out of
  1331. * the loop.
  1332. */
  1333. if (mtu_idx+1 < NMTUS && mtus[mtu_idx+1] > max_mtu)
  1334. break;
  1335. }
  1336. /* If we fell out of the loop because we ran to the end of the table,
  1337. * then we just have to use the last [largest] entry.
  1338. */
  1339. if (mtu_idx == NMTUS)
  1340. mtu_idx--;
  1341. /* If we found an MTU which resulted in the requested Data Segment
  1342. * Length alignment and that's "not far" from the largest MTU which is
  1343. * less than or equal to the maximum MTU, then use that.
  1344. */
  1345. if (aligned_mtu_idx >= 0 &&
  1346. mtu_idx - aligned_mtu_idx <= 1)
  1347. mtu_idx = aligned_mtu_idx;
  1348. /* If the caller has passed in an MTU Index pointer, pass the
  1349. * MTU Index back. Return the MTU value.
  1350. */
  1351. if (mtu_idxp)
  1352. *mtu_idxp = mtu_idx;
  1353. return mtus[mtu_idx];
  1354. }
  1355. EXPORT_SYMBOL(cxgb4_best_aligned_mtu);
  1356. /**
  1357. * cxgb4_tp_smt_idx - Get the Source Mac Table index for this VI
  1358. * @chip: chip type
  1359. * @viid: VI id of the given port
  1360. *
  1361. * Return the SMT index for this VI.
  1362. */
  1363. unsigned int cxgb4_tp_smt_idx(enum chip_type chip, unsigned int viid)
  1364. {
  1365. /* In T4/T5, SMT contains 256 SMAC entries organized in
  1366. * 128 rows of 2 entries each.
  1367. * In T6, SMT contains 256 SMAC entries in 256 rows.
  1368. * TODO: The below code needs to be updated when we add support
  1369. * for 256 VFs.
  1370. */
  1371. if (CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5)
  1372. return ((viid & 0x7f) << 1);
  1373. else
  1374. return (viid & 0x7f);
  1375. }
  1376. EXPORT_SYMBOL(cxgb4_tp_smt_idx);
  1377. /**
  1378. * cxgb4_port_chan - get the HW channel of a port
  1379. * @dev: the net device for the port
  1380. *
  1381. * Return the HW Tx channel of the given port.
  1382. */
  1383. unsigned int cxgb4_port_chan(const struct net_device *dev)
  1384. {
  1385. return netdev2pinfo(dev)->tx_chan;
  1386. }
  1387. EXPORT_SYMBOL(cxgb4_port_chan);
  1388. unsigned int cxgb4_dbfifo_count(const struct net_device *dev, int lpfifo)
  1389. {
  1390. struct adapter *adap = netdev2adap(dev);
  1391. u32 v1, v2, lp_count, hp_count;
  1392. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  1393. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  1394. if (is_t4(adap->params.chip)) {
  1395. lp_count = LP_COUNT_G(v1);
  1396. hp_count = HP_COUNT_G(v1);
  1397. } else {
  1398. lp_count = LP_COUNT_T5_G(v1);
  1399. hp_count = HP_COUNT_T5_G(v2);
  1400. }
  1401. return lpfifo ? lp_count : hp_count;
  1402. }
  1403. EXPORT_SYMBOL(cxgb4_dbfifo_count);
  1404. /**
  1405. * cxgb4_port_viid - get the VI id of a port
  1406. * @dev: the net device for the port
  1407. *
  1408. * Return the VI id of the given port.
  1409. */
  1410. unsigned int cxgb4_port_viid(const struct net_device *dev)
  1411. {
  1412. return netdev2pinfo(dev)->viid;
  1413. }
  1414. EXPORT_SYMBOL(cxgb4_port_viid);
  1415. /**
  1416. * cxgb4_port_idx - get the index of a port
  1417. * @dev: the net device for the port
  1418. *
  1419. * Return the index of the given port.
  1420. */
  1421. unsigned int cxgb4_port_idx(const struct net_device *dev)
  1422. {
  1423. return netdev2pinfo(dev)->port_id;
  1424. }
  1425. EXPORT_SYMBOL(cxgb4_port_idx);
  1426. void cxgb4_get_tcp_stats(struct pci_dev *pdev, struct tp_tcp_stats *v4,
  1427. struct tp_tcp_stats *v6)
  1428. {
  1429. struct adapter *adap = pci_get_drvdata(pdev);
  1430. spin_lock(&adap->stats_lock);
  1431. t4_tp_get_tcp_stats(adap, v4, v6);
  1432. spin_unlock(&adap->stats_lock);
  1433. }
  1434. EXPORT_SYMBOL(cxgb4_get_tcp_stats);
  1435. void cxgb4_iscsi_init(struct net_device *dev, unsigned int tag_mask,
  1436. const unsigned int *pgsz_order)
  1437. {
  1438. struct adapter *adap = netdev2adap(dev);
  1439. t4_write_reg(adap, ULP_RX_ISCSI_TAGMASK_A, tag_mask);
  1440. t4_write_reg(adap, ULP_RX_ISCSI_PSZ_A, HPZ0_V(pgsz_order[0]) |
  1441. HPZ1_V(pgsz_order[1]) | HPZ2_V(pgsz_order[2]) |
  1442. HPZ3_V(pgsz_order[3]));
  1443. }
  1444. EXPORT_SYMBOL(cxgb4_iscsi_init);
  1445. int cxgb4_flush_eq_cache(struct net_device *dev)
  1446. {
  1447. struct adapter *adap = netdev2adap(dev);
  1448. return t4_sge_ctxt_flush(adap, adap->mbox);
  1449. }
  1450. EXPORT_SYMBOL(cxgb4_flush_eq_cache);
  1451. static int read_eq_indices(struct adapter *adap, u16 qid, u16 *pidx, u16 *cidx)
  1452. {
  1453. u32 addr = t4_read_reg(adap, SGE_DBQ_CTXT_BADDR_A) + 24 * qid + 8;
  1454. __be64 indices;
  1455. int ret;
  1456. spin_lock(&adap->win0_lock);
  1457. ret = t4_memory_rw(adap, 0, MEM_EDC0, addr,
  1458. sizeof(indices), (__be32 *)&indices,
  1459. T4_MEMORY_READ);
  1460. spin_unlock(&adap->win0_lock);
  1461. if (!ret) {
  1462. *cidx = (be64_to_cpu(indices) >> 25) & 0xffff;
  1463. *pidx = (be64_to_cpu(indices) >> 9) & 0xffff;
  1464. }
  1465. return ret;
  1466. }
  1467. int cxgb4_sync_txq_pidx(struct net_device *dev, u16 qid, u16 pidx,
  1468. u16 size)
  1469. {
  1470. struct adapter *adap = netdev2adap(dev);
  1471. u16 hw_pidx, hw_cidx;
  1472. int ret;
  1473. ret = read_eq_indices(adap, qid, &hw_pidx, &hw_cidx);
  1474. if (ret)
  1475. goto out;
  1476. if (pidx != hw_pidx) {
  1477. u16 delta;
  1478. u32 val;
  1479. if (pidx >= hw_pidx)
  1480. delta = pidx - hw_pidx;
  1481. else
  1482. delta = size - hw_pidx + pidx;
  1483. if (is_t4(adap->params.chip))
  1484. val = PIDX_V(delta);
  1485. else
  1486. val = PIDX_T5_V(delta);
  1487. wmb();
  1488. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1489. QID_V(qid) | val);
  1490. }
  1491. out:
  1492. return ret;
  1493. }
  1494. EXPORT_SYMBOL(cxgb4_sync_txq_pidx);
  1495. int cxgb4_read_tpte(struct net_device *dev, u32 stag, __be32 *tpte)
  1496. {
  1497. struct adapter *adap;
  1498. u32 offset, memtype, memaddr;
  1499. u32 edc0_size, edc1_size, mc0_size, mc1_size, size;
  1500. u32 edc0_end, edc1_end, mc0_end, mc1_end;
  1501. int ret;
  1502. adap = netdev2adap(dev);
  1503. offset = ((stag >> 8) * 32) + adap->vres.stag.start;
  1504. /* Figure out where the offset lands in the Memory Type/Address scheme.
  1505. * This code assumes that the memory is laid out starting at offset 0
  1506. * with no breaks as: EDC0, EDC1, MC0, MC1. All cards have both EDC0
  1507. * and EDC1. Some cards will have neither MC0 nor MC1, most cards have
  1508. * MC0, and some have both MC0 and MC1.
  1509. */
  1510. size = t4_read_reg(adap, MA_EDRAM0_BAR_A);
  1511. edc0_size = EDRAM0_SIZE_G(size) << 20;
  1512. size = t4_read_reg(adap, MA_EDRAM1_BAR_A);
  1513. edc1_size = EDRAM1_SIZE_G(size) << 20;
  1514. size = t4_read_reg(adap, MA_EXT_MEMORY0_BAR_A);
  1515. mc0_size = EXT_MEM0_SIZE_G(size) << 20;
  1516. edc0_end = edc0_size;
  1517. edc1_end = edc0_end + edc1_size;
  1518. mc0_end = edc1_end + mc0_size;
  1519. if (offset < edc0_end) {
  1520. memtype = MEM_EDC0;
  1521. memaddr = offset;
  1522. } else if (offset < edc1_end) {
  1523. memtype = MEM_EDC1;
  1524. memaddr = offset - edc0_end;
  1525. } else {
  1526. if (offset < mc0_end) {
  1527. memtype = MEM_MC0;
  1528. memaddr = offset - edc1_end;
  1529. } else if (is_t5(adap->params.chip)) {
  1530. size = t4_read_reg(adap, MA_EXT_MEMORY1_BAR_A);
  1531. mc1_size = EXT_MEM1_SIZE_G(size) << 20;
  1532. mc1_end = mc0_end + mc1_size;
  1533. if (offset < mc1_end) {
  1534. memtype = MEM_MC1;
  1535. memaddr = offset - mc0_end;
  1536. } else {
  1537. /* offset beyond the end of any memory */
  1538. goto err;
  1539. }
  1540. } else {
  1541. /* T4/T6 only has a single memory channel */
  1542. goto err;
  1543. }
  1544. }
  1545. spin_lock(&adap->win0_lock);
  1546. ret = t4_memory_rw(adap, 0, memtype, memaddr, 32, tpte, T4_MEMORY_READ);
  1547. spin_unlock(&adap->win0_lock);
  1548. return ret;
  1549. err:
  1550. dev_err(adap->pdev_dev, "stag %#x, offset %#x out of range\n",
  1551. stag, offset);
  1552. return -EINVAL;
  1553. }
  1554. EXPORT_SYMBOL(cxgb4_read_tpte);
  1555. u64 cxgb4_read_sge_timestamp(struct net_device *dev)
  1556. {
  1557. u32 hi, lo;
  1558. struct adapter *adap;
  1559. adap = netdev2adap(dev);
  1560. lo = t4_read_reg(adap, SGE_TIMESTAMP_LO_A);
  1561. hi = TSVAL_G(t4_read_reg(adap, SGE_TIMESTAMP_HI_A));
  1562. return ((u64)hi << 32) | (u64)lo;
  1563. }
  1564. EXPORT_SYMBOL(cxgb4_read_sge_timestamp);
  1565. int cxgb4_bar2_sge_qregs(struct net_device *dev,
  1566. unsigned int qid,
  1567. enum cxgb4_bar2_qtype qtype,
  1568. int user,
  1569. u64 *pbar2_qoffset,
  1570. unsigned int *pbar2_qid)
  1571. {
  1572. return t4_bar2_sge_qregs(netdev2adap(dev),
  1573. qid,
  1574. (qtype == CXGB4_BAR2_QTYPE_EGRESS
  1575. ? T4_BAR2_QTYPE_EGRESS
  1576. : T4_BAR2_QTYPE_INGRESS),
  1577. user,
  1578. pbar2_qoffset,
  1579. pbar2_qid);
  1580. }
  1581. EXPORT_SYMBOL(cxgb4_bar2_sge_qregs);
  1582. static struct pci_driver cxgb4_driver;
  1583. static void check_neigh_update(struct neighbour *neigh)
  1584. {
  1585. const struct device *parent;
  1586. const struct net_device *netdev = neigh->dev;
  1587. if (is_vlan_dev(netdev))
  1588. netdev = vlan_dev_real_dev(netdev);
  1589. parent = netdev->dev.parent;
  1590. if (parent && parent->driver == &cxgb4_driver.driver)
  1591. t4_l2t_update(dev_get_drvdata(parent), neigh);
  1592. }
  1593. static int netevent_cb(struct notifier_block *nb, unsigned long event,
  1594. void *data)
  1595. {
  1596. switch (event) {
  1597. case NETEVENT_NEIGH_UPDATE:
  1598. check_neigh_update(data);
  1599. break;
  1600. case NETEVENT_REDIRECT:
  1601. default:
  1602. break;
  1603. }
  1604. return 0;
  1605. }
  1606. static bool netevent_registered;
  1607. static struct notifier_block cxgb4_netevent_nb = {
  1608. .notifier_call = netevent_cb
  1609. };
  1610. static void drain_db_fifo(struct adapter *adap, int usecs)
  1611. {
  1612. u32 v1, v2, lp_count, hp_count;
  1613. do {
  1614. v1 = t4_read_reg(adap, SGE_DBFIFO_STATUS_A);
  1615. v2 = t4_read_reg(adap, SGE_DBFIFO_STATUS2_A);
  1616. if (is_t4(adap->params.chip)) {
  1617. lp_count = LP_COUNT_G(v1);
  1618. hp_count = HP_COUNT_G(v1);
  1619. } else {
  1620. lp_count = LP_COUNT_T5_G(v1);
  1621. hp_count = HP_COUNT_T5_G(v2);
  1622. }
  1623. if (lp_count == 0 && hp_count == 0)
  1624. break;
  1625. set_current_state(TASK_UNINTERRUPTIBLE);
  1626. schedule_timeout(usecs_to_jiffies(usecs));
  1627. } while (1);
  1628. }
  1629. static void disable_txq_db(struct sge_txq *q)
  1630. {
  1631. unsigned long flags;
  1632. spin_lock_irqsave(&q->db_lock, flags);
  1633. q->db_disabled = 1;
  1634. spin_unlock_irqrestore(&q->db_lock, flags);
  1635. }
  1636. static void enable_txq_db(struct adapter *adap, struct sge_txq *q)
  1637. {
  1638. spin_lock_irq(&q->db_lock);
  1639. if (q->db_pidx_inc) {
  1640. /* Make sure that all writes to the TX descriptors
  1641. * are committed before we tell HW about them.
  1642. */
  1643. wmb();
  1644. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1645. QID_V(q->cntxt_id) | PIDX_V(q->db_pidx_inc));
  1646. q->db_pidx_inc = 0;
  1647. }
  1648. q->db_disabled = 0;
  1649. spin_unlock_irq(&q->db_lock);
  1650. }
  1651. static void disable_dbs(struct adapter *adap)
  1652. {
  1653. int i;
  1654. for_each_ethrxq(&adap->sge, i)
  1655. disable_txq_db(&adap->sge.ethtxq[i].q);
  1656. if (is_offload(adap)) {
  1657. struct sge_uld_txq_info *txq_info =
  1658. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1659. if (txq_info) {
  1660. for_each_ofldtxq(&adap->sge, i) {
  1661. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1662. disable_txq_db(&txq->q);
  1663. }
  1664. }
  1665. }
  1666. for_each_port(adap, i)
  1667. disable_txq_db(&adap->sge.ctrlq[i].q);
  1668. }
  1669. static void enable_dbs(struct adapter *adap)
  1670. {
  1671. int i;
  1672. for_each_ethrxq(&adap->sge, i)
  1673. enable_txq_db(adap, &adap->sge.ethtxq[i].q);
  1674. if (is_offload(adap)) {
  1675. struct sge_uld_txq_info *txq_info =
  1676. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1677. if (txq_info) {
  1678. for_each_ofldtxq(&adap->sge, i) {
  1679. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1680. enable_txq_db(adap, &txq->q);
  1681. }
  1682. }
  1683. }
  1684. for_each_port(adap, i)
  1685. enable_txq_db(adap, &adap->sge.ctrlq[i].q);
  1686. }
  1687. static void notify_rdma_uld(struct adapter *adap, enum cxgb4_control cmd)
  1688. {
  1689. enum cxgb4_uld type = CXGB4_ULD_RDMA;
  1690. if (adap->uld && adap->uld[type].handle)
  1691. adap->uld[type].control(adap->uld[type].handle, cmd);
  1692. }
  1693. static void process_db_full(struct work_struct *work)
  1694. {
  1695. struct adapter *adap;
  1696. adap = container_of(work, struct adapter, db_full_task);
  1697. drain_db_fifo(adap, dbfifo_drain_delay);
  1698. enable_dbs(adap);
  1699. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  1700. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1701. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1702. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F,
  1703. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F);
  1704. else
  1705. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1706. DBFIFO_LP_INT_F, DBFIFO_LP_INT_F);
  1707. }
  1708. static void sync_txq_pidx(struct adapter *adap, struct sge_txq *q)
  1709. {
  1710. u16 hw_pidx, hw_cidx;
  1711. int ret;
  1712. spin_lock_irq(&q->db_lock);
  1713. ret = read_eq_indices(adap, (u16)q->cntxt_id, &hw_pidx, &hw_cidx);
  1714. if (ret)
  1715. goto out;
  1716. if (q->db_pidx != hw_pidx) {
  1717. u16 delta;
  1718. u32 val;
  1719. if (q->db_pidx >= hw_pidx)
  1720. delta = q->db_pidx - hw_pidx;
  1721. else
  1722. delta = q->size - hw_pidx + q->db_pidx;
  1723. if (is_t4(adap->params.chip))
  1724. val = PIDX_V(delta);
  1725. else
  1726. val = PIDX_T5_V(delta);
  1727. wmb();
  1728. t4_write_reg(adap, MYPF_REG(SGE_PF_KDOORBELL_A),
  1729. QID_V(q->cntxt_id) | val);
  1730. }
  1731. out:
  1732. q->db_disabled = 0;
  1733. q->db_pidx_inc = 0;
  1734. spin_unlock_irq(&q->db_lock);
  1735. if (ret)
  1736. CH_WARN(adap, "DB drop recovery failed.\n");
  1737. }
  1738. static void recover_all_queues(struct adapter *adap)
  1739. {
  1740. int i;
  1741. for_each_ethrxq(&adap->sge, i)
  1742. sync_txq_pidx(adap, &adap->sge.ethtxq[i].q);
  1743. if (is_offload(adap)) {
  1744. struct sge_uld_txq_info *txq_info =
  1745. adap->sge.uld_txq_info[CXGB4_TX_OFLD];
  1746. if (txq_info) {
  1747. for_each_ofldtxq(&adap->sge, i) {
  1748. struct sge_uld_txq *txq = &txq_info->uldtxq[i];
  1749. sync_txq_pidx(adap, &txq->q);
  1750. }
  1751. }
  1752. }
  1753. for_each_port(adap, i)
  1754. sync_txq_pidx(adap, &adap->sge.ctrlq[i].q);
  1755. }
  1756. static void process_db_drop(struct work_struct *work)
  1757. {
  1758. struct adapter *adap;
  1759. adap = container_of(work, struct adapter, db_drop_task);
  1760. if (is_t4(adap->params.chip)) {
  1761. drain_db_fifo(adap, dbfifo_drain_delay);
  1762. notify_rdma_uld(adap, CXGB4_CONTROL_DB_DROP);
  1763. drain_db_fifo(adap, dbfifo_drain_delay);
  1764. recover_all_queues(adap);
  1765. drain_db_fifo(adap, dbfifo_drain_delay);
  1766. enable_dbs(adap);
  1767. notify_rdma_uld(adap, CXGB4_CONTROL_DB_EMPTY);
  1768. } else if (is_t5(adap->params.chip)) {
  1769. u32 dropped_db = t4_read_reg(adap, 0x010ac);
  1770. u16 qid = (dropped_db >> 15) & 0x1ffff;
  1771. u16 pidx_inc = dropped_db & 0x1fff;
  1772. u64 bar2_qoffset;
  1773. unsigned int bar2_qid;
  1774. int ret;
  1775. ret = t4_bar2_sge_qregs(adap, qid, T4_BAR2_QTYPE_EGRESS,
  1776. 0, &bar2_qoffset, &bar2_qid);
  1777. if (ret)
  1778. dev_err(adap->pdev_dev, "doorbell drop recovery: "
  1779. "qid=%d, pidx_inc=%d\n", qid, pidx_inc);
  1780. else
  1781. writel(PIDX_T5_V(pidx_inc) | QID_V(bar2_qid),
  1782. adap->bar2 + bar2_qoffset + SGE_UDB_KDOORBELL);
  1783. /* Re-enable BAR2 WC */
  1784. t4_set_reg_field(adap, 0x10b0, 1<<15, 1<<15);
  1785. }
  1786. if (CHELSIO_CHIP_VERSION(adap->params.chip) <= CHELSIO_T5)
  1787. t4_set_reg_field(adap, SGE_DOORBELL_CONTROL_A, DROPPED_DB_F, 0);
  1788. }
  1789. void t4_db_full(struct adapter *adap)
  1790. {
  1791. if (is_t4(adap->params.chip)) {
  1792. disable_dbs(adap);
  1793. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  1794. t4_set_reg_field(adap, SGE_INT_ENABLE3_A,
  1795. DBFIFO_HP_INT_F | DBFIFO_LP_INT_F, 0);
  1796. queue_work(adap->workq, &adap->db_full_task);
  1797. }
  1798. }
  1799. void t4_db_dropped(struct adapter *adap)
  1800. {
  1801. if (is_t4(adap->params.chip)) {
  1802. disable_dbs(adap);
  1803. notify_rdma_uld(adap, CXGB4_CONTROL_DB_FULL);
  1804. }
  1805. queue_work(adap->workq, &adap->db_drop_task);
  1806. }
  1807. void t4_register_netevent_notifier(void)
  1808. {
  1809. if (!netevent_registered) {
  1810. register_netevent_notifier(&cxgb4_netevent_nb);
  1811. netevent_registered = true;
  1812. }
  1813. }
  1814. static void detach_ulds(struct adapter *adap)
  1815. {
  1816. unsigned int i;
  1817. mutex_lock(&uld_mutex);
  1818. list_del(&adap->list_node);
  1819. for (i = 0; i < CXGB4_ULD_MAX; i++)
  1820. if (adap->uld && adap->uld[i].handle) {
  1821. adap->uld[i].state_change(adap->uld[i].handle,
  1822. CXGB4_STATE_DETACH);
  1823. adap->uld[i].handle = NULL;
  1824. }
  1825. if (netevent_registered && list_empty(&adapter_list)) {
  1826. unregister_netevent_notifier(&cxgb4_netevent_nb);
  1827. netevent_registered = false;
  1828. }
  1829. mutex_unlock(&uld_mutex);
  1830. }
  1831. static void notify_ulds(struct adapter *adap, enum cxgb4_state new_state)
  1832. {
  1833. unsigned int i;
  1834. mutex_lock(&uld_mutex);
  1835. for (i = 0; i < CXGB4_ULD_MAX; i++)
  1836. if (adap->uld && adap->uld[i].handle)
  1837. adap->uld[i].state_change(adap->uld[i].handle,
  1838. new_state);
  1839. mutex_unlock(&uld_mutex);
  1840. }
  1841. #if IS_ENABLED(CONFIG_IPV6)
  1842. static int cxgb4_inet6addr_handler(struct notifier_block *this,
  1843. unsigned long event, void *data)
  1844. {
  1845. struct inet6_ifaddr *ifa = data;
  1846. struct net_device *event_dev = ifa->idev->dev;
  1847. const struct device *parent = NULL;
  1848. #if IS_ENABLED(CONFIG_BONDING)
  1849. struct adapter *adap;
  1850. #endif
  1851. if (is_vlan_dev(event_dev))
  1852. event_dev = vlan_dev_real_dev(event_dev);
  1853. #if IS_ENABLED(CONFIG_BONDING)
  1854. if (event_dev->flags & IFF_MASTER) {
  1855. list_for_each_entry(adap, &adapter_list, list_node) {
  1856. switch (event) {
  1857. case NETDEV_UP:
  1858. cxgb4_clip_get(adap->port[0],
  1859. (const u32 *)ifa, 1);
  1860. break;
  1861. case NETDEV_DOWN:
  1862. cxgb4_clip_release(adap->port[0],
  1863. (const u32 *)ifa, 1);
  1864. break;
  1865. default:
  1866. break;
  1867. }
  1868. }
  1869. return NOTIFY_OK;
  1870. }
  1871. #endif
  1872. if (event_dev)
  1873. parent = event_dev->dev.parent;
  1874. if (parent && parent->driver == &cxgb4_driver.driver) {
  1875. switch (event) {
  1876. case NETDEV_UP:
  1877. cxgb4_clip_get(event_dev, (const u32 *)ifa, 1);
  1878. break;
  1879. case NETDEV_DOWN:
  1880. cxgb4_clip_release(event_dev, (const u32 *)ifa, 1);
  1881. break;
  1882. default:
  1883. break;
  1884. }
  1885. }
  1886. return NOTIFY_OK;
  1887. }
  1888. static bool inet6addr_registered;
  1889. static struct notifier_block cxgb4_inet6addr_notifier = {
  1890. .notifier_call = cxgb4_inet6addr_handler
  1891. };
  1892. static void update_clip(const struct adapter *adap)
  1893. {
  1894. int i;
  1895. struct net_device *dev;
  1896. int ret;
  1897. rcu_read_lock();
  1898. for (i = 0; i < MAX_NPORTS; i++) {
  1899. dev = adap->port[i];
  1900. ret = 0;
  1901. if (dev)
  1902. ret = cxgb4_update_root_dev_clip(dev);
  1903. if (ret < 0)
  1904. break;
  1905. }
  1906. rcu_read_unlock();
  1907. }
  1908. #endif /* IS_ENABLED(CONFIG_IPV6) */
  1909. /**
  1910. * cxgb_up - enable the adapter
  1911. * @adap: adapter being enabled
  1912. *
  1913. * Called when the first port is enabled, this function performs the
  1914. * actions necessary to make an adapter operational, such as completing
  1915. * the initialization of HW modules, and enabling interrupts.
  1916. *
  1917. * Must be called with the rtnl lock held.
  1918. */
  1919. static int cxgb_up(struct adapter *adap)
  1920. {
  1921. int err;
  1922. err = setup_sge_queues(adap);
  1923. if (err)
  1924. goto out;
  1925. err = setup_rss(adap);
  1926. if (err)
  1927. goto freeq;
  1928. if (adap->flags & USING_MSIX) {
  1929. name_msix_vecs(adap);
  1930. err = request_irq(adap->msix_info[0].vec, t4_nondata_intr, 0,
  1931. adap->msix_info[0].desc, adap);
  1932. if (err)
  1933. goto irq_err;
  1934. err = request_msix_queue_irqs(adap);
  1935. if (err) {
  1936. free_irq(adap->msix_info[0].vec, adap);
  1937. goto irq_err;
  1938. }
  1939. } else {
  1940. err = request_irq(adap->pdev->irq, t4_intr_handler(adap),
  1941. (adap->flags & USING_MSI) ? 0 : IRQF_SHARED,
  1942. adap->port[0]->name, adap);
  1943. if (err)
  1944. goto irq_err;
  1945. }
  1946. enable_rx(adap);
  1947. t4_sge_start(adap);
  1948. t4_intr_enable(adap);
  1949. adap->flags |= FULL_INIT_DONE;
  1950. notify_ulds(adap, CXGB4_STATE_UP);
  1951. #if IS_ENABLED(CONFIG_IPV6)
  1952. update_clip(adap);
  1953. #endif
  1954. /* Initialize hash mac addr list*/
  1955. INIT_LIST_HEAD(&adap->mac_hlist);
  1956. out:
  1957. return err;
  1958. irq_err:
  1959. dev_err(adap->pdev_dev, "request_irq failed, err %d\n", err);
  1960. freeq:
  1961. t4_free_sge_resources(adap);
  1962. goto out;
  1963. }
  1964. static void cxgb_down(struct adapter *adapter)
  1965. {
  1966. cancel_work_sync(&adapter->tid_release_task);
  1967. cancel_work_sync(&adapter->db_full_task);
  1968. cancel_work_sync(&adapter->db_drop_task);
  1969. adapter->tid_release_task_busy = false;
  1970. adapter->tid_release_head = NULL;
  1971. t4_sge_stop(adapter);
  1972. t4_free_sge_resources(adapter);
  1973. adapter->flags &= ~FULL_INIT_DONE;
  1974. }
  1975. /*
  1976. * net_device operations
  1977. */
  1978. static int cxgb_open(struct net_device *dev)
  1979. {
  1980. int err;
  1981. struct port_info *pi = netdev_priv(dev);
  1982. struct adapter *adapter = pi->adapter;
  1983. netif_carrier_off(dev);
  1984. if (!(adapter->flags & FULL_INIT_DONE)) {
  1985. err = cxgb_up(adapter);
  1986. if (err < 0)
  1987. return err;
  1988. }
  1989. err = link_start(dev);
  1990. if (!err)
  1991. netif_tx_start_all_queues(dev);
  1992. return err;
  1993. }
  1994. static int cxgb_close(struct net_device *dev)
  1995. {
  1996. struct port_info *pi = netdev_priv(dev);
  1997. struct adapter *adapter = pi->adapter;
  1998. netif_tx_stop_all_queues(dev);
  1999. netif_carrier_off(dev);
  2000. return t4_enable_vi(adapter, adapter->pf, pi->viid, false, false);
  2001. }
  2002. int cxgb4_create_server_filter(const struct net_device *dev, unsigned int stid,
  2003. __be32 sip, __be16 sport, __be16 vlan,
  2004. unsigned int queue, unsigned char port, unsigned char mask)
  2005. {
  2006. int ret;
  2007. struct filter_entry *f;
  2008. struct adapter *adap;
  2009. int i;
  2010. u8 *val;
  2011. adap = netdev2adap(dev);
  2012. /* Adjust stid to correct filter index */
  2013. stid -= adap->tids.sftid_base;
  2014. stid += adap->tids.nftids;
  2015. /* Check to make sure the filter requested is writable ...
  2016. */
  2017. f = &adap->tids.ftid_tab[stid];
  2018. ret = writable_filter(f);
  2019. if (ret)
  2020. return ret;
  2021. /* Clear out any old resources being used by the filter before
  2022. * we start constructing the new filter.
  2023. */
  2024. if (f->valid)
  2025. clear_filter(adap, f);
  2026. /* Clear out filter specifications */
  2027. memset(&f->fs, 0, sizeof(struct ch_filter_specification));
  2028. f->fs.val.lport = cpu_to_be16(sport);
  2029. f->fs.mask.lport = ~0;
  2030. val = (u8 *)&sip;
  2031. if ((val[0] | val[1] | val[2] | val[3]) != 0) {
  2032. for (i = 0; i < 4; i++) {
  2033. f->fs.val.lip[i] = val[i];
  2034. f->fs.mask.lip[i] = ~0;
  2035. }
  2036. if (adap->params.tp.vlan_pri_map & PORT_F) {
  2037. f->fs.val.iport = port;
  2038. f->fs.mask.iport = mask;
  2039. }
  2040. }
  2041. if (adap->params.tp.vlan_pri_map & PROTOCOL_F) {
  2042. f->fs.val.proto = IPPROTO_TCP;
  2043. f->fs.mask.proto = ~0;
  2044. }
  2045. f->fs.dirsteer = 1;
  2046. f->fs.iq = queue;
  2047. /* Mark filter as locked */
  2048. f->locked = 1;
  2049. f->fs.rpttid = 1;
  2050. ret = set_filter_wr(adap, stid);
  2051. if (ret) {
  2052. clear_filter(adap, f);
  2053. return ret;
  2054. }
  2055. return 0;
  2056. }
  2057. EXPORT_SYMBOL(cxgb4_create_server_filter);
  2058. int cxgb4_remove_server_filter(const struct net_device *dev, unsigned int stid,
  2059. unsigned int queue, bool ipv6)
  2060. {
  2061. struct filter_entry *f;
  2062. struct adapter *adap;
  2063. adap = netdev2adap(dev);
  2064. /* Adjust stid to correct filter index */
  2065. stid -= adap->tids.sftid_base;
  2066. stid += adap->tids.nftids;
  2067. f = &adap->tids.ftid_tab[stid];
  2068. /* Unlock the filter */
  2069. f->locked = 0;
  2070. return delete_filter(adap, stid);
  2071. }
  2072. EXPORT_SYMBOL(cxgb4_remove_server_filter);
  2073. static void cxgb_get_stats(struct net_device *dev,
  2074. struct rtnl_link_stats64 *ns)
  2075. {
  2076. struct port_stats stats;
  2077. struct port_info *p = netdev_priv(dev);
  2078. struct adapter *adapter = p->adapter;
  2079. /* Block retrieving statistics during EEH error
  2080. * recovery. Otherwise, the recovery might fail
  2081. * and the PCI device will be removed permanently
  2082. */
  2083. spin_lock(&adapter->stats_lock);
  2084. if (!netif_device_present(dev)) {
  2085. spin_unlock(&adapter->stats_lock);
  2086. return;
  2087. }
  2088. t4_get_port_stats_offset(adapter, p->tx_chan, &stats,
  2089. &p->stats_base);
  2090. spin_unlock(&adapter->stats_lock);
  2091. ns->tx_bytes = stats.tx_octets;
  2092. ns->tx_packets = stats.tx_frames;
  2093. ns->rx_bytes = stats.rx_octets;
  2094. ns->rx_packets = stats.rx_frames;
  2095. ns->multicast = stats.rx_mcast_frames;
  2096. /* detailed rx_errors */
  2097. ns->rx_length_errors = stats.rx_jabber + stats.rx_too_long +
  2098. stats.rx_runt;
  2099. ns->rx_over_errors = 0;
  2100. ns->rx_crc_errors = stats.rx_fcs_err;
  2101. ns->rx_frame_errors = stats.rx_symbol_err;
  2102. ns->rx_dropped = stats.rx_ovflow0 + stats.rx_ovflow1 +
  2103. stats.rx_ovflow2 + stats.rx_ovflow3 +
  2104. stats.rx_trunc0 + stats.rx_trunc1 +
  2105. stats.rx_trunc2 + stats.rx_trunc3;
  2106. ns->rx_missed_errors = 0;
  2107. /* detailed tx_errors */
  2108. ns->tx_aborted_errors = 0;
  2109. ns->tx_carrier_errors = 0;
  2110. ns->tx_fifo_errors = 0;
  2111. ns->tx_heartbeat_errors = 0;
  2112. ns->tx_window_errors = 0;
  2113. ns->tx_errors = stats.tx_error_frames;
  2114. ns->rx_errors = stats.rx_symbol_err + stats.rx_fcs_err +
  2115. ns->rx_length_errors + stats.rx_len_err + ns->rx_fifo_errors;
  2116. }
  2117. static int cxgb_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
  2118. {
  2119. unsigned int mbox;
  2120. int ret = 0, prtad, devad;
  2121. struct port_info *pi = netdev_priv(dev);
  2122. struct mii_ioctl_data *data = (struct mii_ioctl_data *)&req->ifr_data;
  2123. switch (cmd) {
  2124. case SIOCGMIIPHY:
  2125. if (pi->mdio_addr < 0)
  2126. return -EOPNOTSUPP;
  2127. data->phy_id = pi->mdio_addr;
  2128. break;
  2129. case SIOCGMIIREG:
  2130. case SIOCSMIIREG:
  2131. if (mdio_phy_id_is_c45(data->phy_id)) {
  2132. prtad = mdio_phy_id_prtad(data->phy_id);
  2133. devad = mdio_phy_id_devad(data->phy_id);
  2134. } else if (data->phy_id < 32) {
  2135. prtad = data->phy_id;
  2136. devad = 0;
  2137. data->reg_num &= 0x1f;
  2138. } else
  2139. return -EINVAL;
  2140. mbox = pi->adapter->pf;
  2141. if (cmd == SIOCGMIIREG)
  2142. ret = t4_mdio_rd(pi->adapter, mbox, prtad, devad,
  2143. data->reg_num, &data->val_out);
  2144. else
  2145. ret = t4_mdio_wr(pi->adapter, mbox, prtad, devad,
  2146. data->reg_num, data->val_in);
  2147. break;
  2148. case SIOCGHWTSTAMP:
  2149. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2150. sizeof(pi->tstamp_config)) ?
  2151. -EFAULT : 0;
  2152. case SIOCSHWTSTAMP:
  2153. if (copy_from_user(&pi->tstamp_config, req->ifr_data,
  2154. sizeof(pi->tstamp_config)))
  2155. return -EFAULT;
  2156. switch (pi->tstamp_config.rx_filter) {
  2157. case HWTSTAMP_FILTER_NONE:
  2158. pi->rxtstamp = false;
  2159. break;
  2160. case HWTSTAMP_FILTER_ALL:
  2161. pi->rxtstamp = true;
  2162. break;
  2163. default:
  2164. pi->tstamp_config.rx_filter = HWTSTAMP_FILTER_NONE;
  2165. return -ERANGE;
  2166. }
  2167. return copy_to_user(req->ifr_data, &pi->tstamp_config,
  2168. sizeof(pi->tstamp_config)) ?
  2169. -EFAULT : 0;
  2170. default:
  2171. return -EOPNOTSUPP;
  2172. }
  2173. return ret;
  2174. }
  2175. static void cxgb_set_rxmode(struct net_device *dev)
  2176. {
  2177. /* unfortunately we can't return errors to the stack */
  2178. set_rxmode(dev, -1, false);
  2179. }
  2180. static int cxgb_change_mtu(struct net_device *dev, int new_mtu)
  2181. {
  2182. int ret;
  2183. struct port_info *pi = netdev_priv(dev);
  2184. ret = t4_set_rxmode(pi->adapter, pi->adapter->pf, pi->viid, new_mtu, -1,
  2185. -1, -1, -1, true);
  2186. if (!ret)
  2187. dev->mtu = new_mtu;
  2188. return ret;
  2189. }
  2190. #ifdef CONFIG_PCI_IOV
  2191. static int dummy_open(struct net_device *dev)
  2192. {
  2193. /* Turn carrier off since we don't have to transmit anything on this
  2194. * interface.
  2195. */
  2196. netif_carrier_off(dev);
  2197. return 0;
  2198. }
  2199. /* Fill MAC address that will be assigned by the FW */
  2200. static void fill_vf_station_mac_addr(struct adapter *adap)
  2201. {
  2202. unsigned int i;
  2203. u8 hw_addr[ETH_ALEN], macaddr[ETH_ALEN];
  2204. int err;
  2205. u8 *na;
  2206. u16 a, b;
  2207. err = t4_get_raw_vpd_params(adap, &adap->params.vpd);
  2208. if (!err) {
  2209. na = adap->params.vpd.na;
  2210. for (i = 0; i < ETH_ALEN; i++)
  2211. hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
  2212. hex2val(na[2 * i + 1]));
  2213. a = (hw_addr[0] << 8) | hw_addr[1];
  2214. b = (hw_addr[1] << 8) | hw_addr[2];
  2215. a ^= b;
  2216. a |= 0x0200; /* locally assigned Ethernet MAC address */
  2217. a &= ~0x0100; /* not a multicast Ethernet MAC address */
  2218. macaddr[0] = a >> 8;
  2219. macaddr[1] = a & 0xff;
  2220. for (i = 2; i < 5; i++)
  2221. macaddr[i] = hw_addr[i + 1];
  2222. for (i = 0; i < adap->num_vfs; i++) {
  2223. macaddr[5] = adap->pf * 16 + i;
  2224. ether_addr_copy(adap->vfinfo[i].vf_mac_addr, macaddr);
  2225. }
  2226. }
  2227. }
  2228. static int cxgb_set_vf_mac(struct net_device *dev, int vf, u8 *mac)
  2229. {
  2230. struct port_info *pi = netdev_priv(dev);
  2231. struct adapter *adap = pi->adapter;
  2232. int ret;
  2233. /* verify MAC addr is valid */
  2234. if (!is_valid_ether_addr(mac)) {
  2235. dev_err(pi->adapter->pdev_dev,
  2236. "Invalid Ethernet address %pM for VF %d\n",
  2237. mac, vf);
  2238. return -EINVAL;
  2239. }
  2240. dev_info(pi->adapter->pdev_dev,
  2241. "Setting MAC %pM on VF %d\n", mac, vf);
  2242. ret = t4_set_vf_mac_acl(adap, vf + 1, 1, mac);
  2243. if (!ret)
  2244. ether_addr_copy(adap->vfinfo[vf].vf_mac_addr, mac);
  2245. return ret;
  2246. }
  2247. static int cxgb_get_vf_config(struct net_device *dev,
  2248. int vf, struct ifla_vf_info *ivi)
  2249. {
  2250. struct port_info *pi = netdev_priv(dev);
  2251. struct adapter *adap = pi->adapter;
  2252. if (vf >= adap->num_vfs)
  2253. return -EINVAL;
  2254. ivi->vf = vf;
  2255. ether_addr_copy(ivi->mac, adap->vfinfo[vf].vf_mac_addr);
  2256. return 0;
  2257. }
  2258. static int cxgb_get_phys_port_id(struct net_device *dev,
  2259. struct netdev_phys_item_id *ppid)
  2260. {
  2261. struct port_info *pi = netdev_priv(dev);
  2262. unsigned int phy_port_id;
  2263. phy_port_id = pi->adapter->adap_idx * 10 + pi->port_id;
  2264. ppid->id_len = sizeof(phy_port_id);
  2265. memcpy(ppid->id, &phy_port_id, ppid->id_len);
  2266. return 0;
  2267. }
  2268. #endif
  2269. static int cxgb_set_mac_addr(struct net_device *dev, void *p)
  2270. {
  2271. int ret;
  2272. struct sockaddr *addr = p;
  2273. struct port_info *pi = netdev_priv(dev);
  2274. if (!is_valid_ether_addr(addr->sa_data))
  2275. return -EADDRNOTAVAIL;
  2276. ret = t4_change_mac(pi->adapter, pi->adapter->pf, pi->viid,
  2277. pi->xact_addr_filt, addr->sa_data, true, true);
  2278. if (ret < 0)
  2279. return ret;
  2280. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  2281. pi->xact_addr_filt = ret;
  2282. return 0;
  2283. }
  2284. #ifdef CONFIG_NET_POLL_CONTROLLER
  2285. static void cxgb_netpoll(struct net_device *dev)
  2286. {
  2287. struct port_info *pi = netdev_priv(dev);
  2288. struct adapter *adap = pi->adapter;
  2289. if (adap->flags & USING_MSIX) {
  2290. int i;
  2291. struct sge_eth_rxq *rx = &adap->sge.ethrxq[pi->first_qset];
  2292. for (i = pi->nqsets; i; i--, rx++)
  2293. t4_sge_intr_msix(0, &rx->rspq);
  2294. } else
  2295. t4_intr_handler(adap)(0, adap);
  2296. }
  2297. #endif
  2298. static int cxgb_set_tx_maxrate(struct net_device *dev, int index, u32 rate)
  2299. {
  2300. struct port_info *pi = netdev_priv(dev);
  2301. struct adapter *adap = pi->adapter;
  2302. struct sched_class *e;
  2303. struct ch_sched_params p;
  2304. struct ch_sched_queue qe;
  2305. u32 req_rate;
  2306. int err = 0;
  2307. if (!can_sched(dev))
  2308. return -ENOTSUPP;
  2309. if (index < 0 || index > pi->nqsets - 1)
  2310. return -EINVAL;
  2311. if (!(adap->flags & FULL_INIT_DONE)) {
  2312. dev_err(adap->pdev_dev,
  2313. "Failed to rate limit on queue %d. Link Down?\n",
  2314. index);
  2315. return -EINVAL;
  2316. }
  2317. /* Convert from Mbps to Kbps */
  2318. req_rate = rate << 10;
  2319. /* Max rate is 10 Gbps */
  2320. if (req_rate >= SCHED_MAX_RATE_KBPS) {
  2321. dev_err(adap->pdev_dev,
  2322. "Invalid rate %u Mbps, Max rate is %u Gbps\n",
  2323. rate, SCHED_MAX_RATE_KBPS);
  2324. return -ERANGE;
  2325. }
  2326. /* First unbind the queue from any existing class */
  2327. memset(&qe, 0, sizeof(qe));
  2328. qe.queue = index;
  2329. qe.class = SCHED_CLS_NONE;
  2330. err = cxgb4_sched_class_unbind(dev, (void *)(&qe), SCHED_QUEUE);
  2331. if (err) {
  2332. dev_err(adap->pdev_dev,
  2333. "Unbinding Queue %d on port %d fail. Err: %d\n",
  2334. index, pi->port_id, err);
  2335. return err;
  2336. }
  2337. /* Queue already unbound */
  2338. if (!req_rate)
  2339. return 0;
  2340. /* Fetch any available unused or matching scheduling class */
  2341. memset(&p, 0, sizeof(p));
  2342. p.type = SCHED_CLASS_TYPE_PACKET;
  2343. p.u.params.level = SCHED_CLASS_LEVEL_CL_RL;
  2344. p.u.params.mode = SCHED_CLASS_MODE_CLASS;
  2345. p.u.params.rateunit = SCHED_CLASS_RATEUNIT_BITS;
  2346. p.u.params.ratemode = SCHED_CLASS_RATEMODE_ABS;
  2347. p.u.params.channel = pi->tx_chan;
  2348. p.u.params.class = SCHED_CLS_NONE;
  2349. p.u.params.minrate = 0;
  2350. p.u.params.maxrate = req_rate;
  2351. p.u.params.weight = 0;
  2352. p.u.params.pktsize = dev->mtu;
  2353. e = cxgb4_sched_class_alloc(dev, &p);
  2354. if (!e)
  2355. return -ENOMEM;
  2356. /* Bind the queue to a scheduling class */
  2357. memset(&qe, 0, sizeof(qe));
  2358. qe.queue = index;
  2359. qe.class = e->idx;
  2360. err = cxgb4_sched_class_bind(dev, (void *)(&qe), SCHED_QUEUE);
  2361. if (err)
  2362. dev_err(adap->pdev_dev,
  2363. "Queue rate limiting failed. Err: %d\n", err);
  2364. return err;
  2365. }
  2366. static int cxgb_setup_tc(struct net_device *dev, u32 handle, __be16 proto,
  2367. struct tc_to_netdev *tc)
  2368. {
  2369. struct port_info *pi = netdev2pinfo(dev);
  2370. struct adapter *adap = netdev2adap(dev);
  2371. if (!(adap->flags & FULL_INIT_DONE)) {
  2372. dev_err(adap->pdev_dev,
  2373. "Failed to setup tc on port %d. Link Down?\n",
  2374. pi->port_id);
  2375. return -EINVAL;
  2376. }
  2377. if (TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS) &&
  2378. tc->type == TC_SETUP_CLSU32) {
  2379. switch (tc->cls_u32->command) {
  2380. case TC_CLSU32_NEW_KNODE:
  2381. case TC_CLSU32_REPLACE_KNODE:
  2382. return cxgb4_config_knode(dev, proto, tc->cls_u32);
  2383. case TC_CLSU32_DELETE_KNODE:
  2384. return cxgb4_delete_knode(dev, proto, tc->cls_u32);
  2385. default:
  2386. return -EOPNOTSUPP;
  2387. }
  2388. }
  2389. return -EOPNOTSUPP;
  2390. }
  2391. static const struct net_device_ops cxgb4_netdev_ops = {
  2392. .ndo_open = cxgb_open,
  2393. .ndo_stop = cxgb_close,
  2394. .ndo_start_xmit = t4_eth_xmit,
  2395. .ndo_select_queue = cxgb_select_queue,
  2396. .ndo_get_stats64 = cxgb_get_stats,
  2397. .ndo_set_rx_mode = cxgb_set_rxmode,
  2398. .ndo_set_mac_address = cxgb_set_mac_addr,
  2399. .ndo_set_features = cxgb_set_features,
  2400. .ndo_validate_addr = eth_validate_addr,
  2401. .ndo_do_ioctl = cxgb_ioctl,
  2402. .ndo_change_mtu = cxgb_change_mtu,
  2403. #ifdef CONFIG_NET_POLL_CONTROLLER
  2404. .ndo_poll_controller = cxgb_netpoll,
  2405. #endif
  2406. #ifdef CONFIG_CHELSIO_T4_FCOE
  2407. .ndo_fcoe_enable = cxgb_fcoe_enable,
  2408. .ndo_fcoe_disable = cxgb_fcoe_disable,
  2409. #endif /* CONFIG_CHELSIO_T4_FCOE */
  2410. .ndo_set_tx_maxrate = cxgb_set_tx_maxrate,
  2411. .ndo_setup_tc = cxgb_setup_tc,
  2412. };
  2413. #ifdef CONFIG_PCI_IOV
  2414. static const struct net_device_ops cxgb4_mgmt_netdev_ops = {
  2415. .ndo_open = dummy_open,
  2416. .ndo_set_vf_mac = cxgb_set_vf_mac,
  2417. .ndo_get_vf_config = cxgb_get_vf_config,
  2418. .ndo_get_phys_port_id = cxgb_get_phys_port_id,
  2419. };
  2420. #endif
  2421. static void get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  2422. {
  2423. struct adapter *adapter = netdev2adap(dev);
  2424. strlcpy(info->driver, cxgb4_driver_name, sizeof(info->driver));
  2425. strlcpy(info->version, cxgb4_driver_version,
  2426. sizeof(info->version));
  2427. strlcpy(info->bus_info, pci_name(adapter->pdev),
  2428. sizeof(info->bus_info));
  2429. }
  2430. static const struct ethtool_ops cxgb4_mgmt_ethtool_ops = {
  2431. .get_drvinfo = get_drvinfo,
  2432. };
  2433. void t4_fatal_err(struct adapter *adap)
  2434. {
  2435. int port;
  2436. /* Disable the SGE since ULDs are going to free resources that
  2437. * could be exposed to the adapter. RDMA MWs for example...
  2438. */
  2439. t4_shutdown_adapter(adap);
  2440. for_each_port(adap, port) {
  2441. struct net_device *dev = adap->port[port];
  2442. /* If we get here in very early initialization the network
  2443. * devices may not have been set up yet.
  2444. */
  2445. if (!dev)
  2446. continue;
  2447. netif_tx_stop_all_queues(dev);
  2448. netif_carrier_off(dev);
  2449. }
  2450. dev_alert(adap->pdev_dev, "encountered fatal error, adapter stopped\n");
  2451. }
  2452. static void setup_memwin(struct adapter *adap)
  2453. {
  2454. u32 nic_win_base = t4_get_util_window(adap);
  2455. t4_setup_memwin(adap, nic_win_base, MEMWIN_NIC);
  2456. }
  2457. static void setup_memwin_rdma(struct adapter *adap)
  2458. {
  2459. if (adap->vres.ocq.size) {
  2460. u32 start;
  2461. unsigned int sz_kb;
  2462. start = t4_read_pcie_cfg4(adap, PCI_BASE_ADDRESS_2);
  2463. start &= PCI_BASE_ADDRESS_MEM_MASK;
  2464. start += OCQ_WIN_OFFSET(adap->pdev, &adap->vres);
  2465. sz_kb = roundup_pow_of_two(adap->vres.ocq.size) >> 10;
  2466. t4_write_reg(adap,
  2467. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_BASE_WIN_A, 3),
  2468. start | BIR_V(1) | WINDOW_V(ilog2(sz_kb)));
  2469. t4_write_reg(adap,
  2470. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3),
  2471. adap->vres.ocq.start);
  2472. t4_read_reg(adap,
  2473. PCIE_MEM_ACCESS_REG(PCIE_MEM_ACCESS_OFFSET_A, 3));
  2474. }
  2475. }
  2476. static int adap_init1(struct adapter *adap, struct fw_caps_config_cmd *c)
  2477. {
  2478. u32 v;
  2479. int ret;
  2480. /* get device capabilities */
  2481. memset(c, 0, sizeof(*c));
  2482. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  2483. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  2484. c->cfvalid_to_len16 = htonl(FW_LEN16(*c));
  2485. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), c);
  2486. if (ret < 0)
  2487. return ret;
  2488. c->op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  2489. FW_CMD_REQUEST_F | FW_CMD_WRITE_F);
  2490. ret = t4_wr_mbox(adap, adap->mbox, c, sizeof(*c), NULL);
  2491. if (ret < 0)
  2492. return ret;
  2493. ret = t4_config_glbl_rss(adap, adap->pf,
  2494. FW_RSS_GLB_CONFIG_CMD_MODE_BASICVIRTUAL,
  2495. FW_RSS_GLB_CONFIG_CMD_TNLMAPEN_F |
  2496. FW_RSS_GLB_CONFIG_CMD_TNLALLLKP_F);
  2497. if (ret < 0)
  2498. return ret;
  2499. ret = t4_cfg_pfvf(adap, adap->mbox, adap->pf, 0, adap->sge.egr_sz, 64,
  2500. MAX_INGQ, 0, 0, 4, 0xf, 0xf, 16, FW_CMD_CAP_PF,
  2501. FW_CMD_CAP_PF);
  2502. if (ret < 0)
  2503. return ret;
  2504. t4_sge_init(adap);
  2505. /* tweak some settings */
  2506. t4_write_reg(adap, TP_SHIFT_CNT_A, 0x64f8849);
  2507. t4_write_reg(adap, ULP_RX_TDDP_PSZ_A, HPZ0_V(PAGE_SHIFT - 12));
  2508. t4_write_reg(adap, TP_PIO_ADDR_A, TP_INGRESS_CONFIG_A);
  2509. v = t4_read_reg(adap, TP_PIO_DATA_A);
  2510. t4_write_reg(adap, TP_PIO_DATA_A, v & ~CSUM_HAS_PSEUDO_HDR_F);
  2511. /* first 4 Tx modulation queues point to consecutive Tx channels */
  2512. adap->params.tp.tx_modq_map = 0xE4;
  2513. t4_write_reg(adap, TP_TX_MOD_QUEUE_REQ_MAP_A,
  2514. TX_MOD_QUEUE_REQ_MAP_V(adap->params.tp.tx_modq_map));
  2515. /* associate each Tx modulation queue with consecutive Tx channels */
  2516. v = 0x84218421;
  2517. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2518. &v, 1, TP_TX_SCHED_HDR_A);
  2519. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2520. &v, 1, TP_TX_SCHED_FIFO_A);
  2521. t4_write_indirect(adap, TP_PIO_ADDR_A, TP_PIO_DATA_A,
  2522. &v, 1, TP_TX_SCHED_PCMD_A);
  2523. #define T4_TX_MODQ_10G_WEIGHT_DEFAULT 16 /* in KB units */
  2524. if (is_offload(adap)) {
  2525. t4_write_reg(adap, TP_TX_MOD_QUEUE_WEIGHT0_A,
  2526. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2527. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2528. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2529. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  2530. t4_write_reg(adap, TP_TX_MOD_CHANNEL_WEIGHT_A,
  2531. TX_MODQ_WEIGHT0_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2532. TX_MODQ_WEIGHT1_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2533. TX_MODQ_WEIGHT2_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT) |
  2534. TX_MODQ_WEIGHT3_V(T4_TX_MODQ_10G_WEIGHT_DEFAULT));
  2535. }
  2536. /* get basic stuff going */
  2537. return t4_early_init(adap, adap->pf);
  2538. }
  2539. /*
  2540. * Max # of ATIDs. The absolute HW max is 16K but we keep it lower.
  2541. */
  2542. #define MAX_ATIDS 8192U
  2543. /*
  2544. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  2545. *
  2546. * If the firmware we're dealing with has Configuration File support, then
  2547. * we use that to perform all configuration
  2548. */
  2549. /*
  2550. * Tweak configuration based on module parameters, etc. Most of these have
  2551. * defaults assigned to them by Firmware Configuration Files (if we're using
  2552. * them) but need to be explicitly set if we're using hard-coded
  2553. * initialization. But even in the case of using Firmware Configuration
  2554. * Files, we'd like to expose the ability to change these via module
  2555. * parameters so these are essentially common tweaks/settings for
  2556. * Configuration Files and hard-coded initialization ...
  2557. */
  2558. static int adap_init0_tweaks(struct adapter *adapter)
  2559. {
  2560. /*
  2561. * Fix up various Host-Dependent Parameters like Page Size, Cache
  2562. * Line Size, etc. The firmware default is for a 4KB Page Size and
  2563. * 64B Cache Line Size ...
  2564. */
  2565. t4_fixup_host_params(adapter, PAGE_SIZE, L1_CACHE_BYTES);
  2566. /*
  2567. * Process module parameters which affect early initialization.
  2568. */
  2569. if (rx_dma_offset != 2 && rx_dma_offset != 0) {
  2570. dev_err(&adapter->pdev->dev,
  2571. "Ignoring illegal rx_dma_offset=%d, using 2\n",
  2572. rx_dma_offset);
  2573. rx_dma_offset = 2;
  2574. }
  2575. t4_set_reg_field(adapter, SGE_CONTROL_A,
  2576. PKTSHIFT_V(PKTSHIFT_M),
  2577. PKTSHIFT_V(rx_dma_offset));
  2578. /*
  2579. * Don't include the "IP Pseudo Header" in CPL_RX_PKT checksums: Linux
  2580. * adds the pseudo header itself.
  2581. */
  2582. t4_tp_wr_bits_indirect(adapter, TP_INGRESS_CONFIG_A,
  2583. CSUM_HAS_PSEUDO_HDR_F, 0);
  2584. return 0;
  2585. }
  2586. /* 10Gb/s-BT PHY Support. chip-external 10Gb/s-BT PHYs are complex chips
  2587. * unto themselves and they contain their own firmware to perform their
  2588. * tasks ...
  2589. */
  2590. static int phy_aq1202_version(const u8 *phy_fw_data,
  2591. size_t phy_fw_size)
  2592. {
  2593. int offset;
  2594. /* At offset 0x8 you're looking for the primary image's
  2595. * starting offset which is 3 Bytes wide
  2596. *
  2597. * At offset 0xa of the primary image, you look for the offset
  2598. * of the DRAM segment which is 3 Bytes wide.
  2599. *
  2600. * The FW version is at offset 0x27e of the DRAM and is 2 Bytes
  2601. * wide
  2602. */
  2603. #define be16(__p) (((__p)[0] << 8) | (__p)[1])
  2604. #define le16(__p) ((__p)[0] | ((__p)[1] << 8))
  2605. #define le24(__p) (le16(__p) | ((__p)[2] << 16))
  2606. offset = le24(phy_fw_data + 0x8) << 12;
  2607. offset = le24(phy_fw_data + offset + 0xa);
  2608. return be16(phy_fw_data + offset + 0x27e);
  2609. #undef be16
  2610. #undef le16
  2611. #undef le24
  2612. }
  2613. static struct info_10gbt_phy_fw {
  2614. unsigned int phy_fw_id; /* PCI Device ID */
  2615. char *phy_fw_file; /* /lib/firmware/ PHY Firmware file */
  2616. int (*phy_fw_version)(const u8 *phy_fw_data, size_t phy_fw_size);
  2617. int phy_flash; /* Has FLASH for PHY Firmware */
  2618. } phy_info_array[] = {
  2619. {
  2620. PHY_AQ1202_DEVICEID,
  2621. PHY_AQ1202_FIRMWARE,
  2622. phy_aq1202_version,
  2623. 1,
  2624. },
  2625. {
  2626. PHY_BCM84834_DEVICEID,
  2627. PHY_BCM84834_FIRMWARE,
  2628. NULL,
  2629. 0,
  2630. },
  2631. { 0, NULL, NULL },
  2632. };
  2633. static struct info_10gbt_phy_fw *find_phy_info(int devid)
  2634. {
  2635. int i;
  2636. for (i = 0; i < ARRAY_SIZE(phy_info_array); i++) {
  2637. if (phy_info_array[i].phy_fw_id == devid)
  2638. return &phy_info_array[i];
  2639. }
  2640. return NULL;
  2641. }
  2642. /* Handle updating of chip-external 10Gb/s-BT PHY firmware. This needs to
  2643. * happen after the FW_RESET_CMD but before the FW_INITIALIZE_CMD. On error
  2644. * we return a negative error number. If we transfer new firmware we return 1
  2645. * (from t4_load_phy_fw()). If we don't do anything we return 0.
  2646. */
  2647. static int adap_init0_phy(struct adapter *adap)
  2648. {
  2649. const struct firmware *phyf;
  2650. int ret;
  2651. struct info_10gbt_phy_fw *phy_info;
  2652. /* Use the device ID to determine which PHY file to flash.
  2653. */
  2654. phy_info = find_phy_info(adap->pdev->device);
  2655. if (!phy_info) {
  2656. dev_warn(adap->pdev_dev,
  2657. "No PHY Firmware file found for this PHY\n");
  2658. return -EOPNOTSUPP;
  2659. }
  2660. /* If we have a T4 PHY firmware file under /lib/firmware/cxgb4/, then
  2661. * use that. The adapter firmware provides us with a memory buffer
  2662. * where we can load a PHY firmware file from the host if we want to
  2663. * override the PHY firmware File in flash.
  2664. */
  2665. ret = request_firmware_direct(&phyf, phy_info->phy_fw_file,
  2666. adap->pdev_dev);
  2667. if (ret < 0) {
  2668. /* For adapters without FLASH attached to PHY for their
  2669. * firmware, it's obviously a fatal error if we can't get the
  2670. * firmware to the adapter. For adapters with PHY firmware
  2671. * FLASH storage, it's worth a warning if we can't find the
  2672. * PHY Firmware but we'll neuter the error ...
  2673. */
  2674. dev_err(adap->pdev_dev, "unable to find PHY Firmware image "
  2675. "/lib/firmware/%s, error %d\n",
  2676. phy_info->phy_fw_file, -ret);
  2677. if (phy_info->phy_flash) {
  2678. int cur_phy_fw_ver = 0;
  2679. t4_phy_fw_ver(adap, &cur_phy_fw_ver);
  2680. dev_warn(adap->pdev_dev, "continuing with, on-adapter "
  2681. "FLASH copy, version %#x\n", cur_phy_fw_ver);
  2682. ret = 0;
  2683. }
  2684. return ret;
  2685. }
  2686. /* Load PHY Firmware onto adapter.
  2687. */
  2688. ret = t4_load_phy_fw(adap, MEMWIN_NIC, &adap->win0_lock,
  2689. phy_info->phy_fw_version,
  2690. (u8 *)phyf->data, phyf->size);
  2691. if (ret < 0)
  2692. dev_err(adap->pdev_dev, "PHY Firmware transfer error %d\n",
  2693. -ret);
  2694. else if (ret > 0) {
  2695. int new_phy_fw_ver = 0;
  2696. if (phy_info->phy_fw_version)
  2697. new_phy_fw_ver = phy_info->phy_fw_version(phyf->data,
  2698. phyf->size);
  2699. dev_info(adap->pdev_dev, "Successfully transferred PHY "
  2700. "Firmware /lib/firmware/%s, version %#x\n",
  2701. phy_info->phy_fw_file, new_phy_fw_ver);
  2702. }
  2703. release_firmware(phyf);
  2704. return ret;
  2705. }
  2706. /*
  2707. * Attempt to initialize the adapter via a Firmware Configuration File.
  2708. */
  2709. static int adap_init0_config(struct adapter *adapter, int reset)
  2710. {
  2711. struct fw_caps_config_cmd caps_cmd;
  2712. const struct firmware *cf;
  2713. unsigned long mtype = 0, maddr = 0;
  2714. u32 finiver, finicsum, cfcsum;
  2715. int ret;
  2716. int config_issued = 0;
  2717. char *fw_config_file, fw_config_file_path[256];
  2718. char *config_name = NULL;
  2719. /*
  2720. * Reset device if necessary.
  2721. */
  2722. if (reset) {
  2723. ret = t4_fw_reset(adapter, adapter->mbox,
  2724. PIORSTMODE_F | PIORST_F);
  2725. if (ret < 0)
  2726. goto bye;
  2727. }
  2728. /* If this is a 10Gb/s-BT adapter make sure the chip-external
  2729. * 10Gb/s-BT PHYs have up-to-date firmware. Note that this step needs
  2730. * to be performed after any global adapter RESET above since some
  2731. * PHYs only have local RAM copies of the PHY firmware.
  2732. */
  2733. if (is_10gbt_device(adapter->pdev->device)) {
  2734. ret = adap_init0_phy(adapter);
  2735. if (ret < 0)
  2736. goto bye;
  2737. }
  2738. /*
  2739. * If we have a T4 configuration file under /lib/firmware/cxgb4/,
  2740. * then use that. Otherwise, use the configuration file stored
  2741. * in the adapter flash ...
  2742. */
  2743. switch (CHELSIO_CHIP_VERSION(adapter->params.chip)) {
  2744. case CHELSIO_T4:
  2745. fw_config_file = FW4_CFNAME;
  2746. break;
  2747. case CHELSIO_T5:
  2748. fw_config_file = FW5_CFNAME;
  2749. break;
  2750. case CHELSIO_T6:
  2751. fw_config_file = FW6_CFNAME;
  2752. break;
  2753. default:
  2754. dev_err(adapter->pdev_dev, "Device %d is not supported\n",
  2755. adapter->pdev->device);
  2756. ret = -EINVAL;
  2757. goto bye;
  2758. }
  2759. ret = request_firmware(&cf, fw_config_file, adapter->pdev_dev);
  2760. if (ret < 0) {
  2761. config_name = "On FLASH";
  2762. mtype = FW_MEMTYPE_CF_FLASH;
  2763. maddr = t4_flash_cfg_addr(adapter);
  2764. } else {
  2765. u32 params[7], val[7];
  2766. sprintf(fw_config_file_path,
  2767. "/lib/firmware/%s", fw_config_file);
  2768. config_name = fw_config_file_path;
  2769. if (cf->size >= FLASH_CFG_MAX_SIZE)
  2770. ret = -ENOMEM;
  2771. else {
  2772. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  2773. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  2774. ret = t4_query_params(adapter, adapter->mbox,
  2775. adapter->pf, 0, 1, params, val);
  2776. if (ret == 0) {
  2777. /*
  2778. * For t4_memory_rw() below addresses and
  2779. * sizes have to be in terms of multiples of 4
  2780. * bytes. So, if the Configuration File isn't
  2781. * a multiple of 4 bytes in length we'll have
  2782. * to write that out separately since we can't
  2783. * guarantee that the bytes following the
  2784. * residual byte in the buffer returned by
  2785. * request_firmware() are zeroed out ...
  2786. */
  2787. size_t resid = cf->size & 0x3;
  2788. size_t size = cf->size & ~0x3;
  2789. __be32 *data = (__be32 *)cf->data;
  2790. mtype = FW_PARAMS_PARAM_Y_G(val[0]);
  2791. maddr = FW_PARAMS_PARAM_Z_G(val[0]) << 16;
  2792. spin_lock(&adapter->win0_lock);
  2793. ret = t4_memory_rw(adapter, 0, mtype, maddr,
  2794. size, data, T4_MEMORY_WRITE);
  2795. if (ret == 0 && resid != 0) {
  2796. union {
  2797. __be32 word;
  2798. char buf[4];
  2799. } last;
  2800. int i;
  2801. last.word = data[size >> 2];
  2802. for (i = resid; i < 4; i++)
  2803. last.buf[i] = 0;
  2804. ret = t4_memory_rw(adapter, 0, mtype,
  2805. maddr + size,
  2806. 4, &last.word,
  2807. T4_MEMORY_WRITE);
  2808. }
  2809. spin_unlock(&adapter->win0_lock);
  2810. }
  2811. }
  2812. release_firmware(cf);
  2813. if (ret)
  2814. goto bye;
  2815. }
  2816. /*
  2817. * Issue a Capability Configuration command to the firmware to get it
  2818. * to parse the Configuration File. We don't use t4_fw_config_file()
  2819. * because we want the ability to modify various features after we've
  2820. * processed the configuration file ...
  2821. */
  2822. memset(&caps_cmd, 0, sizeof(caps_cmd));
  2823. caps_cmd.op_to_write =
  2824. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  2825. FW_CMD_REQUEST_F |
  2826. FW_CMD_READ_F);
  2827. caps_cmd.cfvalid_to_len16 =
  2828. htonl(FW_CAPS_CONFIG_CMD_CFVALID_F |
  2829. FW_CAPS_CONFIG_CMD_MEMTYPE_CF_V(mtype) |
  2830. FW_CAPS_CONFIG_CMD_MEMADDR64K_CF_V(maddr >> 16) |
  2831. FW_LEN16(caps_cmd));
  2832. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  2833. &caps_cmd);
  2834. /* If the CAPS_CONFIG failed with an ENOENT (for a Firmware
  2835. * Configuration File in FLASH), our last gasp effort is to use the
  2836. * Firmware Configuration File which is embedded in the firmware. A
  2837. * very few early versions of the firmware didn't have one embedded
  2838. * but we can ignore those.
  2839. */
  2840. if (ret == -ENOENT) {
  2841. memset(&caps_cmd, 0, sizeof(caps_cmd));
  2842. caps_cmd.op_to_write =
  2843. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  2844. FW_CMD_REQUEST_F |
  2845. FW_CMD_READ_F);
  2846. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  2847. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd,
  2848. sizeof(caps_cmd), &caps_cmd);
  2849. config_name = "Firmware Default";
  2850. }
  2851. config_issued = 1;
  2852. if (ret < 0)
  2853. goto bye;
  2854. finiver = ntohl(caps_cmd.finiver);
  2855. finicsum = ntohl(caps_cmd.finicsum);
  2856. cfcsum = ntohl(caps_cmd.cfcsum);
  2857. if (finicsum != cfcsum)
  2858. dev_warn(adapter->pdev_dev, "Configuration File checksum "\
  2859. "mismatch: [fini] csum=%#x, computed csum=%#x\n",
  2860. finicsum, cfcsum);
  2861. /*
  2862. * And now tell the firmware to use the configuration we just loaded.
  2863. */
  2864. caps_cmd.op_to_write =
  2865. htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  2866. FW_CMD_REQUEST_F |
  2867. FW_CMD_WRITE_F);
  2868. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  2869. ret = t4_wr_mbox(adapter, adapter->mbox, &caps_cmd, sizeof(caps_cmd),
  2870. NULL);
  2871. if (ret < 0)
  2872. goto bye;
  2873. /*
  2874. * Tweak configuration based on system architecture, module
  2875. * parameters, etc.
  2876. */
  2877. ret = adap_init0_tweaks(adapter);
  2878. if (ret < 0)
  2879. goto bye;
  2880. /*
  2881. * And finally tell the firmware to initialize itself using the
  2882. * parameters from the Configuration File.
  2883. */
  2884. ret = t4_fw_initialize(adapter, adapter->mbox);
  2885. if (ret < 0)
  2886. goto bye;
  2887. /* Emit Firmware Configuration File information and return
  2888. * successfully.
  2889. */
  2890. dev_info(adapter->pdev_dev, "Successfully configured using Firmware "\
  2891. "Configuration File \"%s\", version %#x, computed checksum %#x\n",
  2892. config_name, finiver, cfcsum);
  2893. return 0;
  2894. /*
  2895. * Something bad happened. Return the error ... (If the "error"
  2896. * is that there's no Configuration File on the adapter we don't
  2897. * want to issue a warning since this is fairly common.)
  2898. */
  2899. bye:
  2900. if (config_issued && ret != -ENOENT)
  2901. dev_warn(adapter->pdev_dev, "\"%s\" configuration file error %d\n",
  2902. config_name, -ret);
  2903. return ret;
  2904. }
  2905. static struct fw_info fw_info_array[] = {
  2906. {
  2907. .chip = CHELSIO_T4,
  2908. .fs_name = FW4_CFNAME,
  2909. .fw_mod_name = FW4_FNAME,
  2910. .fw_hdr = {
  2911. .chip = FW_HDR_CHIP_T4,
  2912. .fw_ver = __cpu_to_be32(FW_VERSION(T4)),
  2913. .intfver_nic = FW_INTFVER(T4, NIC),
  2914. .intfver_vnic = FW_INTFVER(T4, VNIC),
  2915. .intfver_ri = FW_INTFVER(T4, RI),
  2916. .intfver_iscsi = FW_INTFVER(T4, ISCSI),
  2917. .intfver_fcoe = FW_INTFVER(T4, FCOE),
  2918. },
  2919. }, {
  2920. .chip = CHELSIO_T5,
  2921. .fs_name = FW5_CFNAME,
  2922. .fw_mod_name = FW5_FNAME,
  2923. .fw_hdr = {
  2924. .chip = FW_HDR_CHIP_T5,
  2925. .fw_ver = __cpu_to_be32(FW_VERSION(T5)),
  2926. .intfver_nic = FW_INTFVER(T5, NIC),
  2927. .intfver_vnic = FW_INTFVER(T5, VNIC),
  2928. .intfver_ri = FW_INTFVER(T5, RI),
  2929. .intfver_iscsi = FW_INTFVER(T5, ISCSI),
  2930. .intfver_fcoe = FW_INTFVER(T5, FCOE),
  2931. },
  2932. }, {
  2933. .chip = CHELSIO_T6,
  2934. .fs_name = FW6_CFNAME,
  2935. .fw_mod_name = FW6_FNAME,
  2936. .fw_hdr = {
  2937. .chip = FW_HDR_CHIP_T6,
  2938. .fw_ver = __cpu_to_be32(FW_VERSION(T6)),
  2939. .intfver_nic = FW_INTFVER(T6, NIC),
  2940. .intfver_vnic = FW_INTFVER(T6, VNIC),
  2941. .intfver_ofld = FW_INTFVER(T6, OFLD),
  2942. .intfver_ri = FW_INTFVER(T6, RI),
  2943. .intfver_iscsipdu = FW_INTFVER(T6, ISCSIPDU),
  2944. .intfver_iscsi = FW_INTFVER(T6, ISCSI),
  2945. .intfver_fcoepdu = FW_INTFVER(T6, FCOEPDU),
  2946. .intfver_fcoe = FW_INTFVER(T6, FCOE),
  2947. },
  2948. }
  2949. };
  2950. static struct fw_info *find_fw_info(int chip)
  2951. {
  2952. int i;
  2953. for (i = 0; i < ARRAY_SIZE(fw_info_array); i++) {
  2954. if (fw_info_array[i].chip == chip)
  2955. return &fw_info_array[i];
  2956. }
  2957. return NULL;
  2958. }
  2959. /*
  2960. * Phase 0 of initialization: contact FW, obtain config, perform basic init.
  2961. */
  2962. static int adap_init0(struct adapter *adap)
  2963. {
  2964. int ret;
  2965. u32 v, port_vec;
  2966. enum dev_state state;
  2967. u32 params[7], val[7];
  2968. struct fw_caps_config_cmd caps_cmd;
  2969. int reset = 1;
  2970. /* Grab Firmware Device Log parameters as early as possible so we have
  2971. * access to it for debugging, etc.
  2972. */
  2973. ret = t4_init_devlog_params(adap);
  2974. if (ret < 0)
  2975. return ret;
  2976. /* Contact FW, advertising Master capability */
  2977. ret = t4_fw_hello(adap, adap->mbox, adap->mbox,
  2978. is_kdump_kernel() ? MASTER_MUST : MASTER_MAY, &state);
  2979. if (ret < 0) {
  2980. dev_err(adap->pdev_dev, "could not connect to FW, error %d\n",
  2981. ret);
  2982. return ret;
  2983. }
  2984. if (ret == adap->mbox)
  2985. adap->flags |= MASTER_PF;
  2986. /*
  2987. * If we're the Master PF Driver and the device is uninitialized,
  2988. * then let's consider upgrading the firmware ... (We always want
  2989. * to check the firmware version number in order to A. get it for
  2990. * later reporting and B. to warn if the currently loaded firmware
  2991. * is excessively mismatched relative to the driver.)
  2992. */
  2993. t4_get_fw_version(adap, &adap->params.fw_vers);
  2994. t4_get_bs_version(adap, &adap->params.bs_vers);
  2995. t4_get_tp_version(adap, &adap->params.tp_vers);
  2996. t4_get_exprom_version(adap, &adap->params.er_vers);
  2997. ret = t4_check_fw_version(adap);
  2998. /* If firmware is too old (not supported by driver) force an update. */
  2999. if (ret)
  3000. state = DEV_STATE_UNINIT;
  3001. if ((adap->flags & MASTER_PF) && state != DEV_STATE_INIT) {
  3002. struct fw_info *fw_info;
  3003. struct fw_hdr *card_fw;
  3004. const struct firmware *fw;
  3005. const u8 *fw_data = NULL;
  3006. unsigned int fw_size = 0;
  3007. /* This is the firmware whose headers the driver was compiled
  3008. * against
  3009. */
  3010. fw_info = find_fw_info(CHELSIO_CHIP_VERSION(adap->params.chip));
  3011. if (fw_info == NULL) {
  3012. dev_err(adap->pdev_dev,
  3013. "unable to get firmware info for chip %d.\n",
  3014. CHELSIO_CHIP_VERSION(adap->params.chip));
  3015. return -EINVAL;
  3016. }
  3017. /* allocate memory to read the header of the firmware on the
  3018. * card
  3019. */
  3020. card_fw = t4_alloc_mem(sizeof(*card_fw));
  3021. /* Get FW from from /lib/firmware/ */
  3022. ret = request_firmware(&fw, fw_info->fw_mod_name,
  3023. adap->pdev_dev);
  3024. if (ret < 0) {
  3025. dev_err(adap->pdev_dev,
  3026. "unable to load firmware image %s, error %d\n",
  3027. fw_info->fw_mod_name, ret);
  3028. } else {
  3029. fw_data = fw->data;
  3030. fw_size = fw->size;
  3031. }
  3032. /* upgrade FW logic */
  3033. ret = t4_prep_fw(adap, fw_info, fw_data, fw_size, card_fw,
  3034. state, &reset);
  3035. /* Cleaning up */
  3036. release_firmware(fw);
  3037. t4_free_mem(card_fw);
  3038. if (ret < 0)
  3039. goto bye;
  3040. }
  3041. /*
  3042. * Grab VPD parameters. This should be done after we establish a
  3043. * connection to the firmware since some of the VPD parameters
  3044. * (notably the Core Clock frequency) are retrieved via requests to
  3045. * the firmware. On the other hand, we need these fairly early on
  3046. * so we do this right after getting ahold of the firmware.
  3047. */
  3048. ret = t4_get_vpd_params(adap, &adap->params.vpd);
  3049. if (ret < 0)
  3050. goto bye;
  3051. /*
  3052. * Find out what ports are available to us. Note that we need to do
  3053. * this before calling adap_init0_no_config() since it needs nports
  3054. * and portvec ...
  3055. */
  3056. v =
  3057. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3058. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
  3059. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1, &v, &port_vec);
  3060. if (ret < 0)
  3061. goto bye;
  3062. adap->params.nports = hweight32(port_vec);
  3063. adap->params.portvec = port_vec;
  3064. /* If the firmware is initialized already, emit a simply note to that
  3065. * effect. Otherwise, it's time to try initializing the adapter.
  3066. */
  3067. if (state == DEV_STATE_INIT) {
  3068. dev_info(adap->pdev_dev, "Coming up as %s: "\
  3069. "Adapter already initialized\n",
  3070. adap->flags & MASTER_PF ? "MASTER" : "SLAVE");
  3071. } else {
  3072. dev_info(adap->pdev_dev, "Coming up as MASTER: "\
  3073. "Initializing adapter\n");
  3074. /* Find out whether we're dealing with a version of the
  3075. * firmware which has configuration file support.
  3076. */
  3077. params[0] = (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  3078. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_CF));
  3079. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 1,
  3080. params, val);
  3081. /* If the firmware doesn't support Configuration Files,
  3082. * return an error.
  3083. */
  3084. if (ret < 0) {
  3085. dev_err(adap->pdev_dev, "firmware doesn't support "
  3086. "Firmware Configuration Files\n");
  3087. goto bye;
  3088. }
  3089. /* The firmware provides us with a memory buffer where we can
  3090. * load a Configuration File from the host if we want to
  3091. * override the Configuration File in flash.
  3092. */
  3093. ret = adap_init0_config(adap, reset);
  3094. if (ret == -ENOENT) {
  3095. dev_err(adap->pdev_dev, "no Configuration File "
  3096. "present on adapter.\n");
  3097. goto bye;
  3098. }
  3099. if (ret < 0) {
  3100. dev_err(adap->pdev_dev, "could not initialize "
  3101. "adapter, error %d\n", -ret);
  3102. goto bye;
  3103. }
  3104. }
  3105. /* Give the SGE code a chance to pull in anything that it needs ...
  3106. * Note that this must be called after we retrieve our VPD parameters
  3107. * in order to know how to convert core ticks to seconds, etc.
  3108. */
  3109. ret = t4_sge_init(adap);
  3110. if (ret < 0)
  3111. goto bye;
  3112. if (is_bypass_device(adap->pdev->device))
  3113. adap->params.bypass = 1;
  3114. /*
  3115. * Grab some of our basic fundamental operating parameters.
  3116. */
  3117. #define FW_PARAM_DEV(param) \
  3118. (FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) | \
  3119. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_##param))
  3120. #define FW_PARAM_PFVF(param) \
  3121. FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_PFVF) | \
  3122. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_PFVF_##param)| \
  3123. FW_PARAMS_PARAM_Y_V(0) | \
  3124. FW_PARAMS_PARAM_Z_V(0)
  3125. params[0] = FW_PARAM_PFVF(EQ_START);
  3126. params[1] = FW_PARAM_PFVF(L2T_START);
  3127. params[2] = FW_PARAM_PFVF(L2T_END);
  3128. params[3] = FW_PARAM_PFVF(FILTER_START);
  3129. params[4] = FW_PARAM_PFVF(FILTER_END);
  3130. params[5] = FW_PARAM_PFVF(IQFLINT_START);
  3131. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params, val);
  3132. if (ret < 0)
  3133. goto bye;
  3134. adap->sge.egr_start = val[0];
  3135. adap->l2t_start = val[1];
  3136. adap->l2t_end = val[2];
  3137. adap->tids.ftid_base = val[3];
  3138. adap->tids.nftids = val[4] - val[3] + 1;
  3139. adap->sge.ingr_start = val[5];
  3140. /* qids (ingress/egress) returned from firmware can be anywhere
  3141. * in the range from EQ(IQFLINT)_START to EQ(IQFLINT)_END.
  3142. * Hence driver needs to allocate memory for this range to
  3143. * store the queue info. Get the highest IQFLINT/EQ index returned
  3144. * in FW_EQ_*_CMD.alloc command.
  3145. */
  3146. params[0] = FW_PARAM_PFVF(EQ_END);
  3147. params[1] = FW_PARAM_PFVF(IQFLINT_END);
  3148. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3149. if (ret < 0)
  3150. goto bye;
  3151. adap->sge.egr_sz = val[0] - adap->sge.egr_start + 1;
  3152. adap->sge.ingr_sz = val[1] - adap->sge.ingr_start + 1;
  3153. adap->sge.egr_map = kcalloc(adap->sge.egr_sz,
  3154. sizeof(*adap->sge.egr_map), GFP_KERNEL);
  3155. if (!adap->sge.egr_map) {
  3156. ret = -ENOMEM;
  3157. goto bye;
  3158. }
  3159. adap->sge.ingr_map = kcalloc(adap->sge.ingr_sz,
  3160. sizeof(*adap->sge.ingr_map), GFP_KERNEL);
  3161. if (!adap->sge.ingr_map) {
  3162. ret = -ENOMEM;
  3163. goto bye;
  3164. }
  3165. /* Allocate the memory for the vaious egress queue bitmaps
  3166. * ie starving_fl, txq_maperr and blocked_fl.
  3167. */
  3168. adap->sge.starving_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3169. sizeof(long), GFP_KERNEL);
  3170. if (!adap->sge.starving_fl) {
  3171. ret = -ENOMEM;
  3172. goto bye;
  3173. }
  3174. adap->sge.txq_maperr = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3175. sizeof(long), GFP_KERNEL);
  3176. if (!adap->sge.txq_maperr) {
  3177. ret = -ENOMEM;
  3178. goto bye;
  3179. }
  3180. #ifdef CONFIG_DEBUG_FS
  3181. adap->sge.blocked_fl = kcalloc(BITS_TO_LONGS(adap->sge.egr_sz),
  3182. sizeof(long), GFP_KERNEL);
  3183. if (!adap->sge.blocked_fl) {
  3184. ret = -ENOMEM;
  3185. goto bye;
  3186. }
  3187. #endif
  3188. params[0] = FW_PARAM_PFVF(CLIP_START);
  3189. params[1] = FW_PARAM_PFVF(CLIP_END);
  3190. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3191. if (ret < 0)
  3192. goto bye;
  3193. adap->clipt_start = val[0];
  3194. adap->clipt_end = val[1];
  3195. /* We don't yet have a PARAMs calls to retrieve the number of Traffic
  3196. * Classes supported by the hardware/firmware so we hard code it here
  3197. * for now.
  3198. */
  3199. adap->params.nsched_cls = is_t4(adap->params.chip) ? 15 : 16;
  3200. /* query params related to active filter region */
  3201. params[0] = FW_PARAM_PFVF(ACTIVE_FILTER_START);
  3202. params[1] = FW_PARAM_PFVF(ACTIVE_FILTER_END);
  3203. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params, val);
  3204. /* If Active filter size is set we enable establishing
  3205. * offload connection through firmware work request
  3206. */
  3207. if ((val[0] != val[1]) && (ret >= 0)) {
  3208. adap->flags |= FW_OFLD_CONN;
  3209. adap->tids.aftid_base = val[0];
  3210. adap->tids.aftid_end = val[1];
  3211. }
  3212. /* If we're running on newer firmware, let it know that we're
  3213. * prepared to deal with encapsulated CPL messages. Older
  3214. * firmware won't understand this and we'll just get
  3215. * unencapsulated messages ...
  3216. */
  3217. params[0] = FW_PARAM_PFVF(CPLFW4MSG_ENCAP);
  3218. val[0] = 1;
  3219. (void)t4_set_params(adap, adap->mbox, adap->pf, 0, 1, params, val);
  3220. /*
  3221. * Find out whether we're allowed to use the T5+ ULPTX MEMWRITE DSGL
  3222. * capability. Earlier versions of the firmware didn't have the
  3223. * ULPTX_MEMWRITE_DSGL so we'll interpret a query failure as no
  3224. * permission to use ULPTX MEMWRITE DSGL.
  3225. */
  3226. if (is_t4(adap->params.chip)) {
  3227. adap->params.ulptx_memwrite_dsgl = false;
  3228. } else {
  3229. params[0] = FW_PARAM_DEV(ULPTX_MEMWRITE_DSGL);
  3230. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3231. 1, params, val);
  3232. adap->params.ulptx_memwrite_dsgl = (ret == 0 && val[0] != 0);
  3233. }
  3234. /* See if FW supports FW_RI_FR_NSMR_TPTE_WR work request */
  3235. params[0] = FW_PARAM_DEV(RI_FR_NSMR_TPTE_WR);
  3236. ret = t4_query_params(adap, adap->mbox, adap->pf, 0,
  3237. 1, params, val);
  3238. adap->params.fr_nsmr_tpte_wr_support = (ret == 0 && val[0] != 0);
  3239. /*
  3240. * Get device capabilities so we can determine what resources we need
  3241. * to manage.
  3242. */
  3243. memset(&caps_cmd, 0, sizeof(caps_cmd));
  3244. caps_cmd.op_to_write = htonl(FW_CMD_OP_V(FW_CAPS_CONFIG_CMD) |
  3245. FW_CMD_REQUEST_F | FW_CMD_READ_F);
  3246. caps_cmd.cfvalid_to_len16 = htonl(FW_LEN16(caps_cmd));
  3247. ret = t4_wr_mbox(adap, adap->mbox, &caps_cmd, sizeof(caps_cmd),
  3248. &caps_cmd);
  3249. if (ret < 0)
  3250. goto bye;
  3251. if (caps_cmd.ofldcaps) {
  3252. /* query offload-related parameters */
  3253. params[0] = FW_PARAM_DEV(NTID);
  3254. params[1] = FW_PARAM_PFVF(SERVER_START);
  3255. params[2] = FW_PARAM_PFVF(SERVER_END);
  3256. params[3] = FW_PARAM_PFVF(TDDP_START);
  3257. params[4] = FW_PARAM_PFVF(TDDP_END);
  3258. params[5] = FW_PARAM_DEV(FLOWC_BUFFIFO_SZ);
  3259. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3260. params, val);
  3261. if (ret < 0)
  3262. goto bye;
  3263. adap->tids.ntids = val[0];
  3264. adap->tids.natids = min(adap->tids.ntids / 2, MAX_ATIDS);
  3265. adap->tids.stid_base = val[1];
  3266. adap->tids.nstids = val[2] - val[1] + 1;
  3267. /*
  3268. * Setup server filter region. Divide the available filter
  3269. * region into two parts. Regular filters get 1/3rd and server
  3270. * filters get 2/3rd part. This is only enabled if workarond
  3271. * path is enabled.
  3272. * 1. For regular filters.
  3273. * 2. Server filter: This are special filters which are used
  3274. * to redirect SYN packets to offload queue.
  3275. */
  3276. if (adap->flags & FW_OFLD_CONN && !is_bypass(adap)) {
  3277. adap->tids.sftid_base = adap->tids.ftid_base +
  3278. DIV_ROUND_UP(adap->tids.nftids, 3);
  3279. adap->tids.nsftids = adap->tids.nftids -
  3280. DIV_ROUND_UP(adap->tids.nftids, 3);
  3281. adap->tids.nftids = adap->tids.sftid_base -
  3282. adap->tids.ftid_base;
  3283. }
  3284. adap->vres.ddp.start = val[3];
  3285. adap->vres.ddp.size = val[4] - val[3] + 1;
  3286. adap->params.ofldq_wr_cred = val[5];
  3287. adap->params.offload = 1;
  3288. adap->num_ofld_uld += 1;
  3289. }
  3290. if (caps_cmd.rdmacaps) {
  3291. params[0] = FW_PARAM_PFVF(STAG_START);
  3292. params[1] = FW_PARAM_PFVF(STAG_END);
  3293. params[2] = FW_PARAM_PFVF(RQ_START);
  3294. params[3] = FW_PARAM_PFVF(RQ_END);
  3295. params[4] = FW_PARAM_PFVF(PBL_START);
  3296. params[5] = FW_PARAM_PFVF(PBL_END);
  3297. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6,
  3298. params, val);
  3299. if (ret < 0)
  3300. goto bye;
  3301. adap->vres.stag.start = val[0];
  3302. adap->vres.stag.size = val[1] - val[0] + 1;
  3303. adap->vres.rq.start = val[2];
  3304. adap->vres.rq.size = val[3] - val[2] + 1;
  3305. adap->vres.pbl.start = val[4];
  3306. adap->vres.pbl.size = val[5] - val[4] + 1;
  3307. params[0] = FW_PARAM_PFVF(SQRQ_START);
  3308. params[1] = FW_PARAM_PFVF(SQRQ_END);
  3309. params[2] = FW_PARAM_PFVF(CQ_START);
  3310. params[3] = FW_PARAM_PFVF(CQ_END);
  3311. params[4] = FW_PARAM_PFVF(OCQ_START);
  3312. params[5] = FW_PARAM_PFVF(OCQ_END);
  3313. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 6, params,
  3314. val);
  3315. if (ret < 0)
  3316. goto bye;
  3317. adap->vres.qp.start = val[0];
  3318. adap->vres.qp.size = val[1] - val[0] + 1;
  3319. adap->vres.cq.start = val[2];
  3320. adap->vres.cq.size = val[3] - val[2] + 1;
  3321. adap->vres.ocq.start = val[4];
  3322. adap->vres.ocq.size = val[5] - val[4] + 1;
  3323. params[0] = FW_PARAM_DEV(MAXORDIRD_QP);
  3324. params[1] = FW_PARAM_DEV(MAXIRD_ADAPTER);
  3325. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2, params,
  3326. val);
  3327. if (ret < 0) {
  3328. adap->params.max_ordird_qp = 8;
  3329. adap->params.max_ird_adapter = 32 * adap->tids.ntids;
  3330. ret = 0;
  3331. } else {
  3332. adap->params.max_ordird_qp = val[0];
  3333. adap->params.max_ird_adapter = val[1];
  3334. }
  3335. dev_info(adap->pdev_dev,
  3336. "max_ordird_qp %d max_ird_adapter %d\n",
  3337. adap->params.max_ordird_qp,
  3338. adap->params.max_ird_adapter);
  3339. adap->num_ofld_uld += 2;
  3340. }
  3341. if (caps_cmd.iscsicaps) {
  3342. params[0] = FW_PARAM_PFVF(ISCSI_START);
  3343. params[1] = FW_PARAM_PFVF(ISCSI_END);
  3344. ret = t4_query_params(adap, adap->mbox, adap->pf, 0, 2,
  3345. params, val);
  3346. if (ret < 0)
  3347. goto bye;
  3348. adap->vres.iscsi.start = val[0];
  3349. adap->vres.iscsi.size = val[1] - val[0] + 1;
  3350. /* LIO target and cxgb4i initiaitor */
  3351. adap->num_ofld_uld += 2;
  3352. }
  3353. if (caps_cmd.cryptocaps) {
  3354. /* Should query params here...TODO */
  3355. adap->params.crypto |= ULP_CRYPTO_LOOKASIDE;
  3356. adap->num_uld += 1;
  3357. }
  3358. #undef FW_PARAM_PFVF
  3359. #undef FW_PARAM_DEV
  3360. /* The MTU/MSS Table is initialized by now, so load their values. If
  3361. * we're initializing the adapter, then we'll make any modifications
  3362. * we want to the MTU/MSS Table and also initialize the congestion
  3363. * parameters.
  3364. */
  3365. t4_read_mtu_tbl(adap, adap->params.mtus, NULL);
  3366. if (state != DEV_STATE_INIT) {
  3367. int i;
  3368. /* The default MTU Table contains values 1492 and 1500.
  3369. * However, for TCP, it's better to have two values which are
  3370. * a multiple of 8 +/- 4 bytes apart near this popular MTU.
  3371. * This allows us to have a TCP Data Payload which is a
  3372. * multiple of 8 regardless of what combination of TCP Options
  3373. * are in use (always a multiple of 4 bytes) which is
  3374. * important for performance reasons. For instance, if no
  3375. * options are in use, then we have a 20-byte IP header and a
  3376. * 20-byte TCP header. In this case, a 1500-byte MSS would
  3377. * result in a TCP Data Payload of 1500 - 40 == 1460 bytes
  3378. * which is not a multiple of 8. So using an MSS of 1488 in
  3379. * this case results in a TCP Data Payload of 1448 bytes which
  3380. * is a multiple of 8. On the other hand, if 12-byte TCP Time
  3381. * Stamps have been negotiated, then an MTU of 1500 bytes
  3382. * results in a TCP Data Payload of 1448 bytes which, as
  3383. * above, is a multiple of 8 bytes ...
  3384. */
  3385. for (i = 0; i < NMTUS; i++)
  3386. if (adap->params.mtus[i] == 1492) {
  3387. adap->params.mtus[i] = 1488;
  3388. break;
  3389. }
  3390. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  3391. adap->params.b_wnd);
  3392. }
  3393. t4_init_sge_params(adap);
  3394. adap->flags |= FW_OK;
  3395. t4_init_tp_params(adap);
  3396. return 0;
  3397. /*
  3398. * Something bad happened. If a command timed out or failed with EIO
  3399. * FW does not operate within its spec or something catastrophic
  3400. * happened to HW/FW, stop issuing commands.
  3401. */
  3402. bye:
  3403. kfree(adap->sge.egr_map);
  3404. kfree(adap->sge.ingr_map);
  3405. kfree(adap->sge.starving_fl);
  3406. kfree(adap->sge.txq_maperr);
  3407. #ifdef CONFIG_DEBUG_FS
  3408. kfree(adap->sge.blocked_fl);
  3409. #endif
  3410. if (ret != -ETIMEDOUT && ret != -EIO)
  3411. t4_fw_bye(adap, adap->mbox);
  3412. return ret;
  3413. }
  3414. /* EEH callbacks */
  3415. static pci_ers_result_t eeh_err_detected(struct pci_dev *pdev,
  3416. pci_channel_state_t state)
  3417. {
  3418. int i;
  3419. struct adapter *adap = pci_get_drvdata(pdev);
  3420. if (!adap)
  3421. goto out;
  3422. rtnl_lock();
  3423. adap->flags &= ~FW_OK;
  3424. notify_ulds(adap, CXGB4_STATE_START_RECOVERY);
  3425. spin_lock(&adap->stats_lock);
  3426. for_each_port(adap, i) {
  3427. struct net_device *dev = adap->port[i];
  3428. netif_device_detach(dev);
  3429. netif_carrier_off(dev);
  3430. }
  3431. spin_unlock(&adap->stats_lock);
  3432. disable_interrupts(adap);
  3433. if (adap->flags & FULL_INIT_DONE)
  3434. cxgb_down(adap);
  3435. rtnl_unlock();
  3436. if ((adap->flags & DEV_ENABLED)) {
  3437. pci_disable_device(pdev);
  3438. adap->flags &= ~DEV_ENABLED;
  3439. }
  3440. out: return state == pci_channel_io_perm_failure ?
  3441. PCI_ERS_RESULT_DISCONNECT : PCI_ERS_RESULT_NEED_RESET;
  3442. }
  3443. static pci_ers_result_t eeh_slot_reset(struct pci_dev *pdev)
  3444. {
  3445. int i, ret;
  3446. struct fw_caps_config_cmd c;
  3447. struct adapter *adap = pci_get_drvdata(pdev);
  3448. if (!adap) {
  3449. pci_restore_state(pdev);
  3450. pci_save_state(pdev);
  3451. return PCI_ERS_RESULT_RECOVERED;
  3452. }
  3453. if (!(adap->flags & DEV_ENABLED)) {
  3454. if (pci_enable_device(pdev)) {
  3455. dev_err(&pdev->dev, "Cannot reenable PCI "
  3456. "device after reset\n");
  3457. return PCI_ERS_RESULT_DISCONNECT;
  3458. }
  3459. adap->flags |= DEV_ENABLED;
  3460. }
  3461. pci_set_master(pdev);
  3462. pci_restore_state(pdev);
  3463. pci_save_state(pdev);
  3464. pci_cleanup_aer_uncorrect_error_status(pdev);
  3465. if (t4_wait_dev_ready(adap->regs) < 0)
  3466. return PCI_ERS_RESULT_DISCONNECT;
  3467. if (t4_fw_hello(adap, adap->mbox, adap->pf, MASTER_MUST, NULL) < 0)
  3468. return PCI_ERS_RESULT_DISCONNECT;
  3469. adap->flags |= FW_OK;
  3470. if (adap_init1(adap, &c))
  3471. return PCI_ERS_RESULT_DISCONNECT;
  3472. for_each_port(adap, i) {
  3473. struct port_info *p = adap2pinfo(adap, i);
  3474. ret = t4_alloc_vi(adap, adap->mbox, p->tx_chan, adap->pf, 0, 1,
  3475. NULL, NULL);
  3476. if (ret < 0)
  3477. return PCI_ERS_RESULT_DISCONNECT;
  3478. p->viid = ret;
  3479. p->xact_addr_filt = -1;
  3480. }
  3481. t4_load_mtus(adap, adap->params.mtus, adap->params.a_wnd,
  3482. adap->params.b_wnd);
  3483. setup_memwin(adap);
  3484. if (cxgb_up(adap))
  3485. return PCI_ERS_RESULT_DISCONNECT;
  3486. return PCI_ERS_RESULT_RECOVERED;
  3487. }
  3488. static void eeh_resume(struct pci_dev *pdev)
  3489. {
  3490. int i;
  3491. struct adapter *adap = pci_get_drvdata(pdev);
  3492. if (!adap)
  3493. return;
  3494. rtnl_lock();
  3495. for_each_port(adap, i) {
  3496. struct net_device *dev = adap->port[i];
  3497. if (netif_running(dev)) {
  3498. link_start(dev);
  3499. cxgb_set_rxmode(dev);
  3500. }
  3501. netif_device_attach(dev);
  3502. }
  3503. rtnl_unlock();
  3504. }
  3505. static const struct pci_error_handlers cxgb4_eeh = {
  3506. .error_detected = eeh_err_detected,
  3507. .slot_reset = eeh_slot_reset,
  3508. .resume = eeh_resume,
  3509. };
  3510. /* Return true if the Link Configuration supports "High Speeds" (those greater
  3511. * than 1Gb/s).
  3512. */
  3513. static inline bool is_x_10g_port(const struct link_config *lc)
  3514. {
  3515. unsigned int speeds, high_speeds;
  3516. speeds = FW_PORT_CAP_SPEED_V(FW_PORT_CAP_SPEED_G(lc->supported));
  3517. high_speeds = speeds & ~(FW_PORT_CAP_SPEED_100M | FW_PORT_CAP_SPEED_1G);
  3518. return high_speeds != 0;
  3519. }
  3520. /*
  3521. * Perform default configuration of DMA queues depending on the number and type
  3522. * of ports we found and the number of available CPUs. Most settings can be
  3523. * modified by the admin prior to actual use.
  3524. */
  3525. static void cfg_queues(struct adapter *adap)
  3526. {
  3527. struct sge *s = &adap->sge;
  3528. int i = 0, n10g = 0, qidx = 0;
  3529. #ifndef CONFIG_CHELSIO_T4_DCB
  3530. int q10g = 0;
  3531. #endif
  3532. /* Reduce memory usage in kdump environment, disable all offload.
  3533. */
  3534. if (is_kdump_kernel()) {
  3535. adap->params.offload = 0;
  3536. adap->params.crypto = 0;
  3537. } else if (is_uld(adap) && t4_uld_mem_alloc(adap)) {
  3538. adap->params.offload = 0;
  3539. adap->params.crypto = 0;
  3540. }
  3541. n10g += is_x_10g_port(&adap2pinfo(adap, i)->link_cfg);
  3542. #ifdef CONFIG_CHELSIO_T4_DCB
  3543. /* For Data Center Bridging support we need to be able to support up
  3544. * to 8 Traffic Priorities; each of which will be assigned to its
  3545. * own TX Queue in order to prevent Head-Of-Line Blocking.
  3546. */
  3547. if (adap->params.nports * 8 > MAX_ETH_QSETS) {
  3548. dev_err(adap->pdev_dev, "MAX_ETH_QSETS=%d < %d!\n",
  3549. MAX_ETH_QSETS, adap->params.nports * 8);
  3550. BUG_ON(1);
  3551. }
  3552. for_each_port(adap, i) {
  3553. struct port_info *pi = adap2pinfo(adap, i);
  3554. pi->first_qset = qidx;
  3555. pi->nqsets = 8;
  3556. qidx += pi->nqsets;
  3557. }
  3558. #else /* !CONFIG_CHELSIO_T4_DCB */
  3559. /*
  3560. * We default to 1 queue per non-10G port and up to # of cores queues
  3561. * per 10G port.
  3562. */
  3563. if (n10g)
  3564. q10g = (MAX_ETH_QSETS - (adap->params.nports - n10g)) / n10g;
  3565. if (q10g > netif_get_num_default_rss_queues())
  3566. q10g = netif_get_num_default_rss_queues();
  3567. for_each_port(adap, i) {
  3568. struct port_info *pi = adap2pinfo(adap, i);
  3569. pi->first_qset = qidx;
  3570. pi->nqsets = is_x_10g_port(&pi->link_cfg) ? q10g : 1;
  3571. qidx += pi->nqsets;
  3572. }
  3573. #endif /* !CONFIG_CHELSIO_T4_DCB */
  3574. s->ethqsets = qidx;
  3575. s->max_ethqsets = qidx; /* MSI-X may lower it later */
  3576. if (is_uld(adap)) {
  3577. /*
  3578. * For offload we use 1 queue/channel if all ports are up to 1G,
  3579. * otherwise we divide all available queues amongst the channels
  3580. * capped by the number of available cores.
  3581. */
  3582. if (n10g) {
  3583. i = min_t(int, MAX_OFLD_QSETS, num_online_cpus());
  3584. s->ofldqsets = roundup(i, adap->params.nports);
  3585. } else {
  3586. s->ofldqsets = adap->params.nports;
  3587. }
  3588. }
  3589. for (i = 0; i < ARRAY_SIZE(s->ethrxq); i++) {
  3590. struct sge_eth_rxq *r = &s->ethrxq[i];
  3591. init_rspq(adap, &r->rspq, 5, 10, 1024, 64);
  3592. r->fl.size = 72;
  3593. }
  3594. for (i = 0; i < ARRAY_SIZE(s->ethtxq); i++)
  3595. s->ethtxq[i].q.size = 1024;
  3596. for (i = 0; i < ARRAY_SIZE(s->ctrlq); i++)
  3597. s->ctrlq[i].q.size = 512;
  3598. init_rspq(adap, &s->fw_evtq, 0, 1, 1024, 64);
  3599. init_rspq(adap, &s->intrq, 0, 1, 512, 64);
  3600. }
  3601. /*
  3602. * Reduce the number of Ethernet queues across all ports to at most n.
  3603. * n provides at least one queue per port.
  3604. */
  3605. static void reduce_ethqs(struct adapter *adap, int n)
  3606. {
  3607. int i;
  3608. struct port_info *pi;
  3609. while (n < adap->sge.ethqsets)
  3610. for_each_port(adap, i) {
  3611. pi = adap2pinfo(adap, i);
  3612. if (pi->nqsets > 1) {
  3613. pi->nqsets--;
  3614. adap->sge.ethqsets--;
  3615. if (adap->sge.ethqsets <= n)
  3616. break;
  3617. }
  3618. }
  3619. n = 0;
  3620. for_each_port(adap, i) {
  3621. pi = adap2pinfo(adap, i);
  3622. pi->first_qset = n;
  3623. n += pi->nqsets;
  3624. }
  3625. }
  3626. static int get_msix_info(struct adapter *adap)
  3627. {
  3628. struct uld_msix_info *msix_info;
  3629. unsigned int max_ingq = 0;
  3630. if (is_offload(adap))
  3631. max_ingq += MAX_OFLD_QSETS * adap->num_ofld_uld;
  3632. if (is_pci_uld(adap))
  3633. max_ingq += MAX_OFLD_QSETS * adap->num_uld;
  3634. if (!max_ingq)
  3635. goto out;
  3636. msix_info = kcalloc(max_ingq, sizeof(*msix_info), GFP_KERNEL);
  3637. if (!msix_info)
  3638. return -ENOMEM;
  3639. adap->msix_bmap_ulds.msix_bmap = kcalloc(BITS_TO_LONGS(max_ingq),
  3640. sizeof(long), GFP_KERNEL);
  3641. if (!adap->msix_bmap_ulds.msix_bmap) {
  3642. kfree(msix_info);
  3643. return -ENOMEM;
  3644. }
  3645. spin_lock_init(&adap->msix_bmap_ulds.lock);
  3646. adap->msix_info_ulds = msix_info;
  3647. out:
  3648. return 0;
  3649. }
  3650. static void free_msix_info(struct adapter *adap)
  3651. {
  3652. if (!(adap->num_uld && adap->num_ofld_uld))
  3653. return;
  3654. kfree(adap->msix_info_ulds);
  3655. kfree(adap->msix_bmap_ulds.msix_bmap);
  3656. }
  3657. /* 2 MSI-X vectors needed for the FW queue and non-data interrupts */
  3658. #define EXTRA_VECS 2
  3659. static int enable_msix(struct adapter *adap)
  3660. {
  3661. int ofld_need = 0, uld_need = 0;
  3662. int i, j, want, need, allocated;
  3663. struct sge *s = &adap->sge;
  3664. unsigned int nchan = adap->params.nports;
  3665. struct msix_entry *entries;
  3666. int max_ingq = MAX_INGQ;
  3667. if (is_pci_uld(adap))
  3668. max_ingq += (MAX_OFLD_QSETS * adap->num_uld);
  3669. if (is_offload(adap))
  3670. max_ingq += (MAX_OFLD_QSETS * adap->num_ofld_uld);
  3671. entries = kmalloc(sizeof(*entries) * (max_ingq + 1),
  3672. GFP_KERNEL);
  3673. if (!entries)
  3674. return -ENOMEM;
  3675. /* map for msix */
  3676. if (get_msix_info(adap)) {
  3677. adap->params.offload = 0;
  3678. adap->params.crypto = 0;
  3679. }
  3680. for (i = 0; i < max_ingq + 1; ++i)
  3681. entries[i].entry = i;
  3682. want = s->max_ethqsets + EXTRA_VECS;
  3683. if (is_offload(adap)) {
  3684. want += adap->num_ofld_uld * s->ofldqsets;
  3685. ofld_need = adap->num_ofld_uld * nchan;
  3686. }
  3687. if (is_pci_uld(adap)) {
  3688. want += adap->num_uld * s->ofldqsets;
  3689. uld_need = adap->num_uld * nchan;
  3690. }
  3691. #ifdef CONFIG_CHELSIO_T4_DCB
  3692. /* For Data Center Bridging we need 8 Ethernet TX Priority Queues for
  3693. * each port.
  3694. */
  3695. need = 8 * adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
  3696. #else
  3697. need = adap->params.nports + EXTRA_VECS + ofld_need + uld_need;
  3698. #endif
  3699. allocated = pci_enable_msix_range(adap->pdev, entries, need, want);
  3700. if (allocated < 0) {
  3701. dev_info(adap->pdev_dev, "not enough MSI-X vectors left,"
  3702. " not using MSI-X\n");
  3703. kfree(entries);
  3704. return allocated;
  3705. }
  3706. /* Distribute available vectors to the various queue groups.
  3707. * Every group gets its minimum requirement and NIC gets top
  3708. * priority for leftovers.
  3709. */
  3710. i = allocated - EXTRA_VECS - ofld_need - uld_need;
  3711. if (i < s->max_ethqsets) {
  3712. s->max_ethqsets = i;
  3713. if (i < s->ethqsets)
  3714. reduce_ethqs(adap, i);
  3715. }
  3716. if (is_uld(adap)) {
  3717. if (allocated < want)
  3718. s->nqs_per_uld = nchan;
  3719. else
  3720. s->nqs_per_uld = s->ofldqsets;
  3721. }
  3722. for (i = 0; i < (s->max_ethqsets + EXTRA_VECS); ++i)
  3723. adap->msix_info[i].vec = entries[i].vector;
  3724. if (is_uld(adap)) {
  3725. for (j = 0 ; i < allocated; ++i, j++) {
  3726. adap->msix_info_ulds[j].vec = entries[i].vector;
  3727. adap->msix_info_ulds[j].idx = i;
  3728. }
  3729. adap->msix_bmap_ulds.mapsize = j;
  3730. }
  3731. dev_info(adap->pdev_dev, "%d MSI-X vectors allocated, "
  3732. "nic %d per uld %d\n",
  3733. allocated, s->max_ethqsets, s->nqs_per_uld);
  3734. kfree(entries);
  3735. return 0;
  3736. }
  3737. #undef EXTRA_VECS
  3738. static int init_rss(struct adapter *adap)
  3739. {
  3740. unsigned int i;
  3741. int err;
  3742. err = t4_init_rss_mode(adap, adap->mbox);
  3743. if (err)
  3744. return err;
  3745. for_each_port(adap, i) {
  3746. struct port_info *pi = adap2pinfo(adap, i);
  3747. pi->rss = kcalloc(pi->rss_size, sizeof(u16), GFP_KERNEL);
  3748. if (!pi->rss)
  3749. return -ENOMEM;
  3750. }
  3751. return 0;
  3752. }
  3753. static int cxgb4_get_pcie_dev_link_caps(struct adapter *adap,
  3754. enum pci_bus_speed *speed,
  3755. enum pcie_link_width *width)
  3756. {
  3757. u32 lnkcap1, lnkcap2;
  3758. int err1, err2;
  3759. #define PCIE_MLW_CAP_SHIFT 4 /* start of MLW mask in link capabilities */
  3760. *speed = PCI_SPEED_UNKNOWN;
  3761. *width = PCIE_LNK_WIDTH_UNKNOWN;
  3762. err1 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP,
  3763. &lnkcap1);
  3764. err2 = pcie_capability_read_dword(adap->pdev, PCI_EXP_LNKCAP2,
  3765. &lnkcap2);
  3766. if (!err2 && lnkcap2) { /* PCIe r3.0-compliant */
  3767. if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
  3768. *speed = PCIE_SPEED_8_0GT;
  3769. else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
  3770. *speed = PCIE_SPEED_5_0GT;
  3771. else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
  3772. *speed = PCIE_SPEED_2_5GT;
  3773. }
  3774. if (!err1) {
  3775. *width = (lnkcap1 & PCI_EXP_LNKCAP_MLW) >> PCIE_MLW_CAP_SHIFT;
  3776. if (!lnkcap2) { /* pre-r3.0 */
  3777. if (lnkcap1 & PCI_EXP_LNKCAP_SLS_5_0GB)
  3778. *speed = PCIE_SPEED_5_0GT;
  3779. else if (lnkcap1 & PCI_EXP_LNKCAP_SLS_2_5GB)
  3780. *speed = PCIE_SPEED_2_5GT;
  3781. }
  3782. }
  3783. if (*speed == PCI_SPEED_UNKNOWN || *width == PCIE_LNK_WIDTH_UNKNOWN)
  3784. return err1 ? err1 : err2 ? err2 : -EINVAL;
  3785. return 0;
  3786. }
  3787. static void cxgb4_check_pcie_caps(struct adapter *adap)
  3788. {
  3789. enum pcie_link_width width, width_cap;
  3790. enum pci_bus_speed speed, speed_cap;
  3791. #define PCIE_SPEED_STR(speed) \
  3792. (speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : \
  3793. speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : \
  3794. speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : \
  3795. "Unknown")
  3796. if (cxgb4_get_pcie_dev_link_caps(adap, &speed_cap, &width_cap)) {
  3797. dev_warn(adap->pdev_dev,
  3798. "Unable to determine PCIe device BW capabilities\n");
  3799. return;
  3800. }
  3801. if (pcie_get_minimum_link(adap->pdev, &speed, &width) ||
  3802. speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) {
  3803. dev_warn(adap->pdev_dev,
  3804. "Unable to determine PCI Express bandwidth.\n");
  3805. return;
  3806. }
  3807. dev_info(adap->pdev_dev, "PCIe link speed is %s, device supports %s\n",
  3808. PCIE_SPEED_STR(speed), PCIE_SPEED_STR(speed_cap));
  3809. dev_info(adap->pdev_dev, "PCIe link width is x%d, device supports x%d\n",
  3810. width, width_cap);
  3811. if (speed < speed_cap || width < width_cap)
  3812. dev_info(adap->pdev_dev,
  3813. "A slot with more lanes and/or higher speed is "
  3814. "suggested for optimal performance.\n");
  3815. }
  3816. /* Dump basic information about the adapter */
  3817. static void print_adapter_info(struct adapter *adapter)
  3818. {
  3819. /* Device information */
  3820. dev_info(adapter->pdev_dev, "Chelsio %s rev %d\n",
  3821. adapter->params.vpd.id,
  3822. CHELSIO_CHIP_RELEASE(adapter->params.chip));
  3823. dev_info(adapter->pdev_dev, "S/N: %s, P/N: %s\n",
  3824. adapter->params.vpd.sn, adapter->params.vpd.pn);
  3825. /* Firmware Version */
  3826. if (!adapter->params.fw_vers)
  3827. dev_warn(adapter->pdev_dev, "No firmware loaded\n");
  3828. else
  3829. dev_info(adapter->pdev_dev, "Firmware version: %u.%u.%u.%u\n",
  3830. FW_HDR_FW_VER_MAJOR_G(adapter->params.fw_vers),
  3831. FW_HDR_FW_VER_MINOR_G(adapter->params.fw_vers),
  3832. FW_HDR_FW_VER_MICRO_G(adapter->params.fw_vers),
  3833. FW_HDR_FW_VER_BUILD_G(adapter->params.fw_vers));
  3834. /* Bootstrap Firmware Version. (Some adapters don't have Bootstrap
  3835. * Firmware, so dev_info() is more appropriate here.)
  3836. */
  3837. if (!adapter->params.bs_vers)
  3838. dev_info(adapter->pdev_dev, "No bootstrap loaded\n");
  3839. else
  3840. dev_info(adapter->pdev_dev, "Bootstrap version: %u.%u.%u.%u\n",
  3841. FW_HDR_FW_VER_MAJOR_G(adapter->params.bs_vers),
  3842. FW_HDR_FW_VER_MINOR_G(adapter->params.bs_vers),
  3843. FW_HDR_FW_VER_MICRO_G(adapter->params.bs_vers),
  3844. FW_HDR_FW_VER_BUILD_G(adapter->params.bs_vers));
  3845. /* TP Microcode Version */
  3846. if (!adapter->params.tp_vers)
  3847. dev_warn(adapter->pdev_dev, "No TP Microcode loaded\n");
  3848. else
  3849. dev_info(adapter->pdev_dev,
  3850. "TP Microcode version: %u.%u.%u.%u\n",
  3851. FW_HDR_FW_VER_MAJOR_G(adapter->params.tp_vers),
  3852. FW_HDR_FW_VER_MINOR_G(adapter->params.tp_vers),
  3853. FW_HDR_FW_VER_MICRO_G(adapter->params.tp_vers),
  3854. FW_HDR_FW_VER_BUILD_G(adapter->params.tp_vers));
  3855. /* Expansion ROM version */
  3856. if (!adapter->params.er_vers)
  3857. dev_info(adapter->pdev_dev, "No Expansion ROM loaded\n");
  3858. else
  3859. dev_info(adapter->pdev_dev,
  3860. "Expansion ROM version: %u.%u.%u.%u\n",
  3861. FW_HDR_FW_VER_MAJOR_G(adapter->params.er_vers),
  3862. FW_HDR_FW_VER_MINOR_G(adapter->params.er_vers),
  3863. FW_HDR_FW_VER_MICRO_G(adapter->params.er_vers),
  3864. FW_HDR_FW_VER_BUILD_G(adapter->params.er_vers));
  3865. /* Software/Hardware configuration */
  3866. dev_info(adapter->pdev_dev, "Configuration: %sNIC %s, %s capable\n",
  3867. is_offload(adapter) ? "R" : "",
  3868. ((adapter->flags & USING_MSIX) ? "MSI-X" :
  3869. (adapter->flags & USING_MSI) ? "MSI" : ""),
  3870. is_offload(adapter) ? "Offload" : "non-Offload");
  3871. }
  3872. static void print_port_info(const struct net_device *dev)
  3873. {
  3874. char buf[80];
  3875. char *bufp = buf;
  3876. const char *spd = "";
  3877. const struct port_info *pi = netdev_priv(dev);
  3878. const struct adapter *adap = pi->adapter;
  3879. if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_2_5GB)
  3880. spd = " 2.5 GT/s";
  3881. else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_5_0GB)
  3882. spd = " 5 GT/s";
  3883. else if (adap->params.pci.speed == PCI_EXP_LNKSTA_CLS_8_0GB)
  3884. spd = " 8 GT/s";
  3885. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100M)
  3886. bufp += sprintf(bufp, "100M/");
  3887. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_1G)
  3888. bufp += sprintf(bufp, "1G/");
  3889. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_10G)
  3890. bufp += sprintf(bufp, "10G/");
  3891. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_25G)
  3892. bufp += sprintf(bufp, "25G/");
  3893. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_40G)
  3894. bufp += sprintf(bufp, "40G/");
  3895. if (pi->link_cfg.supported & FW_PORT_CAP_SPEED_100G)
  3896. bufp += sprintf(bufp, "100G/");
  3897. if (bufp != buf)
  3898. --bufp;
  3899. sprintf(bufp, "BASE-%s", t4_get_port_type_description(pi->port_type));
  3900. netdev_info(dev, "%s: Chelsio %s (%s) %s\n",
  3901. dev->name, adap->params.vpd.id, adap->name, buf);
  3902. }
  3903. static void enable_pcie_relaxed_ordering(struct pci_dev *dev)
  3904. {
  3905. pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_RELAX_EN);
  3906. }
  3907. /*
  3908. * Free the following resources:
  3909. * - memory used for tables
  3910. * - MSI/MSI-X
  3911. * - net devices
  3912. * - resources FW is holding for us
  3913. */
  3914. static void free_some_resources(struct adapter *adapter)
  3915. {
  3916. unsigned int i;
  3917. t4_free_mem(adapter->l2t);
  3918. t4_cleanup_sched(adapter);
  3919. t4_free_mem(adapter->tids.tid_tab);
  3920. cxgb4_cleanup_tc_u32(adapter);
  3921. kfree(adapter->sge.egr_map);
  3922. kfree(adapter->sge.ingr_map);
  3923. kfree(adapter->sge.starving_fl);
  3924. kfree(adapter->sge.txq_maperr);
  3925. #ifdef CONFIG_DEBUG_FS
  3926. kfree(adapter->sge.blocked_fl);
  3927. #endif
  3928. disable_msi(adapter);
  3929. for_each_port(adapter, i)
  3930. if (adapter->port[i]) {
  3931. struct port_info *pi = adap2pinfo(adapter, i);
  3932. if (pi->viid != 0)
  3933. t4_free_vi(adapter, adapter->mbox, adapter->pf,
  3934. 0, pi->viid);
  3935. kfree(adap2pinfo(adapter, i)->rss);
  3936. free_netdev(adapter->port[i]);
  3937. }
  3938. if (adapter->flags & FW_OK)
  3939. t4_fw_bye(adapter, adapter->pf);
  3940. }
  3941. #define TSO_FLAGS (NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN)
  3942. #define VLAN_FEAT (NETIF_F_SG | NETIF_F_IP_CSUM | TSO_FLAGS | \
  3943. NETIF_F_IPV6_CSUM | NETIF_F_HIGHDMA)
  3944. #define SEGMENT_SIZE 128
  3945. static int get_chip_type(struct pci_dev *pdev, u32 pl_rev)
  3946. {
  3947. u16 device_id;
  3948. /* Retrieve adapter's device ID */
  3949. pci_read_config_word(pdev, PCI_DEVICE_ID, &device_id);
  3950. switch (device_id >> 12) {
  3951. case CHELSIO_T4:
  3952. return CHELSIO_CHIP_CODE(CHELSIO_T4, pl_rev);
  3953. case CHELSIO_T5:
  3954. return CHELSIO_CHIP_CODE(CHELSIO_T5, pl_rev);
  3955. case CHELSIO_T6:
  3956. return CHELSIO_CHIP_CODE(CHELSIO_T6, pl_rev);
  3957. default:
  3958. dev_err(&pdev->dev, "Device %d is not supported\n",
  3959. device_id);
  3960. }
  3961. return -EINVAL;
  3962. }
  3963. #ifdef CONFIG_PCI_IOV
  3964. static void dummy_setup(struct net_device *dev)
  3965. {
  3966. dev->type = ARPHRD_NONE;
  3967. dev->mtu = 0;
  3968. dev->hard_header_len = 0;
  3969. dev->addr_len = 0;
  3970. dev->tx_queue_len = 0;
  3971. dev->flags |= IFF_NOARP;
  3972. dev->priv_flags |= IFF_NO_QUEUE;
  3973. /* Initialize the device structure. */
  3974. dev->netdev_ops = &cxgb4_mgmt_netdev_ops;
  3975. dev->ethtool_ops = &cxgb4_mgmt_ethtool_ops;
  3976. dev->destructor = free_netdev;
  3977. }
  3978. static int config_mgmt_dev(struct pci_dev *pdev)
  3979. {
  3980. struct adapter *adap = pci_get_drvdata(pdev);
  3981. struct net_device *netdev;
  3982. struct port_info *pi;
  3983. char name[IFNAMSIZ];
  3984. int err;
  3985. snprintf(name, IFNAMSIZ, "mgmtpf%d%d", adap->adap_idx, adap->pf);
  3986. netdev = alloc_netdev(sizeof(struct port_info), name, NET_NAME_UNKNOWN,
  3987. dummy_setup);
  3988. if (!netdev)
  3989. return -ENOMEM;
  3990. pi = netdev_priv(netdev);
  3991. pi->adapter = adap;
  3992. pi->port_id = adap->pf % adap->params.nports;
  3993. SET_NETDEV_DEV(netdev, &pdev->dev);
  3994. adap->port[0] = netdev;
  3995. err = register_netdev(adap->port[0]);
  3996. if (err) {
  3997. pr_info("Unable to register VF mgmt netdev %s\n", name);
  3998. free_netdev(adap->port[0]);
  3999. adap->port[0] = NULL;
  4000. return err;
  4001. }
  4002. return 0;
  4003. }
  4004. static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
  4005. {
  4006. struct adapter *adap = pci_get_drvdata(pdev);
  4007. int err = 0;
  4008. int current_vfs = pci_num_vf(pdev);
  4009. u32 pcie_fw;
  4010. pcie_fw = readl(adap->regs + PCIE_FW_A);
  4011. /* Check if cxgb4 is the MASTER and fw is initialized */
  4012. if (!(pcie_fw & PCIE_FW_INIT_F) ||
  4013. !(pcie_fw & PCIE_FW_MASTER_VLD_F) ||
  4014. PCIE_FW_MASTER_G(pcie_fw) != 4) {
  4015. dev_warn(&pdev->dev,
  4016. "cxgb4 driver needs to be MASTER to support SRIOV\n");
  4017. return -EOPNOTSUPP;
  4018. }
  4019. /* If any of the VF's is already assigned to Guest OS, then
  4020. * SRIOV for the same cannot be modified
  4021. */
  4022. if (current_vfs && pci_vfs_assigned(pdev)) {
  4023. dev_err(&pdev->dev,
  4024. "Cannot modify SR-IOV while VFs are assigned\n");
  4025. num_vfs = current_vfs;
  4026. return num_vfs;
  4027. }
  4028. /* Disable SRIOV when zero is passed.
  4029. * One needs to disable SRIOV before modifying it, else
  4030. * stack throws the below warning:
  4031. * " 'n' VFs already enabled. Disable before enabling 'm' VFs."
  4032. */
  4033. if (!num_vfs) {
  4034. pci_disable_sriov(pdev);
  4035. if (adap->port[0]) {
  4036. unregister_netdev(adap->port[0]);
  4037. adap->port[0] = NULL;
  4038. }
  4039. /* free VF resources */
  4040. kfree(adap->vfinfo);
  4041. adap->vfinfo = NULL;
  4042. adap->num_vfs = 0;
  4043. return num_vfs;
  4044. }
  4045. if (num_vfs != current_vfs) {
  4046. err = pci_enable_sriov(pdev, num_vfs);
  4047. if (err)
  4048. return err;
  4049. adap->num_vfs = num_vfs;
  4050. err = config_mgmt_dev(pdev);
  4051. if (err)
  4052. return err;
  4053. }
  4054. adap->vfinfo = kcalloc(adap->num_vfs,
  4055. sizeof(struct vf_info), GFP_KERNEL);
  4056. if (adap->vfinfo)
  4057. fill_vf_station_mac_addr(adap);
  4058. return num_vfs;
  4059. }
  4060. #endif
  4061. static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  4062. {
  4063. int func, i, err, s_qpp, qpp, num_seg;
  4064. struct port_info *pi;
  4065. bool highdma = false;
  4066. struct adapter *adapter = NULL;
  4067. struct net_device *netdev;
  4068. void __iomem *regs;
  4069. u32 whoami, pl_rev;
  4070. enum chip_type chip;
  4071. static int adap_idx = 1;
  4072. #ifdef CONFIG_PCI_IOV
  4073. u32 v, port_vec;
  4074. #endif
  4075. printk_once(KERN_INFO "%s - version %s\n", DRV_DESC, DRV_VERSION);
  4076. err = pci_request_regions(pdev, KBUILD_MODNAME);
  4077. if (err) {
  4078. /* Just info, some other driver may have claimed the device. */
  4079. dev_info(&pdev->dev, "cannot obtain PCI resources\n");
  4080. return err;
  4081. }
  4082. err = pci_enable_device(pdev);
  4083. if (err) {
  4084. dev_err(&pdev->dev, "cannot enable PCI device\n");
  4085. goto out_release_regions;
  4086. }
  4087. regs = pci_ioremap_bar(pdev, 0);
  4088. if (!regs) {
  4089. dev_err(&pdev->dev, "cannot map device registers\n");
  4090. err = -ENOMEM;
  4091. goto out_disable_device;
  4092. }
  4093. err = t4_wait_dev_ready(regs);
  4094. if (err < 0)
  4095. goto out_unmap_bar0;
  4096. /* We control everything through one PF */
  4097. whoami = readl(regs + PL_WHOAMI_A);
  4098. pl_rev = REV_G(readl(regs + PL_REV_A));
  4099. chip = get_chip_type(pdev, pl_rev);
  4100. func = CHELSIO_CHIP_VERSION(chip) <= CHELSIO_T5 ?
  4101. SOURCEPF_G(whoami) : T6_SOURCEPF_G(whoami);
  4102. if (func != ent->driver_data) {
  4103. #ifndef CONFIG_PCI_IOV
  4104. iounmap(regs);
  4105. #endif
  4106. pci_disable_device(pdev);
  4107. pci_save_state(pdev); /* to restore SR-IOV later */
  4108. goto sriov;
  4109. }
  4110. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  4111. highdma = true;
  4112. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  4113. if (err) {
  4114. dev_err(&pdev->dev, "unable to obtain 64-bit DMA for "
  4115. "coherent allocations\n");
  4116. goto out_unmap_bar0;
  4117. }
  4118. } else {
  4119. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  4120. if (err) {
  4121. dev_err(&pdev->dev, "no usable DMA configuration\n");
  4122. goto out_unmap_bar0;
  4123. }
  4124. }
  4125. pci_enable_pcie_error_reporting(pdev);
  4126. enable_pcie_relaxed_ordering(pdev);
  4127. pci_set_master(pdev);
  4128. pci_save_state(pdev);
  4129. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  4130. if (!adapter) {
  4131. err = -ENOMEM;
  4132. goto out_unmap_bar0;
  4133. }
  4134. adap_idx++;
  4135. adapter->workq = create_singlethread_workqueue("cxgb4");
  4136. if (!adapter->workq) {
  4137. err = -ENOMEM;
  4138. goto out_free_adapter;
  4139. }
  4140. adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
  4141. (sizeof(struct mbox_cmd) *
  4142. T4_OS_LOG_MBOX_CMDS),
  4143. GFP_KERNEL);
  4144. if (!adapter->mbox_log) {
  4145. err = -ENOMEM;
  4146. goto out_free_adapter;
  4147. }
  4148. adapter->mbox_log->size = T4_OS_LOG_MBOX_CMDS;
  4149. /* PCI device has been enabled */
  4150. adapter->flags |= DEV_ENABLED;
  4151. adapter->regs = regs;
  4152. adapter->pdev = pdev;
  4153. adapter->pdev_dev = &pdev->dev;
  4154. adapter->name = pci_name(pdev);
  4155. adapter->mbox = func;
  4156. adapter->pf = func;
  4157. adapter->msg_enable = DFLT_MSG_ENABLE;
  4158. memset(adapter->chan_map, 0xff, sizeof(adapter->chan_map));
  4159. spin_lock_init(&adapter->stats_lock);
  4160. spin_lock_init(&adapter->tid_release_lock);
  4161. spin_lock_init(&adapter->win0_lock);
  4162. spin_lock_init(&adapter->mbox_lock);
  4163. INIT_LIST_HEAD(&adapter->mlist.list);
  4164. INIT_WORK(&adapter->tid_release_task, process_tid_release_list);
  4165. INIT_WORK(&adapter->db_full_task, process_db_full);
  4166. INIT_WORK(&adapter->db_drop_task, process_db_drop);
  4167. err = t4_prep_adapter(adapter);
  4168. if (err)
  4169. goto out_free_adapter;
  4170. if (!is_t4(adapter->params.chip)) {
  4171. s_qpp = (QUEUESPERPAGEPF0_S +
  4172. (QUEUESPERPAGEPF1_S - QUEUESPERPAGEPF0_S) *
  4173. adapter->pf);
  4174. qpp = 1 << QUEUESPERPAGEPF0_G(t4_read_reg(adapter,
  4175. SGE_EGRESS_QUEUES_PER_PAGE_PF_A) >> s_qpp);
  4176. num_seg = PAGE_SIZE / SEGMENT_SIZE;
  4177. /* Each segment size is 128B. Write coalescing is enabled only
  4178. * when SGE_EGRESS_QUEUES_PER_PAGE_PF reg value for the
  4179. * queue is less no of segments that can be accommodated in
  4180. * a page size.
  4181. */
  4182. if (qpp > num_seg) {
  4183. dev_err(&pdev->dev,
  4184. "Incorrect number of egress queues per page\n");
  4185. err = -EINVAL;
  4186. goto out_free_adapter;
  4187. }
  4188. adapter->bar2 = ioremap_wc(pci_resource_start(pdev, 2),
  4189. pci_resource_len(pdev, 2));
  4190. if (!adapter->bar2) {
  4191. dev_err(&pdev->dev, "cannot map device bar2 region\n");
  4192. err = -ENOMEM;
  4193. goto out_free_adapter;
  4194. }
  4195. }
  4196. setup_memwin(adapter);
  4197. err = adap_init0(adapter);
  4198. #ifdef CONFIG_DEBUG_FS
  4199. bitmap_zero(adapter->sge.blocked_fl, adapter->sge.egr_sz);
  4200. #endif
  4201. setup_memwin_rdma(adapter);
  4202. if (err)
  4203. goto out_unmap_bar;
  4204. /* configure SGE_STAT_CFG_A to read WC stats */
  4205. if (!is_t4(adapter->params.chip))
  4206. t4_write_reg(adapter, SGE_STAT_CFG_A, STATSOURCE_T5_V(7) |
  4207. (is_t5(adapter->params.chip) ? STATMODE_V(0) :
  4208. T6_STATMODE_V(0)));
  4209. for_each_port(adapter, i) {
  4210. netdev = alloc_etherdev_mq(sizeof(struct port_info),
  4211. MAX_ETH_QSETS);
  4212. if (!netdev) {
  4213. err = -ENOMEM;
  4214. goto out_free_dev;
  4215. }
  4216. SET_NETDEV_DEV(netdev, &pdev->dev);
  4217. adapter->port[i] = netdev;
  4218. pi = netdev_priv(netdev);
  4219. pi->adapter = adapter;
  4220. pi->xact_addr_filt = -1;
  4221. pi->port_id = i;
  4222. netdev->irq = pdev->irq;
  4223. netdev->hw_features = NETIF_F_SG | TSO_FLAGS |
  4224. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  4225. NETIF_F_RXCSUM | NETIF_F_RXHASH |
  4226. NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX |
  4227. NETIF_F_HW_TC;
  4228. if (highdma)
  4229. netdev->hw_features |= NETIF_F_HIGHDMA;
  4230. netdev->features |= netdev->hw_features;
  4231. netdev->vlan_features = netdev->features & VLAN_FEAT;
  4232. netdev->priv_flags |= IFF_UNICAST_FLT;
  4233. /* MTU range: 81 - 9600 */
  4234. netdev->min_mtu = 81;
  4235. netdev->max_mtu = MAX_MTU;
  4236. netdev->netdev_ops = &cxgb4_netdev_ops;
  4237. #ifdef CONFIG_CHELSIO_T4_DCB
  4238. netdev->dcbnl_ops = &cxgb4_dcb_ops;
  4239. cxgb4_dcb_state_init(netdev);
  4240. #endif
  4241. cxgb4_set_ethtool_ops(netdev);
  4242. }
  4243. pci_set_drvdata(pdev, adapter);
  4244. if (adapter->flags & FW_OK) {
  4245. err = t4_port_init(adapter, func, func, 0);
  4246. if (err)
  4247. goto out_free_dev;
  4248. } else if (adapter->params.nports == 1) {
  4249. /* If we don't have a connection to the firmware -- possibly
  4250. * because of an error -- grab the raw VPD parameters so we
  4251. * can set the proper MAC Address on the debug network
  4252. * interface that we've created.
  4253. */
  4254. u8 hw_addr[ETH_ALEN];
  4255. u8 *na = adapter->params.vpd.na;
  4256. err = t4_get_raw_vpd_params(adapter, &adapter->params.vpd);
  4257. if (!err) {
  4258. for (i = 0; i < ETH_ALEN; i++)
  4259. hw_addr[i] = (hex2val(na[2 * i + 0]) * 16 +
  4260. hex2val(na[2 * i + 1]));
  4261. t4_set_hw_addr(adapter, 0, hw_addr);
  4262. }
  4263. }
  4264. /* Configure queues and allocate tables now, they can be needed as
  4265. * soon as the first register_netdev completes.
  4266. */
  4267. cfg_queues(adapter);
  4268. adapter->l2t = t4_init_l2t(adapter->l2t_start, adapter->l2t_end);
  4269. if (!adapter->l2t) {
  4270. /* We tolerate a lack of L2T, giving up some functionality */
  4271. dev_warn(&pdev->dev, "could not allocate L2T, continuing\n");
  4272. adapter->params.offload = 0;
  4273. }
  4274. #if IS_ENABLED(CONFIG_IPV6)
  4275. if ((CHELSIO_CHIP_VERSION(adapter->params.chip) <= CHELSIO_T5) &&
  4276. (!(t4_read_reg(adapter, LE_DB_CONFIG_A) & ASLIPCOMPEN_F))) {
  4277. /* CLIP functionality is not present in hardware,
  4278. * hence disable all offload features
  4279. */
  4280. dev_warn(&pdev->dev,
  4281. "CLIP not enabled in hardware, continuing\n");
  4282. adapter->params.offload = 0;
  4283. } else {
  4284. adapter->clipt = t4_init_clip_tbl(adapter->clipt_start,
  4285. adapter->clipt_end);
  4286. if (!adapter->clipt) {
  4287. /* We tolerate a lack of clip_table, giving up
  4288. * some functionality
  4289. */
  4290. dev_warn(&pdev->dev,
  4291. "could not allocate Clip table, continuing\n");
  4292. adapter->params.offload = 0;
  4293. }
  4294. }
  4295. #endif
  4296. for_each_port(adapter, i) {
  4297. pi = adap2pinfo(adapter, i);
  4298. pi->sched_tbl = t4_init_sched(adapter->params.nsched_cls);
  4299. if (!pi->sched_tbl)
  4300. dev_warn(&pdev->dev,
  4301. "could not activate scheduling on port %d\n",
  4302. i);
  4303. }
  4304. if (tid_init(&adapter->tids) < 0) {
  4305. dev_warn(&pdev->dev, "could not allocate TID table, "
  4306. "continuing\n");
  4307. adapter->params.offload = 0;
  4308. } else {
  4309. adapter->tc_u32 = cxgb4_init_tc_u32(adapter);
  4310. if (!adapter->tc_u32)
  4311. dev_warn(&pdev->dev,
  4312. "could not offload tc u32, continuing\n");
  4313. }
  4314. if (is_offload(adapter)) {
  4315. if (t4_read_reg(adapter, LE_DB_CONFIG_A) & HASHEN_F) {
  4316. u32 hash_base, hash_reg;
  4317. if (chip <= CHELSIO_T5) {
  4318. hash_reg = LE_DB_TID_HASHBASE_A;
  4319. hash_base = t4_read_reg(adapter, hash_reg);
  4320. adapter->tids.hash_base = hash_base / 4;
  4321. } else {
  4322. hash_reg = T6_LE_DB_HASH_TID_BASE_A;
  4323. hash_base = t4_read_reg(adapter, hash_reg);
  4324. adapter->tids.hash_base = hash_base;
  4325. }
  4326. }
  4327. }
  4328. /* See what interrupts we'll be using */
  4329. if (msi > 1 && enable_msix(adapter) == 0)
  4330. adapter->flags |= USING_MSIX;
  4331. else if (msi > 0 && pci_enable_msi(pdev) == 0) {
  4332. adapter->flags |= USING_MSI;
  4333. if (msi > 1)
  4334. free_msix_info(adapter);
  4335. }
  4336. /* check for PCI Express bandwidth capabiltites */
  4337. cxgb4_check_pcie_caps(adapter);
  4338. err = init_rss(adapter);
  4339. if (err)
  4340. goto out_free_dev;
  4341. /*
  4342. * The card is now ready to go. If any errors occur during device
  4343. * registration we do not fail the whole card but rather proceed only
  4344. * with the ports we manage to register successfully. However we must
  4345. * register at least one net device.
  4346. */
  4347. for_each_port(adapter, i) {
  4348. pi = adap2pinfo(adapter, i);
  4349. adapter->port[i]->dev_port = pi->lport;
  4350. netif_set_real_num_tx_queues(adapter->port[i], pi->nqsets);
  4351. netif_set_real_num_rx_queues(adapter->port[i], pi->nqsets);
  4352. err = register_netdev(adapter->port[i]);
  4353. if (err)
  4354. break;
  4355. adapter->chan_map[pi->tx_chan] = i;
  4356. print_port_info(adapter->port[i]);
  4357. }
  4358. if (i == 0) {
  4359. dev_err(&pdev->dev, "could not register any net devices\n");
  4360. goto out_free_dev;
  4361. }
  4362. if (err) {
  4363. dev_warn(&pdev->dev, "only %d net devices registered\n", i);
  4364. err = 0;
  4365. }
  4366. if (cxgb4_debugfs_root) {
  4367. adapter->debugfs_root = debugfs_create_dir(pci_name(pdev),
  4368. cxgb4_debugfs_root);
  4369. setup_debugfs(adapter);
  4370. }
  4371. /* PCIe EEH recovery on powerpc platforms needs fundamental reset */
  4372. pdev->needs_freset = 1;
  4373. if (is_uld(adapter)) {
  4374. mutex_lock(&uld_mutex);
  4375. list_add_tail(&adapter->list_node, &adapter_list);
  4376. mutex_unlock(&uld_mutex);
  4377. }
  4378. print_adapter_info(adapter);
  4379. setup_fw_sge_queues(adapter);
  4380. return 0;
  4381. sriov:
  4382. #ifdef CONFIG_PCI_IOV
  4383. adapter = kzalloc(sizeof(*adapter), GFP_KERNEL);
  4384. if (!adapter) {
  4385. err = -ENOMEM;
  4386. goto free_pci_region;
  4387. }
  4388. adapter->pdev = pdev;
  4389. adapter->pdev_dev = &pdev->dev;
  4390. adapter->name = pci_name(pdev);
  4391. adapter->mbox = func;
  4392. adapter->pf = func;
  4393. adapter->regs = regs;
  4394. adapter->adap_idx = adap_idx;
  4395. adapter->mbox_log = kzalloc(sizeof(*adapter->mbox_log) +
  4396. (sizeof(struct mbox_cmd) *
  4397. T4_OS_LOG_MBOX_CMDS),
  4398. GFP_KERNEL);
  4399. if (!adapter->mbox_log) {
  4400. err = -ENOMEM;
  4401. goto free_adapter;
  4402. }
  4403. spin_lock_init(&adapter->mbox_lock);
  4404. INIT_LIST_HEAD(&adapter->mlist.list);
  4405. v = FW_PARAMS_MNEM_V(FW_PARAMS_MNEM_DEV) |
  4406. FW_PARAMS_PARAM_X_V(FW_PARAMS_PARAM_DEV_PORTVEC);
  4407. err = t4_query_params(adapter, adapter->mbox, adapter->pf, 0, 1,
  4408. &v, &port_vec);
  4409. if (err < 0) {
  4410. dev_err(adapter->pdev_dev, "Could not fetch port params\n");
  4411. goto free_adapter;
  4412. }
  4413. adapter->params.nports = hweight32(port_vec);
  4414. pci_set_drvdata(pdev, adapter);
  4415. return 0;
  4416. free_adapter:
  4417. kfree(adapter);
  4418. free_pci_region:
  4419. iounmap(regs);
  4420. pci_disable_sriov(pdev);
  4421. pci_release_regions(pdev);
  4422. return err;
  4423. #else
  4424. return 0;
  4425. #endif
  4426. out_free_dev:
  4427. free_some_resources(adapter);
  4428. if (adapter->flags & USING_MSIX)
  4429. free_msix_info(adapter);
  4430. if (adapter->num_uld || adapter->num_ofld_uld)
  4431. t4_uld_mem_free(adapter);
  4432. out_unmap_bar:
  4433. if (!is_t4(adapter->params.chip))
  4434. iounmap(adapter->bar2);
  4435. out_free_adapter:
  4436. if (adapter->workq)
  4437. destroy_workqueue(adapter->workq);
  4438. kfree(adapter->mbox_log);
  4439. kfree(adapter);
  4440. out_unmap_bar0:
  4441. iounmap(regs);
  4442. out_disable_device:
  4443. pci_disable_pcie_error_reporting(pdev);
  4444. pci_disable_device(pdev);
  4445. out_release_regions:
  4446. pci_release_regions(pdev);
  4447. return err;
  4448. }
  4449. static void remove_one(struct pci_dev *pdev)
  4450. {
  4451. struct adapter *adapter = pci_get_drvdata(pdev);
  4452. if (!adapter) {
  4453. pci_release_regions(pdev);
  4454. return;
  4455. }
  4456. if (adapter->pf == 4) {
  4457. int i;
  4458. /* Tear down per-adapter Work Queue first since it can contain
  4459. * references to our adapter data structure.
  4460. */
  4461. destroy_workqueue(adapter->workq);
  4462. if (is_uld(adapter))
  4463. detach_ulds(adapter);
  4464. disable_interrupts(adapter);
  4465. for_each_port(adapter, i)
  4466. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  4467. unregister_netdev(adapter->port[i]);
  4468. debugfs_remove_recursive(adapter->debugfs_root);
  4469. /* If we allocated filters, free up state associated with any
  4470. * valid filters ...
  4471. */
  4472. clear_all_filters(adapter);
  4473. if (adapter->flags & FULL_INIT_DONE)
  4474. cxgb_down(adapter);
  4475. if (adapter->flags & USING_MSIX)
  4476. free_msix_info(adapter);
  4477. if (adapter->num_uld || adapter->num_ofld_uld)
  4478. t4_uld_mem_free(adapter);
  4479. free_some_resources(adapter);
  4480. #if IS_ENABLED(CONFIG_IPV6)
  4481. t4_cleanup_clip_tbl(adapter);
  4482. #endif
  4483. iounmap(adapter->regs);
  4484. if (!is_t4(adapter->params.chip))
  4485. iounmap(adapter->bar2);
  4486. pci_disable_pcie_error_reporting(pdev);
  4487. if ((adapter->flags & DEV_ENABLED)) {
  4488. pci_disable_device(pdev);
  4489. adapter->flags &= ~DEV_ENABLED;
  4490. }
  4491. pci_release_regions(pdev);
  4492. kfree(adapter->mbox_log);
  4493. synchronize_rcu();
  4494. kfree(adapter);
  4495. }
  4496. #ifdef CONFIG_PCI_IOV
  4497. else {
  4498. if (adapter->port[0])
  4499. unregister_netdev(adapter->port[0]);
  4500. iounmap(adapter->regs);
  4501. kfree(adapter->vfinfo);
  4502. kfree(adapter);
  4503. pci_disable_sriov(pdev);
  4504. pci_release_regions(pdev);
  4505. }
  4506. #endif
  4507. }
  4508. /* "Shutdown" quiesces the device, stopping Ingress Packet and Interrupt
  4509. * delivery. This is essentially a stripped down version of the PCI remove()
  4510. * function where we do the minimal amount of work necessary to shutdown any
  4511. * further activity.
  4512. */
  4513. static void shutdown_one(struct pci_dev *pdev)
  4514. {
  4515. struct adapter *adapter = pci_get_drvdata(pdev);
  4516. /* As with remove_one() above (see extended comment), we only want do
  4517. * do cleanup on PCI Devices which went all the way through init_one()
  4518. * ...
  4519. */
  4520. if (!adapter) {
  4521. pci_release_regions(pdev);
  4522. return;
  4523. }
  4524. if (adapter->pf == 4) {
  4525. int i;
  4526. for_each_port(adapter, i)
  4527. if (adapter->port[i]->reg_state == NETREG_REGISTERED)
  4528. cxgb_close(adapter->port[i]);
  4529. t4_uld_clean_up(adapter);
  4530. disable_interrupts(adapter);
  4531. disable_msi(adapter);
  4532. t4_sge_stop(adapter);
  4533. if (adapter->flags & FW_OK)
  4534. t4_fw_bye(adapter, adapter->mbox);
  4535. }
  4536. #ifdef CONFIG_PCI_IOV
  4537. else {
  4538. if (adapter->port[0])
  4539. unregister_netdev(adapter->port[0]);
  4540. iounmap(adapter->regs);
  4541. kfree(adapter->vfinfo);
  4542. kfree(adapter);
  4543. pci_disable_sriov(pdev);
  4544. pci_release_regions(pdev);
  4545. }
  4546. #endif
  4547. }
  4548. static struct pci_driver cxgb4_driver = {
  4549. .name = KBUILD_MODNAME,
  4550. .id_table = cxgb4_pci_tbl,
  4551. .probe = init_one,
  4552. .remove = remove_one,
  4553. .shutdown = shutdown_one,
  4554. #ifdef CONFIG_PCI_IOV
  4555. .sriov_configure = cxgb4_iov_configure,
  4556. #endif
  4557. .err_handler = &cxgb4_eeh,
  4558. };
  4559. static int __init cxgb4_init_module(void)
  4560. {
  4561. int ret;
  4562. /* Debugfs support is optional, just warn if this fails */
  4563. cxgb4_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
  4564. if (!cxgb4_debugfs_root)
  4565. pr_warn("could not create debugfs entry, continuing\n");
  4566. ret = pci_register_driver(&cxgb4_driver);
  4567. if (ret < 0)
  4568. debugfs_remove(cxgb4_debugfs_root);
  4569. #if IS_ENABLED(CONFIG_IPV6)
  4570. if (!inet6addr_registered) {
  4571. register_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  4572. inet6addr_registered = true;
  4573. }
  4574. #endif
  4575. return ret;
  4576. }
  4577. static void __exit cxgb4_cleanup_module(void)
  4578. {
  4579. #if IS_ENABLED(CONFIG_IPV6)
  4580. if (inet6addr_registered) {
  4581. unregister_inet6addr_notifier(&cxgb4_inet6addr_notifier);
  4582. inet6addr_registered = false;
  4583. }
  4584. #endif
  4585. pci_unregister_driver(&cxgb4_driver);
  4586. debugfs_remove(cxgb4_debugfs_root); /* NULL ok */
  4587. }
  4588. module_init(cxgb4_init_module);
  4589. module_exit(cxgb4_cleanup_module);