cnic.c 141 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527
  1. /* cnic.c: Broadcom CNIC core network driver.
  2. *
  3. * Copyright (c) 2006-2010 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Original skeleton written by: John(Zongxi) Chen (zongxi@broadcom.com)
  10. * Modified and maintained by: Michael Chan <mchan@broadcom.com>
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/errno.h>
  16. #include <linux/list.h>
  17. #include <linux/slab.h>
  18. #include <linux/pci.h>
  19. #include <linux/init.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/uio_driver.h>
  22. #include <linux/in.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/delay.h>
  25. #include <linux/ethtool.h>
  26. #include <linux/if_vlan.h>
  27. #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
  28. #define BCM_VLAN 1
  29. #endif
  30. #include <net/ip.h>
  31. #include <net/tcp.h>
  32. #include <net/route.h>
  33. #include <net/ipv6.h>
  34. #include <net/ip6_route.h>
  35. #include <net/ip6_checksum.h>
  36. #include <scsi/iscsi_if.h>
  37. #include "cnic_if.h"
  38. #include "bnx2.h"
  39. #include "bnx2x/bnx2x_reg.h"
  40. #include "bnx2x/bnx2x_fw_defs.h"
  41. #include "bnx2x/bnx2x_hsi.h"
  42. #include "../scsi/bnx2i/57xx_iscsi_constants.h"
  43. #include "../scsi/bnx2i/57xx_iscsi_hsi.h"
  44. #include "cnic.h"
  45. #include "cnic_defs.h"
  46. #define DRV_MODULE_NAME "cnic"
  47. static char version[] __devinitdata =
  48. "Broadcom NetXtreme II CNIC Driver " DRV_MODULE_NAME " v" CNIC_MODULE_VERSION " (" CNIC_MODULE_RELDATE ")\n";
  49. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com> and John(Zongxi) "
  50. "Chen (zongxi@broadcom.com");
  51. MODULE_DESCRIPTION("Broadcom NetXtreme II CNIC Driver");
  52. MODULE_LICENSE("GPL");
  53. MODULE_VERSION(CNIC_MODULE_VERSION);
  54. /* cnic_dev_list modifications are protected by both rtnl and cnic_dev_lock */
  55. static LIST_HEAD(cnic_dev_list);
  56. static LIST_HEAD(cnic_udev_list);
  57. static DEFINE_RWLOCK(cnic_dev_lock);
  58. static DEFINE_MUTEX(cnic_lock);
  59. static struct cnic_ulp_ops *cnic_ulp_tbl[MAX_CNIC_ULP_TYPE];
  60. static int cnic_service_bnx2(void *, void *);
  61. static int cnic_service_bnx2x(void *, void *);
  62. static int cnic_ctl(void *, struct cnic_ctl_info *);
  63. static struct cnic_ops cnic_bnx2_ops = {
  64. .cnic_owner = THIS_MODULE,
  65. .cnic_handler = cnic_service_bnx2,
  66. .cnic_ctl = cnic_ctl,
  67. };
  68. static struct cnic_ops cnic_bnx2x_ops = {
  69. .cnic_owner = THIS_MODULE,
  70. .cnic_handler = cnic_service_bnx2x,
  71. .cnic_ctl = cnic_ctl,
  72. };
  73. static struct workqueue_struct *cnic_wq;
  74. static void cnic_shutdown_rings(struct cnic_dev *);
  75. static void cnic_init_rings(struct cnic_dev *);
  76. static int cnic_cm_set_pg(struct cnic_sock *);
  77. static int cnic_uio_open(struct uio_info *uinfo, struct inode *inode)
  78. {
  79. struct cnic_uio_dev *udev = uinfo->priv;
  80. struct cnic_dev *dev;
  81. if (!capable(CAP_NET_ADMIN))
  82. return -EPERM;
  83. if (udev->uio_dev != -1)
  84. return -EBUSY;
  85. rtnl_lock();
  86. dev = udev->dev;
  87. if (!dev || !test_bit(CNIC_F_CNIC_UP, &dev->flags)) {
  88. rtnl_unlock();
  89. return -ENODEV;
  90. }
  91. udev->uio_dev = iminor(inode);
  92. cnic_shutdown_rings(dev);
  93. cnic_init_rings(dev);
  94. rtnl_unlock();
  95. return 0;
  96. }
  97. static int cnic_uio_close(struct uio_info *uinfo, struct inode *inode)
  98. {
  99. struct cnic_uio_dev *udev = uinfo->priv;
  100. udev->uio_dev = -1;
  101. return 0;
  102. }
  103. static inline void cnic_hold(struct cnic_dev *dev)
  104. {
  105. atomic_inc(&dev->ref_count);
  106. }
  107. static inline void cnic_put(struct cnic_dev *dev)
  108. {
  109. atomic_dec(&dev->ref_count);
  110. }
  111. static inline void csk_hold(struct cnic_sock *csk)
  112. {
  113. atomic_inc(&csk->ref_count);
  114. }
  115. static inline void csk_put(struct cnic_sock *csk)
  116. {
  117. atomic_dec(&csk->ref_count);
  118. }
  119. static struct cnic_dev *cnic_from_netdev(struct net_device *netdev)
  120. {
  121. struct cnic_dev *cdev;
  122. read_lock(&cnic_dev_lock);
  123. list_for_each_entry(cdev, &cnic_dev_list, list) {
  124. if (netdev == cdev->netdev) {
  125. cnic_hold(cdev);
  126. read_unlock(&cnic_dev_lock);
  127. return cdev;
  128. }
  129. }
  130. read_unlock(&cnic_dev_lock);
  131. return NULL;
  132. }
  133. static inline void ulp_get(struct cnic_ulp_ops *ulp_ops)
  134. {
  135. atomic_inc(&ulp_ops->ref_count);
  136. }
  137. static inline void ulp_put(struct cnic_ulp_ops *ulp_ops)
  138. {
  139. atomic_dec(&ulp_ops->ref_count);
  140. }
  141. static void cnic_ctx_wr(struct cnic_dev *dev, u32 cid_addr, u32 off, u32 val)
  142. {
  143. struct cnic_local *cp = dev->cnic_priv;
  144. struct cnic_eth_dev *ethdev = cp->ethdev;
  145. struct drv_ctl_info info;
  146. struct drv_ctl_io *io = &info.data.io;
  147. info.cmd = DRV_CTL_CTX_WR_CMD;
  148. io->cid_addr = cid_addr;
  149. io->offset = off;
  150. io->data = val;
  151. ethdev->drv_ctl(dev->netdev, &info);
  152. }
  153. static void cnic_ctx_tbl_wr(struct cnic_dev *dev, u32 off, dma_addr_t addr)
  154. {
  155. struct cnic_local *cp = dev->cnic_priv;
  156. struct cnic_eth_dev *ethdev = cp->ethdev;
  157. struct drv_ctl_info info;
  158. struct drv_ctl_io *io = &info.data.io;
  159. info.cmd = DRV_CTL_CTXTBL_WR_CMD;
  160. io->offset = off;
  161. io->dma_addr = addr;
  162. ethdev->drv_ctl(dev->netdev, &info);
  163. }
  164. static void cnic_ring_ctl(struct cnic_dev *dev, u32 cid, u32 cl_id, int start)
  165. {
  166. struct cnic_local *cp = dev->cnic_priv;
  167. struct cnic_eth_dev *ethdev = cp->ethdev;
  168. struct drv_ctl_info info;
  169. struct drv_ctl_l2_ring *ring = &info.data.ring;
  170. if (start)
  171. info.cmd = DRV_CTL_START_L2_CMD;
  172. else
  173. info.cmd = DRV_CTL_STOP_L2_CMD;
  174. ring->cid = cid;
  175. ring->client_id = cl_id;
  176. ethdev->drv_ctl(dev->netdev, &info);
  177. }
  178. static void cnic_reg_wr_ind(struct cnic_dev *dev, u32 off, u32 val)
  179. {
  180. struct cnic_local *cp = dev->cnic_priv;
  181. struct cnic_eth_dev *ethdev = cp->ethdev;
  182. struct drv_ctl_info info;
  183. struct drv_ctl_io *io = &info.data.io;
  184. info.cmd = DRV_CTL_IO_WR_CMD;
  185. io->offset = off;
  186. io->data = val;
  187. ethdev->drv_ctl(dev->netdev, &info);
  188. }
  189. static u32 cnic_reg_rd_ind(struct cnic_dev *dev, u32 off)
  190. {
  191. struct cnic_local *cp = dev->cnic_priv;
  192. struct cnic_eth_dev *ethdev = cp->ethdev;
  193. struct drv_ctl_info info;
  194. struct drv_ctl_io *io = &info.data.io;
  195. info.cmd = DRV_CTL_IO_RD_CMD;
  196. io->offset = off;
  197. ethdev->drv_ctl(dev->netdev, &info);
  198. return io->data;
  199. }
  200. static int cnic_in_use(struct cnic_sock *csk)
  201. {
  202. return test_bit(SK_F_INUSE, &csk->flags);
  203. }
  204. static void cnic_spq_completion(struct cnic_dev *dev, int cmd, u32 count)
  205. {
  206. struct cnic_local *cp = dev->cnic_priv;
  207. struct cnic_eth_dev *ethdev = cp->ethdev;
  208. struct drv_ctl_info info;
  209. info.cmd = cmd;
  210. info.data.credit.credit_count = count;
  211. ethdev->drv_ctl(dev->netdev, &info);
  212. }
  213. static int cnic_get_l5_cid(struct cnic_local *cp, u32 cid, u32 *l5_cid)
  214. {
  215. u32 i;
  216. for (i = 0; i < cp->max_cid_space; i++) {
  217. if (cp->ctx_tbl[i].cid == cid) {
  218. *l5_cid = i;
  219. return 0;
  220. }
  221. }
  222. return -EINVAL;
  223. }
  224. static int cnic_send_nlmsg(struct cnic_local *cp, u32 type,
  225. struct cnic_sock *csk)
  226. {
  227. struct iscsi_path path_req;
  228. char *buf = NULL;
  229. u16 len = 0;
  230. u32 msg_type = ISCSI_KEVENT_IF_DOWN;
  231. struct cnic_ulp_ops *ulp_ops;
  232. struct cnic_uio_dev *udev = cp->udev;
  233. int rc = 0, retry = 0;
  234. if (!udev || udev->uio_dev == -1)
  235. return -ENODEV;
  236. if (csk) {
  237. len = sizeof(path_req);
  238. buf = (char *) &path_req;
  239. memset(&path_req, 0, len);
  240. msg_type = ISCSI_KEVENT_PATH_REQ;
  241. path_req.handle = (u64) csk->l5_cid;
  242. if (test_bit(SK_F_IPV6, &csk->flags)) {
  243. memcpy(&path_req.dst.v6_addr, &csk->dst_ip[0],
  244. sizeof(struct in6_addr));
  245. path_req.ip_addr_len = 16;
  246. } else {
  247. memcpy(&path_req.dst.v4_addr, &csk->dst_ip[0],
  248. sizeof(struct in_addr));
  249. path_req.ip_addr_len = 4;
  250. }
  251. path_req.vlan_id = csk->vlan_id;
  252. path_req.pmtu = csk->mtu;
  253. }
  254. while (retry < 3) {
  255. rc = 0;
  256. rcu_read_lock();
  257. ulp_ops = rcu_dereference(cnic_ulp_tbl[CNIC_ULP_ISCSI]);
  258. if (ulp_ops)
  259. rc = ulp_ops->iscsi_nl_send_msg(
  260. cp->ulp_handle[CNIC_ULP_ISCSI],
  261. msg_type, buf, len);
  262. rcu_read_unlock();
  263. if (rc == 0 || msg_type != ISCSI_KEVENT_PATH_REQ)
  264. break;
  265. msleep(100);
  266. retry++;
  267. }
  268. return 0;
  269. }
  270. static void cnic_cm_upcall(struct cnic_local *, struct cnic_sock *, u8);
  271. static int cnic_iscsi_nl_msg_recv(struct cnic_dev *dev, u32 msg_type,
  272. char *buf, u16 len)
  273. {
  274. int rc = -EINVAL;
  275. switch (msg_type) {
  276. case ISCSI_UEVENT_PATH_UPDATE: {
  277. struct cnic_local *cp;
  278. u32 l5_cid;
  279. struct cnic_sock *csk;
  280. struct iscsi_path *path_resp;
  281. if (len < sizeof(*path_resp))
  282. break;
  283. path_resp = (struct iscsi_path *) buf;
  284. cp = dev->cnic_priv;
  285. l5_cid = (u32) path_resp->handle;
  286. if (l5_cid >= MAX_CM_SK_TBL_SZ)
  287. break;
  288. rcu_read_lock();
  289. if (!rcu_dereference(cp->ulp_ops[CNIC_ULP_L4])) {
  290. rc = -ENODEV;
  291. rcu_read_unlock();
  292. break;
  293. }
  294. csk = &cp->csk_tbl[l5_cid];
  295. csk_hold(csk);
  296. if (cnic_in_use(csk) &&
  297. test_bit(SK_F_CONNECT_START, &csk->flags)) {
  298. memcpy(csk->ha, path_resp->mac_addr, 6);
  299. if (test_bit(SK_F_IPV6, &csk->flags))
  300. memcpy(&csk->src_ip[0], &path_resp->src.v6_addr,
  301. sizeof(struct in6_addr));
  302. else
  303. memcpy(&csk->src_ip[0], &path_resp->src.v4_addr,
  304. sizeof(struct in_addr));
  305. if (is_valid_ether_addr(csk->ha)) {
  306. cnic_cm_set_pg(csk);
  307. } else if (!test_bit(SK_F_OFFLD_SCHED, &csk->flags) &&
  308. !test_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) {
  309. cnic_cm_upcall(cp, csk,
  310. L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE);
  311. clear_bit(SK_F_CONNECT_START, &csk->flags);
  312. }
  313. }
  314. csk_put(csk);
  315. rcu_read_unlock();
  316. rc = 0;
  317. }
  318. }
  319. return rc;
  320. }
  321. static int cnic_offld_prep(struct cnic_sock *csk)
  322. {
  323. if (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags))
  324. return 0;
  325. if (!test_bit(SK_F_CONNECT_START, &csk->flags)) {
  326. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  327. return 0;
  328. }
  329. return 1;
  330. }
  331. static int cnic_close_prep(struct cnic_sock *csk)
  332. {
  333. clear_bit(SK_F_CONNECT_START, &csk->flags);
  334. smp_mb__after_clear_bit();
  335. if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) {
  336. while (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags))
  337. msleep(1);
  338. return 1;
  339. }
  340. return 0;
  341. }
  342. static int cnic_abort_prep(struct cnic_sock *csk)
  343. {
  344. clear_bit(SK_F_CONNECT_START, &csk->flags);
  345. smp_mb__after_clear_bit();
  346. while (test_and_set_bit(SK_F_OFFLD_SCHED, &csk->flags))
  347. msleep(1);
  348. if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) {
  349. csk->state = L4_KCQE_OPCODE_VALUE_RESET_COMP;
  350. return 1;
  351. }
  352. return 0;
  353. }
  354. int cnic_register_driver(int ulp_type, struct cnic_ulp_ops *ulp_ops)
  355. {
  356. struct cnic_dev *dev;
  357. if (ulp_type < 0 || ulp_type >= MAX_CNIC_ULP_TYPE) {
  358. pr_err("%s: Bad type %d\n", __func__, ulp_type);
  359. return -EINVAL;
  360. }
  361. mutex_lock(&cnic_lock);
  362. if (cnic_ulp_tbl[ulp_type]) {
  363. pr_err("%s: Type %d has already been registered\n",
  364. __func__, ulp_type);
  365. mutex_unlock(&cnic_lock);
  366. return -EBUSY;
  367. }
  368. read_lock(&cnic_dev_lock);
  369. list_for_each_entry(dev, &cnic_dev_list, list) {
  370. struct cnic_local *cp = dev->cnic_priv;
  371. clear_bit(ULP_F_INIT, &cp->ulp_flags[ulp_type]);
  372. }
  373. read_unlock(&cnic_dev_lock);
  374. atomic_set(&ulp_ops->ref_count, 0);
  375. rcu_assign_pointer(cnic_ulp_tbl[ulp_type], ulp_ops);
  376. mutex_unlock(&cnic_lock);
  377. /* Prevent race conditions with netdev_event */
  378. rtnl_lock();
  379. list_for_each_entry(dev, &cnic_dev_list, list) {
  380. struct cnic_local *cp = dev->cnic_priv;
  381. if (!test_and_set_bit(ULP_F_INIT, &cp->ulp_flags[ulp_type]))
  382. ulp_ops->cnic_init(dev);
  383. }
  384. rtnl_unlock();
  385. return 0;
  386. }
  387. int cnic_unregister_driver(int ulp_type)
  388. {
  389. struct cnic_dev *dev;
  390. struct cnic_ulp_ops *ulp_ops;
  391. int i = 0;
  392. if (ulp_type < 0 || ulp_type >= MAX_CNIC_ULP_TYPE) {
  393. pr_err("%s: Bad type %d\n", __func__, ulp_type);
  394. return -EINVAL;
  395. }
  396. mutex_lock(&cnic_lock);
  397. ulp_ops = cnic_ulp_tbl[ulp_type];
  398. if (!ulp_ops) {
  399. pr_err("%s: Type %d has not been registered\n",
  400. __func__, ulp_type);
  401. goto out_unlock;
  402. }
  403. read_lock(&cnic_dev_lock);
  404. list_for_each_entry(dev, &cnic_dev_list, list) {
  405. struct cnic_local *cp = dev->cnic_priv;
  406. if (rcu_dereference(cp->ulp_ops[ulp_type])) {
  407. pr_err("%s: Type %d still has devices registered\n",
  408. __func__, ulp_type);
  409. read_unlock(&cnic_dev_lock);
  410. goto out_unlock;
  411. }
  412. }
  413. read_unlock(&cnic_dev_lock);
  414. rcu_assign_pointer(cnic_ulp_tbl[ulp_type], NULL);
  415. mutex_unlock(&cnic_lock);
  416. synchronize_rcu();
  417. while ((atomic_read(&ulp_ops->ref_count) != 0) && (i < 20)) {
  418. msleep(100);
  419. i++;
  420. }
  421. if (atomic_read(&ulp_ops->ref_count) != 0)
  422. netdev_warn(dev->netdev, "Failed waiting for ref count to go to zero\n");
  423. return 0;
  424. out_unlock:
  425. mutex_unlock(&cnic_lock);
  426. return -EINVAL;
  427. }
  428. static int cnic_start_hw(struct cnic_dev *);
  429. static void cnic_stop_hw(struct cnic_dev *);
  430. static int cnic_register_device(struct cnic_dev *dev, int ulp_type,
  431. void *ulp_ctx)
  432. {
  433. struct cnic_local *cp = dev->cnic_priv;
  434. struct cnic_ulp_ops *ulp_ops;
  435. if (ulp_type < 0 || ulp_type >= MAX_CNIC_ULP_TYPE) {
  436. pr_err("%s: Bad type %d\n", __func__, ulp_type);
  437. return -EINVAL;
  438. }
  439. mutex_lock(&cnic_lock);
  440. if (cnic_ulp_tbl[ulp_type] == NULL) {
  441. pr_err("%s: Driver with type %d has not been registered\n",
  442. __func__, ulp_type);
  443. mutex_unlock(&cnic_lock);
  444. return -EAGAIN;
  445. }
  446. if (rcu_dereference(cp->ulp_ops[ulp_type])) {
  447. pr_err("%s: Type %d has already been registered to this device\n",
  448. __func__, ulp_type);
  449. mutex_unlock(&cnic_lock);
  450. return -EBUSY;
  451. }
  452. clear_bit(ULP_F_START, &cp->ulp_flags[ulp_type]);
  453. cp->ulp_handle[ulp_type] = ulp_ctx;
  454. ulp_ops = cnic_ulp_tbl[ulp_type];
  455. rcu_assign_pointer(cp->ulp_ops[ulp_type], ulp_ops);
  456. cnic_hold(dev);
  457. if (test_bit(CNIC_F_CNIC_UP, &dev->flags))
  458. if (!test_and_set_bit(ULP_F_START, &cp->ulp_flags[ulp_type]))
  459. ulp_ops->cnic_start(cp->ulp_handle[ulp_type]);
  460. mutex_unlock(&cnic_lock);
  461. return 0;
  462. }
  463. EXPORT_SYMBOL(cnic_register_driver);
  464. static int cnic_unregister_device(struct cnic_dev *dev, int ulp_type)
  465. {
  466. struct cnic_local *cp = dev->cnic_priv;
  467. int i = 0;
  468. if (ulp_type < 0 || ulp_type >= MAX_CNIC_ULP_TYPE) {
  469. pr_err("%s: Bad type %d\n", __func__, ulp_type);
  470. return -EINVAL;
  471. }
  472. mutex_lock(&cnic_lock);
  473. if (rcu_dereference(cp->ulp_ops[ulp_type])) {
  474. rcu_assign_pointer(cp->ulp_ops[ulp_type], NULL);
  475. cnic_put(dev);
  476. } else {
  477. pr_err("%s: device not registered to this ulp type %d\n",
  478. __func__, ulp_type);
  479. mutex_unlock(&cnic_lock);
  480. return -EINVAL;
  481. }
  482. mutex_unlock(&cnic_lock);
  483. if (ulp_type == CNIC_ULP_ISCSI)
  484. cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
  485. synchronize_rcu();
  486. while (test_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[ulp_type]) &&
  487. i < 20) {
  488. msleep(100);
  489. i++;
  490. }
  491. if (test_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[ulp_type]))
  492. netdev_warn(dev->netdev, "Failed waiting for ULP up call to complete\n");
  493. return 0;
  494. }
  495. EXPORT_SYMBOL(cnic_unregister_driver);
  496. static int cnic_init_id_tbl(struct cnic_id_tbl *id_tbl, u32 size, u32 start_id)
  497. {
  498. id_tbl->start = start_id;
  499. id_tbl->max = size;
  500. id_tbl->next = 0;
  501. spin_lock_init(&id_tbl->lock);
  502. id_tbl->table = kzalloc(DIV_ROUND_UP(size, 32) * 4, GFP_KERNEL);
  503. if (!id_tbl->table)
  504. return -ENOMEM;
  505. return 0;
  506. }
  507. static void cnic_free_id_tbl(struct cnic_id_tbl *id_tbl)
  508. {
  509. kfree(id_tbl->table);
  510. id_tbl->table = NULL;
  511. }
  512. static int cnic_alloc_id(struct cnic_id_tbl *id_tbl, u32 id)
  513. {
  514. int ret = -1;
  515. id -= id_tbl->start;
  516. if (id >= id_tbl->max)
  517. return ret;
  518. spin_lock(&id_tbl->lock);
  519. if (!test_bit(id, id_tbl->table)) {
  520. set_bit(id, id_tbl->table);
  521. ret = 0;
  522. }
  523. spin_unlock(&id_tbl->lock);
  524. return ret;
  525. }
  526. /* Returns -1 if not successful */
  527. static u32 cnic_alloc_new_id(struct cnic_id_tbl *id_tbl)
  528. {
  529. u32 id;
  530. spin_lock(&id_tbl->lock);
  531. id = find_next_zero_bit(id_tbl->table, id_tbl->max, id_tbl->next);
  532. if (id >= id_tbl->max) {
  533. id = -1;
  534. if (id_tbl->next != 0) {
  535. id = find_first_zero_bit(id_tbl->table, id_tbl->next);
  536. if (id >= id_tbl->next)
  537. id = -1;
  538. }
  539. }
  540. if (id < id_tbl->max) {
  541. set_bit(id, id_tbl->table);
  542. id_tbl->next = (id + 1) & (id_tbl->max - 1);
  543. id += id_tbl->start;
  544. }
  545. spin_unlock(&id_tbl->lock);
  546. return id;
  547. }
  548. static void cnic_free_id(struct cnic_id_tbl *id_tbl, u32 id)
  549. {
  550. if (id == -1)
  551. return;
  552. id -= id_tbl->start;
  553. if (id >= id_tbl->max)
  554. return;
  555. clear_bit(id, id_tbl->table);
  556. }
  557. static void cnic_free_dma(struct cnic_dev *dev, struct cnic_dma *dma)
  558. {
  559. int i;
  560. if (!dma->pg_arr)
  561. return;
  562. for (i = 0; i < dma->num_pages; i++) {
  563. if (dma->pg_arr[i]) {
  564. dma_free_coherent(&dev->pcidev->dev, BCM_PAGE_SIZE,
  565. dma->pg_arr[i], dma->pg_map_arr[i]);
  566. dma->pg_arr[i] = NULL;
  567. }
  568. }
  569. if (dma->pgtbl) {
  570. dma_free_coherent(&dev->pcidev->dev, dma->pgtbl_size,
  571. dma->pgtbl, dma->pgtbl_map);
  572. dma->pgtbl = NULL;
  573. }
  574. kfree(dma->pg_arr);
  575. dma->pg_arr = NULL;
  576. dma->num_pages = 0;
  577. }
  578. static void cnic_setup_page_tbl(struct cnic_dev *dev, struct cnic_dma *dma)
  579. {
  580. int i;
  581. u32 *page_table = dma->pgtbl;
  582. for (i = 0; i < dma->num_pages; i++) {
  583. /* Each entry needs to be in big endian format. */
  584. *page_table = (u32) ((u64) dma->pg_map_arr[i] >> 32);
  585. page_table++;
  586. *page_table = (u32) dma->pg_map_arr[i];
  587. page_table++;
  588. }
  589. }
  590. static void cnic_setup_page_tbl_le(struct cnic_dev *dev, struct cnic_dma *dma)
  591. {
  592. int i;
  593. u32 *page_table = dma->pgtbl;
  594. for (i = 0; i < dma->num_pages; i++) {
  595. /* Each entry needs to be in little endian format. */
  596. *page_table = dma->pg_map_arr[i] & 0xffffffff;
  597. page_table++;
  598. *page_table = (u32) ((u64) dma->pg_map_arr[i] >> 32);
  599. page_table++;
  600. }
  601. }
  602. static int cnic_alloc_dma(struct cnic_dev *dev, struct cnic_dma *dma,
  603. int pages, int use_pg_tbl)
  604. {
  605. int i, size;
  606. struct cnic_local *cp = dev->cnic_priv;
  607. size = pages * (sizeof(void *) + sizeof(dma_addr_t));
  608. dma->pg_arr = kzalloc(size, GFP_ATOMIC);
  609. if (dma->pg_arr == NULL)
  610. return -ENOMEM;
  611. dma->pg_map_arr = (dma_addr_t *) (dma->pg_arr + pages);
  612. dma->num_pages = pages;
  613. for (i = 0; i < pages; i++) {
  614. dma->pg_arr[i] = dma_alloc_coherent(&dev->pcidev->dev,
  615. BCM_PAGE_SIZE,
  616. &dma->pg_map_arr[i],
  617. GFP_ATOMIC);
  618. if (dma->pg_arr[i] == NULL)
  619. goto error;
  620. }
  621. if (!use_pg_tbl)
  622. return 0;
  623. dma->pgtbl_size = ((pages * 8) + BCM_PAGE_SIZE - 1) &
  624. ~(BCM_PAGE_SIZE - 1);
  625. dma->pgtbl = dma_alloc_coherent(&dev->pcidev->dev, dma->pgtbl_size,
  626. &dma->pgtbl_map, GFP_ATOMIC);
  627. if (dma->pgtbl == NULL)
  628. goto error;
  629. cp->setup_pgtbl(dev, dma);
  630. return 0;
  631. error:
  632. cnic_free_dma(dev, dma);
  633. return -ENOMEM;
  634. }
  635. static void cnic_free_context(struct cnic_dev *dev)
  636. {
  637. struct cnic_local *cp = dev->cnic_priv;
  638. int i;
  639. for (i = 0; i < cp->ctx_blks; i++) {
  640. if (cp->ctx_arr[i].ctx) {
  641. dma_free_coherent(&dev->pcidev->dev, cp->ctx_blk_size,
  642. cp->ctx_arr[i].ctx,
  643. cp->ctx_arr[i].mapping);
  644. cp->ctx_arr[i].ctx = NULL;
  645. }
  646. }
  647. }
  648. static void __cnic_free_uio(struct cnic_uio_dev *udev)
  649. {
  650. uio_unregister_device(&udev->cnic_uinfo);
  651. if (udev->l2_buf) {
  652. dma_free_coherent(&udev->pdev->dev, udev->l2_buf_size,
  653. udev->l2_buf, udev->l2_buf_map);
  654. udev->l2_buf = NULL;
  655. }
  656. if (udev->l2_ring) {
  657. dma_free_coherent(&udev->pdev->dev, udev->l2_ring_size,
  658. udev->l2_ring, udev->l2_ring_map);
  659. udev->l2_ring = NULL;
  660. }
  661. pci_dev_put(udev->pdev);
  662. kfree(udev);
  663. }
  664. static void cnic_free_uio(struct cnic_uio_dev *udev)
  665. {
  666. if (!udev)
  667. return;
  668. write_lock(&cnic_dev_lock);
  669. list_del_init(&udev->list);
  670. write_unlock(&cnic_dev_lock);
  671. __cnic_free_uio(udev);
  672. }
  673. static void cnic_free_resc(struct cnic_dev *dev)
  674. {
  675. struct cnic_local *cp = dev->cnic_priv;
  676. struct cnic_uio_dev *udev = cp->udev;
  677. if (udev) {
  678. udev->dev = NULL;
  679. cp->udev = NULL;
  680. }
  681. cnic_free_context(dev);
  682. kfree(cp->ctx_arr);
  683. cp->ctx_arr = NULL;
  684. cp->ctx_blks = 0;
  685. cnic_free_dma(dev, &cp->gbl_buf_info);
  686. cnic_free_dma(dev, &cp->conn_buf_info);
  687. cnic_free_dma(dev, &cp->kwq_info);
  688. cnic_free_dma(dev, &cp->kwq_16_data_info);
  689. cnic_free_dma(dev, &cp->kcq2.dma);
  690. cnic_free_dma(dev, &cp->kcq1.dma);
  691. kfree(cp->iscsi_tbl);
  692. cp->iscsi_tbl = NULL;
  693. kfree(cp->ctx_tbl);
  694. cp->ctx_tbl = NULL;
  695. cnic_free_id_tbl(&cp->fcoe_cid_tbl);
  696. cnic_free_id_tbl(&cp->cid_tbl);
  697. }
  698. static int cnic_alloc_context(struct cnic_dev *dev)
  699. {
  700. struct cnic_local *cp = dev->cnic_priv;
  701. if (CHIP_NUM(cp) == CHIP_NUM_5709) {
  702. int i, k, arr_size;
  703. cp->ctx_blk_size = BCM_PAGE_SIZE;
  704. cp->cids_per_blk = BCM_PAGE_SIZE / 128;
  705. arr_size = BNX2_MAX_CID / cp->cids_per_blk *
  706. sizeof(struct cnic_ctx);
  707. cp->ctx_arr = kzalloc(arr_size, GFP_KERNEL);
  708. if (cp->ctx_arr == NULL)
  709. return -ENOMEM;
  710. k = 0;
  711. for (i = 0; i < 2; i++) {
  712. u32 j, reg, off, lo, hi;
  713. if (i == 0)
  714. off = BNX2_PG_CTX_MAP;
  715. else
  716. off = BNX2_ISCSI_CTX_MAP;
  717. reg = cnic_reg_rd_ind(dev, off);
  718. lo = reg >> 16;
  719. hi = reg & 0xffff;
  720. for (j = lo; j < hi; j += cp->cids_per_blk, k++)
  721. cp->ctx_arr[k].cid = j;
  722. }
  723. cp->ctx_blks = k;
  724. if (cp->ctx_blks >= (BNX2_MAX_CID / cp->cids_per_blk)) {
  725. cp->ctx_blks = 0;
  726. return -ENOMEM;
  727. }
  728. for (i = 0; i < cp->ctx_blks; i++) {
  729. cp->ctx_arr[i].ctx =
  730. dma_alloc_coherent(&dev->pcidev->dev,
  731. BCM_PAGE_SIZE,
  732. &cp->ctx_arr[i].mapping,
  733. GFP_KERNEL);
  734. if (cp->ctx_arr[i].ctx == NULL)
  735. return -ENOMEM;
  736. }
  737. }
  738. return 0;
  739. }
  740. static int cnic_alloc_kcq(struct cnic_dev *dev, struct kcq_info *info)
  741. {
  742. int err, i, is_bnx2 = 0;
  743. struct kcqe **kcq;
  744. if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags))
  745. is_bnx2 = 1;
  746. err = cnic_alloc_dma(dev, &info->dma, KCQ_PAGE_CNT, is_bnx2);
  747. if (err)
  748. return err;
  749. kcq = (struct kcqe **) info->dma.pg_arr;
  750. info->kcq = kcq;
  751. if (is_bnx2)
  752. return 0;
  753. for (i = 0; i < KCQ_PAGE_CNT; i++) {
  754. struct bnx2x_bd_chain_next *next =
  755. (struct bnx2x_bd_chain_next *) &kcq[i][MAX_KCQE_CNT];
  756. int j = i + 1;
  757. if (j >= KCQ_PAGE_CNT)
  758. j = 0;
  759. next->addr_hi = (u64) info->dma.pg_map_arr[j] >> 32;
  760. next->addr_lo = info->dma.pg_map_arr[j] & 0xffffffff;
  761. }
  762. return 0;
  763. }
  764. static int cnic_alloc_uio_rings(struct cnic_dev *dev, int pages)
  765. {
  766. struct cnic_local *cp = dev->cnic_priv;
  767. struct cnic_uio_dev *udev;
  768. read_lock(&cnic_dev_lock);
  769. list_for_each_entry(udev, &cnic_udev_list, list) {
  770. if (udev->pdev == dev->pcidev) {
  771. udev->dev = dev;
  772. cp->udev = udev;
  773. read_unlock(&cnic_dev_lock);
  774. return 0;
  775. }
  776. }
  777. read_unlock(&cnic_dev_lock);
  778. udev = kzalloc(sizeof(struct cnic_uio_dev), GFP_ATOMIC);
  779. if (!udev)
  780. return -ENOMEM;
  781. udev->uio_dev = -1;
  782. udev->dev = dev;
  783. udev->pdev = dev->pcidev;
  784. udev->l2_ring_size = pages * BCM_PAGE_SIZE;
  785. udev->l2_ring = dma_alloc_coherent(&udev->pdev->dev, udev->l2_ring_size,
  786. &udev->l2_ring_map,
  787. GFP_KERNEL | __GFP_COMP);
  788. if (!udev->l2_ring)
  789. goto err_udev;
  790. udev->l2_buf_size = (cp->l2_rx_ring_size + 1) * cp->l2_single_buf_size;
  791. udev->l2_buf_size = PAGE_ALIGN(udev->l2_buf_size);
  792. udev->l2_buf = dma_alloc_coherent(&udev->pdev->dev, udev->l2_buf_size,
  793. &udev->l2_buf_map,
  794. GFP_KERNEL | __GFP_COMP);
  795. if (!udev->l2_buf)
  796. goto err_dma;
  797. write_lock(&cnic_dev_lock);
  798. list_add(&udev->list, &cnic_udev_list);
  799. write_unlock(&cnic_dev_lock);
  800. pci_dev_get(udev->pdev);
  801. cp->udev = udev;
  802. return 0;
  803. err_dma:
  804. dma_free_coherent(&udev->pdev->dev, udev->l2_ring_size,
  805. udev->l2_ring, udev->l2_ring_map);
  806. err_udev:
  807. kfree(udev);
  808. return -ENOMEM;
  809. }
  810. static int cnic_init_uio(struct cnic_dev *dev)
  811. {
  812. struct cnic_local *cp = dev->cnic_priv;
  813. struct cnic_uio_dev *udev = cp->udev;
  814. struct uio_info *uinfo;
  815. int ret = 0;
  816. if (!udev)
  817. return -ENOMEM;
  818. uinfo = &udev->cnic_uinfo;
  819. uinfo->mem[0].addr = dev->netdev->base_addr;
  820. uinfo->mem[0].internal_addr = dev->regview;
  821. uinfo->mem[0].size = dev->netdev->mem_end - dev->netdev->mem_start;
  822. uinfo->mem[0].memtype = UIO_MEM_PHYS;
  823. if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
  824. uinfo->mem[1].addr = (unsigned long) cp->status_blk.gen &
  825. PAGE_MASK;
  826. if (cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)
  827. uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE * 9;
  828. else
  829. uinfo->mem[1].size = BNX2_SBLK_MSIX_ALIGN_SIZE;
  830. uinfo->name = "bnx2_cnic";
  831. } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
  832. uinfo->mem[1].addr = (unsigned long) cp->bnx2x_def_status_blk &
  833. PAGE_MASK;
  834. uinfo->mem[1].size = sizeof(*cp->bnx2x_def_status_blk);
  835. uinfo->name = "bnx2x_cnic";
  836. }
  837. uinfo->mem[1].memtype = UIO_MEM_LOGICAL;
  838. uinfo->mem[2].addr = (unsigned long) udev->l2_ring;
  839. uinfo->mem[2].size = udev->l2_ring_size;
  840. uinfo->mem[2].memtype = UIO_MEM_LOGICAL;
  841. uinfo->mem[3].addr = (unsigned long) udev->l2_buf;
  842. uinfo->mem[3].size = udev->l2_buf_size;
  843. uinfo->mem[3].memtype = UIO_MEM_LOGICAL;
  844. uinfo->version = CNIC_MODULE_VERSION;
  845. uinfo->irq = UIO_IRQ_CUSTOM;
  846. uinfo->open = cnic_uio_open;
  847. uinfo->release = cnic_uio_close;
  848. if (udev->uio_dev == -1) {
  849. if (!uinfo->priv) {
  850. uinfo->priv = udev;
  851. ret = uio_register_device(&udev->pdev->dev, uinfo);
  852. }
  853. } else {
  854. cnic_init_rings(dev);
  855. }
  856. return ret;
  857. }
  858. static int cnic_alloc_bnx2_resc(struct cnic_dev *dev)
  859. {
  860. struct cnic_local *cp = dev->cnic_priv;
  861. int ret;
  862. ret = cnic_alloc_dma(dev, &cp->kwq_info, KWQ_PAGE_CNT, 1);
  863. if (ret)
  864. goto error;
  865. cp->kwq = (struct kwqe **) cp->kwq_info.pg_arr;
  866. ret = cnic_alloc_kcq(dev, &cp->kcq1);
  867. if (ret)
  868. goto error;
  869. ret = cnic_alloc_context(dev);
  870. if (ret)
  871. goto error;
  872. ret = cnic_alloc_uio_rings(dev, 2);
  873. if (ret)
  874. goto error;
  875. ret = cnic_init_uio(dev);
  876. if (ret)
  877. goto error;
  878. return 0;
  879. error:
  880. cnic_free_resc(dev);
  881. return ret;
  882. }
  883. static int cnic_alloc_bnx2x_context(struct cnic_dev *dev)
  884. {
  885. struct cnic_local *cp = dev->cnic_priv;
  886. int ctx_blk_size = cp->ethdev->ctx_blk_size;
  887. int total_mem, blks, i;
  888. total_mem = BNX2X_CONTEXT_MEM_SIZE * cp->max_cid_space;
  889. blks = total_mem / ctx_blk_size;
  890. if (total_mem % ctx_blk_size)
  891. blks++;
  892. if (blks > cp->ethdev->ctx_tbl_len)
  893. return -ENOMEM;
  894. cp->ctx_arr = kcalloc(blks, sizeof(struct cnic_ctx), GFP_KERNEL);
  895. if (cp->ctx_arr == NULL)
  896. return -ENOMEM;
  897. cp->ctx_blks = blks;
  898. cp->ctx_blk_size = ctx_blk_size;
  899. if (!BNX2X_CHIP_IS_57710(cp->chip_id))
  900. cp->ctx_align = 0;
  901. else
  902. cp->ctx_align = ctx_blk_size;
  903. cp->cids_per_blk = ctx_blk_size / BNX2X_CONTEXT_MEM_SIZE;
  904. for (i = 0; i < blks; i++) {
  905. cp->ctx_arr[i].ctx =
  906. dma_alloc_coherent(&dev->pcidev->dev, cp->ctx_blk_size,
  907. &cp->ctx_arr[i].mapping,
  908. GFP_KERNEL);
  909. if (cp->ctx_arr[i].ctx == NULL)
  910. return -ENOMEM;
  911. if (cp->ctx_align && cp->ctx_blk_size == ctx_blk_size) {
  912. if (cp->ctx_arr[i].mapping & (cp->ctx_align - 1)) {
  913. cnic_free_context(dev);
  914. cp->ctx_blk_size += cp->ctx_align;
  915. i = -1;
  916. continue;
  917. }
  918. }
  919. }
  920. return 0;
  921. }
  922. static int cnic_alloc_bnx2x_resc(struct cnic_dev *dev)
  923. {
  924. struct cnic_local *cp = dev->cnic_priv;
  925. struct cnic_eth_dev *ethdev = cp->ethdev;
  926. u32 start_cid = ethdev->starting_cid;
  927. int i, j, n, ret, pages;
  928. struct cnic_dma *kwq_16_dma = &cp->kwq_16_data_info;
  929. cp->iro_arr = ethdev->iro_arr;
  930. cp->max_cid_space = MAX_ISCSI_TBL_SZ + BNX2X_FCOE_NUM_CONNECTIONS;
  931. cp->iscsi_start_cid = start_cid;
  932. cp->fcoe_start_cid = start_cid + MAX_ISCSI_TBL_SZ;
  933. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  934. cp->max_cid_space += BNX2X_FCOE_NUM_CONNECTIONS;
  935. cp->fcoe_init_cid = ethdev->fcoe_init_cid;
  936. if (!cp->fcoe_init_cid)
  937. cp->fcoe_init_cid = 0x10;
  938. }
  939. if (start_cid < BNX2X_ISCSI_START_CID) {
  940. u32 delta = BNX2X_ISCSI_START_CID - start_cid;
  941. cp->iscsi_start_cid = BNX2X_ISCSI_START_CID;
  942. cp->fcoe_start_cid += delta;
  943. cp->max_cid_space += delta;
  944. }
  945. cp->iscsi_tbl = kzalloc(sizeof(struct cnic_iscsi) * MAX_ISCSI_TBL_SZ,
  946. GFP_KERNEL);
  947. if (!cp->iscsi_tbl)
  948. goto error;
  949. cp->ctx_tbl = kzalloc(sizeof(struct cnic_context) *
  950. cp->max_cid_space, GFP_KERNEL);
  951. if (!cp->ctx_tbl)
  952. goto error;
  953. for (i = 0; i < MAX_ISCSI_TBL_SZ; i++) {
  954. cp->ctx_tbl[i].proto.iscsi = &cp->iscsi_tbl[i];
  955. cp->ctx_tbl[i].ulp_proto_id = CNIC_ULP_ISCSI;
  956. }
  957. for (i = MAX_ISCSI_TBL_SZ; i < cp->max_cid_space; i++)
  958. cp->ctx_tbl[i].ulp_proto_id = CNIC_ULP_FCOE;
  959. pages = PAGE_ALIGN(cp->max_cid_space * CNIC_KWQ16_DATA_SIZE) /
  960. PAGE_SIZE;
  961. ret = cnic_alloc_dma(dev, kwq_16_dma, pages, 0);
  962. if (ret)
  963. return -ENOMEM;
  964. n = PAGE_SIZE / CNIC_KWQ16_DATA_SIZE;
  965. for (i = 0, j = 0; i < cp->max_cid_space; i++) {
  966. long off = CNIC_KWQ16_DATA_SIZE * (i % n);
  967. cp->ctx_tbl[i].kwqe_data = kwq_16_dma->pg_arr[j] + off;
  968. cp->ctx_tbl[i].kwqe_data_mapping = kwq_16_dma->pg_map_arr[j] +
  969. off;
  970. if ((i % n) == (n - 1))
  971. j++;
  972. }
  973. ret = cnic_alloc_kcq(dev, &cp->kcq1);
  974. if (ret)
  975. goto error;
  976. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  977. ret = cnic_alloc_kcq(dev, &cp->kcq2);
  978. if (ret)
  979. goto error;
  980. }
  981. pages = PAGE_ALIGN(BNX2X_ISCSI_NUM_CONNECTIONS *
  982. BNX2X_ISCSI_CONN_BUF_SIZE) / PAGE_SIZE;
  983. ret = cnic_alloc_dma(dev, &cp->conn_buf_info, pages, 1);
  984. if (ret)
  985. goto error;
  986. pages = PAGE_ALIGN(BNX2X_ISCSI_GLB_BUF_SIZE) / PAGE_SIZE;
  987. ret = cnic_alloc_dma(dev, &cp->gbl_buf_info, pages, 0);
  988. if (ret)
  989. goto error;
  990. ret = cnic_alloc_bnx2x_context(dev);
  991. if (ret)
  992. goto error;
  993. cp->bnx2x_def_status_blk = cp->ethdev->irq_arr[1].status_blk;
  994. cp->l2_rx_ring_size = 15;
  995. ret = cnic_alloc_uio_rings(dev, 4);
  996. if (ret)
  997. goto error;
  998. ret = cnic_init_uio(dev);
  999. if (ret)
  1000. goto error;
  1001. return 0;
  1002. error:
  1003. cnic_free_resc(dev);
  1004. return -ENOMEM;
  1005. }
  1006. static inline u32 cnic_kwq_avail(struct cnic_local *cp)
  1007. {
  1008. return cp->max_kwq_idx -
  1009. ((cp->kwq_prod_idx - cp->kwq_con_idx) & cp->max_kwq_idx);
  1010. }
  1011. static int cnic_submit_bnx2_kwqes(struct cnic_dev *dev, struct kwqe *wqes[],
  1012. u32 num_wqes)
  1013. {
  1014. struct cnic_local *cp = dev->cnic_priv;
  1015. struct kwqe *prod_qe;
  1016. u16 prod, sw_prod, i;
  1017. if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
  1018. return -EAGAIN; /* bnx2 is down */
  1019. spin_lock_bh(&cp->cnic_ulp_lock);
  1020. if (num_wqes > cnic_kwq_avail(cp) &&
  1021. !test_bit(CNIC_LCL_FL_KWQ_INIT, &cp->cnic_local_flags)) {
  1022. spin_unlock_bh(&cp->cnic_ulp_lock);
  1023. return -EAGAIN;
  1024. }
  1025. clear_bit(CNIC_LCL_FL_KWQ_INIT, &cp->cnic_local_flags);
  1026. prod = cp->kwq_prod_idx;
  1027. sw_prod = prod & MAX_KWQ_IDX;
  1028. for (i = 0; i < num_wqes; i++) {
  1029. prod_qe = &cp->kwq[KWQ_PG(sw_prod)][KWQ_IDX(sw_prod)];
  1030. memcpy(prod_qe, wqes[i], sizeof(struct kwqe));
  1031. prod++;
  1032. sw_prod = prod & MAX_KWQ_IDX;
  1033. }
  1034. cp->kwq_prod_idx = prod;
  1035. CNIC_WR16(dev, cp->kwq_io_addr, cp->kwq_prod_idx);
  1036. spin_unlock_bh(&cp->cnic_ulp_lock);
  1037. return 0;
  1038. }
  1039. static void *cnic_get_kwqe_16_data(struct cnic_local *cp, u32 l5_cid,
  1040. union l5cm_specific_data *l5_data)
  1041. {
  1042. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1043. dma_addr_t map;
  1044. map = ctx->kwqe_data_mapping;
  1045. l5_data->phy_address.lo = (u64) map & 0xffffffff;
  1046. l5_data->phy_address.hi = (u64) map >> 32;
  1047. return ctx->kwqe_data;
  1048. }
  1049. static int cnic_submit_kwqe_16(struct cnic_dev *dev, u32 cmd, u32 cid,
  1050. u32 type, union l5cm_specific_data *l5_data)
  1051. {
  1052. struct cnic_local *cp = dev->cnic_priv;
  1053. struct l5cm_spe kwqe;
  1054. struct kwqe_16 *kwq[1];
  1055. int ret;
  1056. kwqe.hdr.conn_and_cmd_data =
  1057. cpu_to_le32(((cmd << SPE_HDR_CMD_ID_SHIFT) |
  1058. BNX2X_HW_CID(cp, cid)));
  1059. kwqe.hdr.type = cpu_to_le16(type);
  1060. kwqe.hdr.reserved1 = 0;
  1061. kwqe.data.phy_address.lo = cpu_to_le32(l5_data->phy_address.lo);
  1062. kwqe.data.phy_address.hi = cpu_to_le32(l5_data->phy_address.hi);
  1063. kwq[0] = (struct kwqe_16 *) &kwqe;
  1064. spin_lock_bh(&cp->cnic_ulp_lock);
  1065. ret = cp->ethdev->drv_submit_kwqes_16(dev->netdev, kwq, 1);
  1066. spin_unlock_bh(&cp->cnic_ulp_lock);
  1067. if (ret == 1)
  1068. return 0;
  1069. return -EBUSY;
  1070. }
  1071. static void cnic_reply_bnx2x_kcqes(struct cnic_dev *dev, int ulp_type,
  1072. struct kcqe *cqes[], u32 num_cqes)
  1073. {
  1074. struct cnic_local *cp = dev->cnic_priv;
  1075. struct cnic_ulp_ops *ulp_ops;
  1076. rcu_read_lock();
  1077. ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
  1078. if (likely(ulp_ops)) {
  1079. ulp_ops->indicate_kcqes(cp->ulp_handle[ulp_type],
  1080. cqes, num_cqes);
  1081. }
  1082. rcu_read_unlock();
  1083. }
  1084. static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
  1085. {
  1086. struct cnic_local *cp = dev->cnic_priv;
  1087. struct iscsi_kwqe_init1 *req1 = (struct iscsi_kwqe_init1 *) kwqe;
  1088. int hq_bds, pages;
  1089. u32 pfid = cp->pfid;
  1090. cp->num_iscsi_tasks = req1->num_tasks_per_conn;
  1091. cp->num_ccells = req1->num_ccells_per_conn;
  1092. cp->task_array_size = BNX2X_ISCSI_TASK_CONTEXT_SIZE *
  1093. cp->num_iscsi_tasks;
  1094. cp->r2tq_size = cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS *
  1095. BNX2X_ISCSI_R2TQE_SIZE;
  1096. cp->hq_size = cp->num_ccells * BNX2X_ISCSI_HQ_BD_SIZE;
  1097. pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE;
  1098. hq_bds = pages * (PAGE_SIZE / BNX2X_ISCSI_HQ_BD_SIZE);
  1099. cp->num_cqs = req1->num_cqs;
  1100. if (!dev->max_iscsi_conn)
  1101. return 0;
  1102. /* init Tstorm RAM */
  1103. CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid),
  1104. req1->rq_num_wqes);
  1105. CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
  1106. PAGE_SIZE);
  1107. CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
  1108. TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT);
  1109. CNIC_WR16(dev, BAR_TSTRORM_INTMEM +
  1110. TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
  1111. req1->num_tasks_per_conn);
  1112. /* init Ustorm RAM */
  1113. CNIC_WR16(dev, BAR_USTRORM_INTMEM +
  1114. USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid),
  1115. req1->rq_buffer_size);
  1116. CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
  1117. PAGE_SIZE);
  1118. CNIC_WR8(dev, BAR_USTRORM_INTMEM +
  1119. USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT);
  1120. CNIC_WR16(dev, BAR_USTRORM_INTMEM +
  1121. USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
  1122. req1->num_tasks_per_conn);
  1123. CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_RQ_SIZE_OFFSET(pfid),
  1124. req1->rq_num_wqes);
  1125. CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_CQ_SIZE_OFFSET(pfid),
  1126. req1->cq_num_wqes);
  1127. CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid),
  1128. cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS);
  1129. /* init Xstorm RAM */
  1130. CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
  1131. PAGE_SIZE);
  1132. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1133. XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT);
  1134. CNIC_WR16(dev, BAR_XSTRORM_INTMEM +
  1135. XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
  1136. req1->num_tasks_per_conn);
  1137. CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_HQ_SIZE_OFFSET(pfid),
  1138. hq_bds);
  1139. CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_SQ_SIZE_OFFSET(pfid),
  1140. req1->num_tasks_per_conn);
  1141. CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid),
  1142. cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS);
  1143. /* init Cstorm RAM */
  1144. CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
  1145. PAGE_SIZE);
  1146. CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
  1147. CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT);
  1148. CNIC_WR16(dev, BAR_CSTRORM_INTMEM +
  1149. CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
  1150. req1->num_tasks_per_conn);
  1151. CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_CQ_SIZE_OFFSET(pfid),
  1152. req1->cq_num_wqes);
  1153. CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_HQ_SIZE_OFFSET(pfid),
  1154. hq_bds);
  1155. return 0;
  1156. }
  1157. static int cnic_bnx2x_iscsi_init2(struct cnic_dev *dev, struct kwqe *kwqe)
  1158. {
  1159. struct iscsi_kwqe_init2 *req2 = (struct iscsi_kwqe_init2 *) kwqe;
  1160. struct cnic_local *cp = dev->cnic_priv;
  1161. u32 pfid = cp->pfid;
  1162. struct iscsi_kcqe kcqe;
  1163. struct kcqe *cqes[1];
  1164. memset(&kcqe, 0, sizeof(kcqe));
  1165. if (!dev->max_iscsi_conn) {
  1166. kcqe.completion_status =
  1167. ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED;
  1168. goto done;
  1169. }
  1170. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  1171. TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid), req2->error_bit_map[0]);
  1172. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  1173. TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid) + 4,
  1174. req2->error_bit_map[1]);
  1175. CNIC_WR16(dev, BAR_USTRORM_INTMEM +
  1176. USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid), req2->max_cq_sqn);
  1177. CNIC_WR(dev, BAR_USTRORM_INTMEM +
  1178. USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid), req2->error_bit_map[0]);
  1179. CNIC_WR(dev, BAR_USTRORM_INTMEM +
  1180. USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid) + 4,
  1181. req2->error_bit_map[1]);
  1182. CNIC_WR16(dev, BAR_CSTRORM_INTMEM +
  1183. CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid), req2->max_cq_sqn);
  1184. kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_SUCCESS;
  1185. done:
  1186. kcqe.op_code = ISCSI_KCQE_OPCODE_INIT;
  1187. cqes[0] = (struct kcqe *) &kcqe;
  1188. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_ISCSI, cqes, 1);
  1189. return 0;
  1190. }
  1191. static void cnic_free_bnx2x_conn_resc(struct cnic_dev *dev, u32 l5_cid)
  1192. {
  1193. struct cnic_local *cp = dev->cnic_priv;
  1194. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1195. if (ctx->ulp_proto_id == CNIC_ULP_ISCSI) {
  1196. struct cnic_iscsi *iscsi = ctx->proto.iscsi;
  1197. cnic_free_dma(dev, &iscsi->hq_info);
  1198. cnic_free_dma(dev, &iscsi->r2tq_info);
  1199. cnic_free_dma(dev, &iscsi->task_array_info);
  1200. cnic_free_id(&cp->cid_tbl, ctx->cid);
  1201. } else {
  1202. cnic_free_id(&cp->fcoe_cid_tbl, ctx->cid);
  1203. }
  1204. ctx->cid = 0;
  1205. }
  1206. static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev *dev, u32 l5_cid)
  1207. {
  1208. u32 cid;
  1209. int ret, pages;
  1210. struct cnic_local *cp = dev->cnic_priv;
  1211. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1212. struct cnic_iscsi *iscsi = ctx->proto.iscsi;
  1213. if (ctx->ulp_proto_id == CNIC_ULP_FCOE) {
  1214. cid = cnic_alloc_new_id(&cp->fcoe_cid_tbl);
  1215. if (cid == -1) {
  1216. ret = -ENOMEM;
  1217. goto error;
  1218. }
  1219. ctx->cid = cid;
  1220. return 0;
  1221. }
  1222. cid = cnic_alloc_new_id(&cp->cid_tbl);
  1223. if (cid == -1) {
  1224. ret = -ENOMEM;
  1225. goto error;
  1226. }
  1227. ctx->cid = cid;
  1228. pages = PAGE_ALIGN(cp->task_array_size) / PAGE_SIZE;
  1229. ret = cnic_alloc_dma(dev, &iscsi->task_array_info, pages, 1);
  1230. if (ret)
  1231. goto error;
  1232. pages = PAGE_ALIGN(cp->r2tq_size) / PAGE_SIZE;
  1233. ret = cnic_alloc_dma(dev, &iscsi->r2tq_info, pages, 1);
  1234. if (ret)
  1235. goto error;
  1236. pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE;
  1237. ret = cnic_alloc_dma(dev, &iscsi->hq_info, pages, 1);
  1238. if (ret)
  1239. goto error;
  1240. return 0;
  1241. error:
  1242. cnic_free_bnx2x_conn_resc(dev, l5_cid);
  1243. return ret;
  1244. }
  1245. static void *cnic_get_bnx2x_ctx(struct cnic_dev *dev, u32 cid, int init,
  1246. struct regpair *ctx_addr)
  1247. {
  1248. struct cnic_local *cp = dev->cnic_priv;
  1249. struct cnic_eth_dev *ethdev = cp->ethdev;
  1250. int blk = (cid - ethdev->starting_cid) / cp->cids_per_blk;
  1251. int off = (cid - ethdev->starting_cid) % cp->cids_per_blk;
  1252. unsigned long align_off = 0;
  1253. dma_addr_t ctx_map;
  1254. void *ctx;
  1255. if (cp->ctx_align) {
  1256. unsigned long mask = cp->ctx_align - 1;
  1257. if (cp->ctx_arr[blk].mapping & mask)
  1258. align_off = cp->ctx_align -
  1259. (cp->ctx_arr[blk].mapping & mask);
  1260. }
  1261. ctx_map = cp->ctx_arr[blk].mapping + align_off +
  1262. (off * BNX2X_CONTEXT_MEM_SIZE);
  1263. ctx = cp->ctx_arr[blk].ctx + align_off +
  1264. (off * BNX2X_CONTEXT_MEM_SIZE);
  1265. if (init)
  1266. memset(ctx, 0, BNX2X_CONTEXT_MEM_SIZE);
  1267. ctx_addr->lo = ctx_map & 0xffffffff;
  1268. ctx_addr->hi = (u64) ctx_map >> 32;
  1269. return ctx;
  1270. }
  1271. static int cnic_setup_bnx2x_ctx(struct cnic_dev *dev, struct kwqe *wqes[],
  1272. u32 num)
  1273. {
  1274. struct cnic_local *cp = dev->cnic_priv;
  1275. struct iscsi_kwqe_conn_offload1 *req1 =
  1276. (struct iscsi_kwqe_conn_offload1 *) wqes[0];
  1277. struct iscsi_kwqe_conn_offload2 *req2 =
  1278. (struct iscsi_kwqe_conn_offload2 *) wqes[1];
  1279. struct iscsi_kwqe_conn_offload3 *req3;
  1280. struct cnic_context *ctx = &cp->ctx_tbl[req1->iscsi_conn_id];
  1281. struct cnic_iscsi *iscsi = ctx->proto.iscsi;
  1282. u32 cid = ctx->cid;
  1283. u32 hw_cid = BNX2X_HW_CID(cp, cid);
  1284. struct iscsi_context *ictx;
  1285. struct regpair context_addr;
  1286. int i, j, n = 2, n_max;
  1287. ctx->ctx_flags = 0;
  1288. if (!req2->num_additional_wqes)
  1289. return -EINVAL;
  1290. n_max = req2->num_additional_wqes + 2;
  1291. ictx = cnic_get_bnx2x_ctx(dev, cid, 1, &context_addr);
  1292. if (ictx == NULL)
  1293. return -ENOMEM;
  1294. req3 = (struct iscsi_kwqe_conn_offload3 *) wqes[n++];
  1295. ictx->xstorm_ag_context.hq_prod = 1;
  1296. ictx->xstorm_st_context.iscsi.first_burst_length =
  1297. ISCSI_DEF_FIRST_BURST_LEN;
  1298. ictx->xstorm_st_context.iscsi.max_send_pdu_length =
  1299. ISCSI_DEF_MAX_RECV_SEG_LEN;
  1300. ictx->xstorm_st_context.iscsi.sq_pbl_base.lo =
  1301. req1->sq_page_table_addr_lo;
  1302. ictx->xstorm_st_context.iscsi.sq_pbl_base.hi =
  1303. req1->sq_page_table_addr_hi;
  1304. ictx->xstorm_st_context.iscsi.sq_curr_pbe.lo = req2->sq_first_pte.hi;
  1305. ictx->xstorm_st_context.iscsi.sq_curr_pbe.hi = req2->sq_first_pte.lo;
  1306. ictx->xstorm_st_context.iscsi.hq_pbl_base.lo =
  1307. iscsi->hq_info.pgtbl_map & 0xffffffff;
  1308. ictx->xstorm_st_context.iscsi.hq_pbl_base.hi =
  1309. (u64) iscsi->hq_info.pgtbl_map >> 32;
  1310. ictx->xstorm_st_context.iscsi.hq_curr_pbe_base.lo =
  1311. iscsi->hq_info.pgtbl[0];
  1312. ictx->xstorm_st_context.iscsi.hq_curr_pbe_base.hi =
  1313. iscsi->hq_info.pgtbl[1];
  1314. ictx->xstorm_st_context.iscsi.r2tq_pbl_base.lo =
  1315. iscsi->r2tq_info.pgtbl_map & 0xffffffff;
  1316. ictx->xstorm_st_context.iscsi.r2tq_pbl_base.hi =
  1317. (u64) iscsi->r2tq_info.pgtbl_map >> 32;
  1318. ictx->xstorm_st_context.iscsi.r2tq_curr_pbe_base.lo =
  1319. iscsi->r2tq_info.pgtbl[0];
  1320. ictx->xstorm_st_context.iscsi.r2tq_curr_pbe_base.hi =
  1321. iscsi->r2tq_info.pgtbl[1];
  1322. ictx->xstorm_st_context.iscsi.task_pbl_base.lo =
  1323. iscsi->task_array_info.pgtbl_map & 0xffffffff;
  1324. ictx->xstorm_st_context.iscsi.task_pbl_base.hi =
  1325. (u64) iscsi->task_array_info.pgtbl_map >> 32;
  1326. ictx->xstorm_st_context.iscsi.task_pbl_cache_idx =
  1327. BNX2X_ISCSI_PBL_NOT_CACHED;
  1328. ictx->xstorm_st_context.iscsi.flags.flags |=
  1329. XSTORM_ISCSI_CONTEXT_FLAGS_B_IMMEDIATE_DATA;
  1330. ictx->xstorm_st_context.iscsi.flags.flags |=
  1331. XSTORM_ISCSI_CONTEXT_FLAGS_B_INITIAL_R2T;
  1332. ictx->tstorm_st_context.iscsi.hdr_bytes_2_fetch = ISCSI_HEADER_SIZE;
  1333. /* TSTORM requires the base address of RQ DB & not PTE */
  1334. ictx->tstorm_st_context.iscsi.rq_db_phy_addr.lo =
  1335. req2->rq_page_table_addr_lo & PAGE_MASK;
  1336. ictx->tstorm_st_context.iscsi.rq_db_phy_addr.hi =
  1337. req2->rq_page_table_addr_hi;
  1338. ictx->tstorm_st_context.iscsi.iscsi_conn_id = req1->iscsi_conn_id;
  1339. ictx->tstorm_st_context.tcp.cwnd = 0x5A8;
  1340. ictx->tstorm_st_context.tcp.flags2 |=
  1341. TSTORM_TCP_ST_CONTEXT_SECTION_DA_EN;
  1342. ictx->tstorm_st_context.tcp.ooo_support_mode =
  1343. TCP_TSTORM_OOO_DROP_AND_PROC_ACK;
  1344. ictx->timers_context.flags |= TIMERS_BLOCK_CONTEXT_CONN_VALID_FLG;
  1345. ictx->ustorm_st_context.ring.rq.pbl_base.lo =
  1346. req2->rq_page_table_addr_lo;
  1347. ictx->ustorm_st_context.ring.rq.pbl_base.hi =
  1348. req2->rq_page_table_addr_hi;
  1349. ictx->ustorm_st_context.ring.rq.curr_pbe.lo = req3->qp_first_pte[0].hi;
  1350. ictx->ustorm_st_context.ring.rq.curr_pbe.hi = req3->qp_first_pte[0].lo;
  1351. ictx->ustorm_st_context.ring.r2tq.pbl_base.lo =
  1352. iscsi->r2tq_info.pgtbl_map & 0xffffffff;
  1353. ictx->ustorm_st_context.ring.r2tq.pbl_base.hi =
  1354. (u64) iscsi->r2tq_info.pgtbl_map >> 32;
  1355. ictx->ustorm_st_context.ring.r2tq.curr_pbe.lo =
  1356. iscsi->r2tq_info.pgtbl[0];
  1357. ictx->ustorm_st_context.ring.r2tq.curr_pbe.hi =
  1358. iscsi->r2tq_info.pgtbl[1];
  1359. ictx->ustorm_st_context.ring.cq_pbl_base.lo =
  1360. req1->cq_page_table_addr_lo;
  1361. ictx->ustorm_st_context.ring.cq_pbl_base.hi =
  1362. req1->cq_page_table_addr_hi;
  1363. ictx->ustorm_st_context.ring.cq[0].cq_sn = ISCSI_INITIAL_SN;
  1364. ictx->ustorm_st_context.ring.cq[0].curr_pbe.lo = req2->cq_first_pte.hi;
  1365. ictx->ustorm_st_context.ring.cq[0].curr_pbe.hi = req2->cq_first_pte.lo;
  1366. ictx->ustorm_st_context.task_pbe_cache_index =
  1367. BNX2X_ISCSI_PBL_NOT_CACHED;
  1368. ictx->ustorm_st_context.task_pdu_cache_index =
  1369. BNX2X_ISCSI_PDU_HEADER_NOT_CACHED;
  1370. for (i = 1, j = 1; i < cp->num_cqs; i++, j++) {
  1371. if (j == 3) {
  1372. if (n >= n_max)
  1373. break;
  1374. req3 = (struct iscsi_kwqe_conn_offload3 *) wqes[n++];
  1375. j = 0;
  1376. }
  1377. ictx->ustorm_st_context.ring.cq[i].cq_sn = ISCSI_INITIAL_SN;
  1378. ictx->ustorm_st_context.ring.cq[i].curr_pbe.lo =
  1379. req3->qp_first_pte[j].hi;
  1380. ictx->ustorm_st_context.ring.cq[i].curr_pbe.hi =
  1381. req3->qp_first_pte[j].lo;
  1382. }
  1383. ictx->ustorm_st_context.task_pbl_base.lo =
  1384. iscsi->task_array_info.pgtbl_map & 0xffffffff;
  1385. ictx->ustorm_st_context.task_pbl_base.hi =
  1386. (u64) iscsi->task_array_info.pgtbl_map >> 32;
  1387. ictx->ustorm_st_context.tce_phy_addr.lo =
  1388. iscsi->task_array_info.pgtbl[0];
  1389. ictx->ustorm_st_context.tce_phy_addr.hi =
  1390. iscsi->task_array_info.pgtbl[1];
  1391. ictx->ustorm_st_context.iscsi_conn_id = req1->iscsi_conn_id;
  1392. ictx->ustorm_st_context.num_cqs = cp->num_cqs;
  1393. ictx->ustorm_st_context.negotiated_rx |= ISCSI_DEF_MAX_RECV_SEG_LEN;
  1394. ictx->ustorm_st_context.negotiated_rx_and_flags |=
  1395. ISCSI_DEF_MAX_BURST_LEN;
  1396. ictx->ustorm_st_context.negotiated_rx |=
  1397. ISCSI_DEFAULT_MAX_OUTSTANDING_R2T <<
  1398. USTORM_ISCSI_ST_CONTEXT_MAX_OUTSTANDING_R2TS_SHIFT;
  1399. ictx->cstorm_st_context.hq_pbl_base.lo =
  1400. iscsi->hq_info.pgtbl_map & 0xffffffff;
  1401. ictx->cstorm_st_context.hq_pbl_base.hi =
  1402. (u64) iscsi->hq_info.pgtbl_map >> 32;
  1403. ictx->cstorm_st_context.hq_curr_pbe.lo = iscsi->hq_info.pgtbl[0];
  1404. ictx->cstorm_st_context.hq_curr_pbe.hi = iscsi->hq_info.pgtbl[1];
  1405. ictx->cstorm_st_context.task_pbl_base.lo =
  1406. iscsi->task_array_info.pgtbl_map & 0xffffffff;
  1407. ictx->cstorm_st_context.task_pbl_base.hi =
  1408. (u64) iscsi->task_array_info.pgtbl_map >> 32;
  1409. /* CSTORM and USTORM initialization is different, CSTORM requires
  1410. * CQ DB base & not PTE addr */
  1411. ictx->cstorm_st_context.cq_db_base.lo =
  1412. req1->cq_page_table_addr_lo & PAGE_MASK;
  1413. ictx->cstorm_st_context.cq_db_base.hi = req1->cq_page_table_addr_hi;
  1414. ictx->cstorm_st_context.iscsi_conn_id = req1->iscsi_conn_id;
  1415. ictx->cstorm_st_context.cq_proc_en_bit_map = (1 << cp->num_cqs) - 1;
  1416. for (i = 0; i < cp->num_cqs; i++) {
  1417. ictx->cstorm_st_context.cq_c_prod_sqn_arr.sqn[i] =
  1418. ISCSI_INITIAL_SN;
  1419. ictx->cstorm_st_context.cq_c_sqn_2_notify_arr.sqn[i] =
  1420. ISCSI_INITIAL_SN;
  1421. }
  1422. ictx->xstorm_ag_context.cdu_reserved =
  1423. CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_XCM_AG,
  1424. ISCSI_CONNECTION_TYPE);
  1425. ictx->ustorm_ag_context.cdu_usage =
  1426. CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_UCM_AG,
  1427. ISCSI_CONNECTION_TYPE);
  1428. return 0;
  1429. }
  1430. static int cnic_bnx2x_iscsi_ofld1(struct cnic_dev *dev, struct kwqe *wqes[],
  1431. u32 num, int *work)
  1432. {
  1433. struct iscsi_kwqe_conn_offload1 *req1;
  1434. struct iscsi_kwqe_conn_offload2 *req2;
  1435. struct cnic_local *cp = dev->cnic_priv;
  1436. struct cnic_context *ctx;
  1437. struct iscsi_kcqe kcqe;
  1438. struct kcqe *cqes[1];
  1439. u32 l5_cid;
  1440. int ret = 0;
  1441. if (num < 2) {
  1442. *work = num;
  1443. return -EINVAL;
  1444. }
  1445. req1 = (struct iscsi_kwqe_conn_offload1 *) wqes[0];
  1446. req2 = (struct iscsi_kwqe_conn_offload2 *) wqes[1];
  1447. if ((num - 2) < req2->num_additional_wqes) {
  1448. *work = num;
  1449. return -EINVAL;
  1450. }
  1451. *work = 2 + req2->num_additional_wqes;
  1452. l5_cid = req1->iscsi_conn_id;
  1453. if (l5_cid >= MAX_ISCSI_TBL_SZ)
  1454. return -EINVAL;
  1455. memset(&kcqe, 0, sizeof(kcqe));
  1456. kcqe.op_code = ISCSI_KCQE_OPCODE_OFFLOAD_CONN;
  1457. kcqe.iscsi_conn_id = l5_cid;
  1458. kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE;
  1459. ctx = &cp->ctx_tbl[l5_cid];
  1460. if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags)) {
  1461. kcqe.completion_status =
  1462. ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY;
  1463. goto done;
  1464. }
  1465. if (atomic_inc_return(&cp->iscsi_conn) > dev->max_iscsi_conn) {
  1466. atomic_dec(&cp->iscsi_conn);
  1467. goto done;
  1468. }
  1469. ret = cnic_alloc_bnx2x_conn_resc(dev, l5_cid);
  1470. if (ret) {
  1471. atomic_dec(&cp->iscsi_conn);
  1472. ret = 0;
  1473. goto done;
  1474. }
  1475. ret = cnic_setup_bnx2x_ctx(dev, wqes, num);
  1476. if (ret < 0) {
  1477. cnic_free_bnx2x_conn_resc(dev, l5_cid);
  1478. atomic_dec(&cp->iscsi_conn);
  1479. goto done;
  1480. }
  1481. kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_SUCCESS;
  1482. kcqe.iscsi_conn_context_id = BNX2X_HW_CID(cp, cp->ctx_tbl[l5_cid].cid);
  1483. done:
  1484. cqes[0] = (struct kcqe *) &kcqe;
  1485. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_ISCSI, cqes, 1);
  1486. return ret;
  1487. }
  1488. static int cnic_bnx2x_iscsi_update(struct cnic_dev *dev, struct kwqe *kwqe)
  1489. {
  1490. struct cnic_local *cp = dev->cnic_priv;
  1491. struct iscsi_kwqe_conn_update *req =
  1492. (struct iscsi_kwqe_conn_update *) kwqe;
  1493. void *data;
  1494. union l5cm_specific_data l5_data;
  1495. u32 l5_cid, cid = BNX2X_SW_CID(req->context_id);
  1496. int ret;
  1497. if (cnic_get_l5_cid(cp, cid, &l5_cid) != 0)
  1498. return -EINVAL;
  1499. data = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1500. if (!data)
  1501. return -ENOMEM;
  1502. memcpy(data, kwqe, sizeof(struct kwqe));
  1503. ret = cnic_submit_kwqe_16(dev, ISCSI_RAMROD_CMD_ID_UPDATE_CONN,
  1504. req->context_id, ISCSI_CONNECTION_TYPE, &l5_data);
  1505. return ret;
  1506. }
  1507. static int cnic_bnx2x_destroy_ramrod(struct cnic_dev *dev, u32 l5_cid)
  1508. {
  1509. struct cnic_local *cp = dev->cnic_priv;
  1510. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1511. union l5cm_specific_data l5_data;
  1512. int ret;
  1513. u32 hw_cid, type;
  1514. init_waitqueue_head(&ctx->waitq);
  1515. ctx->wait_cond = 0;
  1516. memset(&l5_data, 0, sizeof(l5_data));
  1517. hw_cid = BNX2X_HW_CID(cp, ctx->cid);
  1518. type = (NONE_CONNECTION_TYPE << SPE_HDR_CONN_TYPE_SHIFT)
  1519. & SPE_HDR_CONN_TYPE;
  1520. type |= ((cp->pfid << SPE_HDR_FUNCTION_ID_SHIFT) &
  1521. SPE_HDR_FUNCTION_ID);
  1522. ret = cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_COMMON_CFC_DEL,
  1523. hw_cid, type, &l5_data);
  1524. if (ret == 0)
  1525. wait_event(ctx->waitq, ctx->wait_cond);
  1526. return ret;
  1527. }
  1528. static int cnic_bnx2x_iscsi_destroy(struct cnic_dev *dev, struct kwqe *kwqe)
  1529. {
  1530. struct cnic_local *cp = dev->cnic_priv;
  1531. struct iscsi_kwqe_conn_destroy *req =
  1532. (struct iscsi_kwqe_conn_destroy *) kwqe;
  1533. u32 l5_cid = req->reserved0;
  1534. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1535. int ret = 0;
  1536. struct iscsi_kcqe kcqe;
  1537. struct kcqe *cqes[1];
  1538. if (!test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags))
  1539. goto skip_cfc_delete;
  1540. if (!time_after(jiffies, ctx->timestamp + (2 * HZ))) {
  1541. unsigned long delta = ctx->timestamp + (2 * HZ) - jiffies;
  1542. if (delta > (2 * HZ))
  1543. delta = 0;
  1544. set_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags);
  1545. queue_delayed_work(cnic_wq, &cp->delete_task, delta);
  1546. goto destroy_reply;
  1547. }
  1548. ret = cnic_bnx2x_destroy_ramrod(dev, l5_cid);
  1549. skip_cfc_delete:
  1550. cnic_free_bnx2x_conn_resc(dev, l5_cid);
  1551. atomic_dec(&cp->iscsi_conn);
  1552. clear_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags);
  1553. destroy_reply:
  1554. memset(&kcqe, 0, sizeof(kcqe));
  1555. kcqe.op_code = ISCSI_KCQE_OPCODE_DESTROY_CONN;
  1556. kcqe.iscsi_conn_id = l5_cid;
  1557. kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_SUCCESS;
  1558. kcqe.iscsi_conn_context_id = req->context_id;
  1559. cqes[0] = (struct kcqe *) &kcqe;
  1560. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_ISCSI, cqes, 1);
  1561. return ret;
  1562. }
  1563. static void cnic_init_storm_conn_bufs(struct cnic_dev *dev,
  1564. struct l4_kwq_connect_req1 *kwqe1,
  1565. struct l4_kwq_connect_req3 *kwqe3,
  1566. struct l5cm_active_conn_buffer *conn_buf)
  1567. {
  1568. struct l5cm_conn_addr_params *conn_addr = &conn_buf->conn_addr_buf;
  1569. struct l5cm_xstorm_conn_buffer *xstorm_buf =
  1570. &conn_buf->xstorm_conn_buffer;
  1571. struct l5cm_tstorm_conn_buffer *tstorm_buf =
  1572. &conn_buf->tstorm_conn_buffer;
  1573. struct regpair context_addr;
  1574. u32 cid = BNX2X_SW_CID(kwqe1->cid);
  1575. struct in6_addr src_ip, dst_ip;
  1576. int i;
  1577. u32 *addrp;
  1578. addrp = (u32 *) &conn_addr->local_ip_addr;
  1579. for (i = 0; i < 4; i++, addrp++)
  1580. src_ip.in6_u.u6_addr32[i] = cpu_to_be32(*addrp);
  1581. addrp = (u32 *) &conn_addr->remote_ip_addr;
  1582. for (i = 0; i < 4; i++, addrp++)
  1583. dst_ip.in6_u.u6_addr32[i] = cpu_to_be32(*addrp);
  1584. cnic_get_bnx2x_ctx(dev, cid, 0, &context_addr);
  1585. xstorm_buf->context_addr.hi = context_addr.hi;
  1586. xstorm_buf->context_addr.lo = context_addr.lo;
  1587. xstorm_buf->mss = 0xffff;
  1588. xstorm_buf->rcv_buf = kwqe3->rcv_buf;
  1589. if (kwqe1->tcp_flags & L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE)
  1590. xstorm_buf->params |= L5CM_XSTORM_CONN_BUFFER_NAGLE_ENABLE;
  1591. xstorm_buf->pseudo_header_checksum =
  1592. swab16(~csum_ipv6_magic(&src_ip, &dst_ip, 0, IPPROTO_TCP, 0));
  1593. if (!(kwqe1->tcp_flags & L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK))
  1594. tstorm_buf->params |=
  1595. L5CM_TSTORM_CONN_BUFFER_DELAYED_ACK_ENABLE;
  1596. if (kwqe3->ka_timeout) {
  1597. tstorm_buf->ka_enable = 1;
  1598. tstorm_buf->ka_timeout = kwqe3->ka_timeout;
  1599. tstorm_buf->ka_interval = kwqe3->ka_interval;
  1600. tstorm_buf->ka_max_probe_count = kwqe3->ka_max_probe_count;
  1601. }
  1602. tstorm_buf->rcv_buf = kwqe3->rcv_buf;
  1603. tstorm_buf->snd_buf = kwqe3->snd_buf;
  1604. tstorm_buf->max_rt_time = 0xffffffff;
  1605. }
  1606. static void cnic_init_bnx2x_mac(struct cnic_dev *dev)
  1607. {
  1608. struct cnic_local *cp = dev->cnic_priv;
  1609. u32 pfid = cp->pfid;
  1610. u8 *mac = dev->mac_addr;
  1611. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1612. XSTORM_ISCSI_LOCAL_MAC_ADDR0_OFFSET(pfid), mac[0]);
  1613. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1614. XSTORM_ISCSI_LOCAL_MAC_ADDR1_OFFSET(pfid), mac[1]);
  1615. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1616. XSTORM_ISCSI_LOCAL_MAC_ADDR2_OFFSET(pfid), mac[2]);
  1617. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1618. XSTORM_ISCSI_LOCAL_MAC_ADDR3_OFFSET(pfid), mac[3]);
  1619. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1620. XSTORM_ISCSI_LOCAL_MAC_ADDR4_OFFSET(pfid), mac[4]);
  1621. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1622. XSTORM_ISCSI_LOCAL_MAC_ADDR5_OFFSET(pfid), mac[5]);
  1623. CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
  1624. TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid), mac[5]);
  1625. CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
  1626. TSTORM_ISCSI_TCP_VARS_LSB_LOCAL_MAC_ADDR_OFFSET(pfid) + 1,
  1627. mac[4]);
  1628. CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
  1629. TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid), mac[3]);
  1630. CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
  1631. TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid) + 1,
  1632. mac[2]);
  1633. CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
  1634. TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid) + 2,
  1635. mac[1]);
  1636. CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
  1637. TSTORM_ISCSI_TCP_VARS_MSB_LOCAL_MAC_ADDR_OFFSET(pfid) + 3,
  1638. mac[0]);
  1639. }
  1640. static void cnic_bnx2x_set_tcp_timestamp(struct cnic_dev *dev, int tcp_ts)
  1641. {
  1642. struct cnic_local *cp = dev->cnic_priv;
  1643. u8 xstorm_flags = XSTORM_L5CM_TCP_FLAGS_WND_SCL_EN;
  1644. u16 tstorm_flags = 0;
  1645. if (tcp_ts) {
  1646. xstorm_flags |= XSTORM_L5CM_TCP_FLAGS_TS_ENABLED;
  1647. tstorm_flags |= TSTORM_L5CM_TCP_FLAGS_TS_ENABLED;
  1648. }
  1649. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1650. XSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp->pfid), xstorm_flags);
  1651. CNIC_WR16(dev, BAR_TSTRORM_INTMEM +
  1652. TSTORM_ISCSI_TCP_VARS_FLAGS_OFFSET(cp->pfid), tstorm_flags);
  1653. }
  1654. static int cnic_bnx2x_connect(struct cnic_dev *dev, struct kwqe *wqes[],
  1655. u32 num, int *work)
  1656. {
  1657. struct cnic_local *cp = dev->cnic_priv;
  1658. struct l4_kwq_connect_req1 *kwqe1 =
  1659. (struct l4_kwq_connect_req1 *) wqes[0];
  1660. struct l4_kwq_connect_req3 *kwqe3;
  1661. struct l5cm_active_conn_buffer *conn_buf;
  1662. struct l5cm_conn_addr_params *conn_addr;
  1663. union l5cm_specific_data l5_data;
  1664. u32 l5_cid = kwqe1->pg_cid;
  1665. struct cnic_sock *csk = &cp->csk_tbl[l5_cid];
  1666. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1667. int ret;
  1668. if (num < 2) {
  1669. *work = num;
  1670. return -EINVAL;
  1671. }
  1672. if (kwqe1->conn_flags & L4_KWQ_CONNECT_REQ1_IP_V6)
  1673. *work = 3;
  1674. else
  1675. *work = 2;
  1676. if (num < *work) {
  1677. *work = num;
  1678. return -EINVAL;
  1679. }
  1680. if (sizeof(*conn_buf) > CNIC_KWQ16_DATA_SIZE) {
  1681. netdev_err(dev->netdev, "conn_buf size too big\n");
  1682. return -ENOMEM;
  1683. }
  1684. conn_buf = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1685. if (!conn_buf)
  1686. return -ENOMEM;
  1687. memset(conn_buf, 0, sizeof(*conn_buf));
  1688. conn_addr = &conn_buf->conn_addr_buf;
  1689. conn_addr->remote_addr_0 = csk->ha[0];
  1690. conn_addr->remote_addr_1 = csk->ha[1];
  1691. conn_addr->remote_addr_2 = csk->ha[2];
  1692. conn_addr->remote_addr_3 = csk->ha[3];
  1693. conn_addr->remote_addr_4 = csk->ha[4];
  1694. conn_addr->remote_addr_5 = csk->ha[5];
  1695. if (kwqe1->conn_flags & L4_KWQ_CONNECT_REQ1_IP_V6) {
  1696. struct l4_kwq_connect_req2 *kwqe2 =
  1697. (struct l4_kwq_connect_req2 *) wqes[1];
  1698. conn_addr->local_ip_addr.ip_addr_hi_hi = kwqe2->src_ip_v6_4;
  1699. conn_addr->local_ip_addr.ip_addr_hi_lo = kwqe2->src_ip_v6_3;
  1700. conn_addr->local_ip_addr.ip_addr_lo_hi = kwqe2->src_ip_v6_2;
  1701. conn_addr->remote_ip_addr.ip_addr_hi_hi = kwqe2->dst_ip_v6_4;
  1702. conn_addr->remote_ip_addr.ip_addr_hi_lo = kwqe2->dst_ip_v6_3;
  1703. conn_addr->remote_ip_addr.ip_addr_lo_hi = kwqe2->dst_ip_v6_2;
  1704. conn_addr->params |= L5CM_CONN_ADDR_PARAMS_IP_VERSION;
  1705. }
  1706. kwqe3 = (struct l4_kwq_connect_req3 *) wqes[*work - 1];
  1707. conn_addr->local_ip_addr.ip_addr_lo_lo = kwqe1->src_ip;
  1708. conn_addr->remote_ip_addr.ip_addr_lo_lo = kwqe1->dst_ip;
  1709. conn_addr->local_tcp_port = kwqe1->src_port;
  1710. conn_addr->remote_tcp_port = kwqe1->dst_port;
  1711. conn_addr->pmtu = kwqe3->pmtu;
  1712. cnic_init_storm_conn_bufs(dev, kwqe1, kwqe3, conn_buf);
  1713. CNIC_WR16(dev, BAR_XSTRORM_INTMEM +
  1714. XSTORM_ISCSI_LOCAL_VLAN_OFFSET(cp->pfid), csk->vlan_id);
  1715. cnic_bnx2x_set_tcp_timestamp(dev,
  1716. kwqe1->tcp_flags & L4_KWQ_CONNECT_REQ1_TIME_STAMP);
  1717. ret = cnic_submit_kwqe_16(dev, L5CM_RAMROD_CMD_ID_TCP_CONNECT,
  1718. kwqe1->cid, ISCSI_CONNECTION_TYPE, &l5_data);
  1719. if (!ret)
  1720. set_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags);
  1721. return ret;
  1722. }
  1723. static int cnic_bnx2x_close(struct cnic_dev *dev, struct kwqe *kwqe)
  1724. {
  1725. struct l4_kwq_close_req *req = (struct l4_kwq_close_req *) kwqe;
  1726. union l5cm_specific_data l5_data;
  1727. int ret;
  1728. memset(&l5_data, 0, sizeof(l5_data));
  1729. ret = cnic_submit_kwqe_16(dev, L5CM_RAMROD_CMD_ID_CLOSE,
  1730. req->cid, ISCSI_CONNECTION_TYPE, &l5_data);
  1731. return ret;
  1732. }
  1733. static int cnic_bnx2x_reset(struct cnic_dev *dev, struct kwqe *kwqe)
  1734. {
  1735. struct l4_kwq_reset_req *req = (struct l4_kwq_reset_req *) kwqe;
  1736. union l5cm_specific_data l5_data;
  1737. int ret;
  1738. memset(&l5_data, 0, sizeof(l5_data));
  1739. ret = cnic_submit_kwqe_16(dev, L5CM_RAMROD_CMD_ID_ABORT,
  1740. req->cid, ISCSI_CONNECTION_TYPE, &l5_data);
  1741. return ret;
  1742. }
  1743. static int cnic_bnx2x_offload_pg(struct cnic_dev *dev, struct kwqe *kwqe)
  1744. {
  1745. struct l4_kwq_offload_pg *req = (struct l4_kwq_offload_pg *) kwqe;
  1746. struct l4_kcq kcqe;
  1747. struct kcqe *cqes[1];
  1748. memset(&kcqe, 0, sizeof(kcqe));
  1749. kcqe.pg_host_opaque = req->host_opaque;
  1750. kcqe.pg_cid = req->host_opaque;
  1751. kcqe.op_code = L4_KCQE_OPCODE_VALUE_OFFLOAD_PG;
  1752. cqes[0] = (struct kcqe *) &kcqe;
  1753. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_L4, cqes, 1);
  1754. return 0;
  1755. }
  1756. static int cnic_bnx2x_update_pg(struct cnic_dev *dev, struct kwqe *kwqe)
  1757. {
  1758. struct l4_kwq_update_pg *req = (struct l4_kwq_update_pg *) kwqe;
  1759. struct l4_kcq kcqe;
  1760. struct kcqe *cqes[1];
  1761. memset(&kcqe, 0, sizeof(kcqe));
  1762. kcqe.pg_host_opaque = req->pg_host_opaque;
  1763. kcqe.pg_cid = req->pg_cid;
  1764. kcqe.op_code = L4_KCQE_OPCODE_VALUE_UPDATE_PG;
  1765. cqes[0] = (struct kcqe *) &kcqe;
  1766. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_L4, cqes, 1);
  1767. return 0;
  1768. }
  1769. static int cnic_bnx2x_fcoe_stat(struct cnic_dev *dev, struct kwqe *kwqe)
  1770. {
  1771. struct fcoe_kwqe_stat *req;
  1772. struct fcoe_stat_ramrod_params *fcoe_stat;
  1773. union l5cm_specific_data l5_data;
  1774. struct cnic_local *cp = dev->cnic_priv;
  1775. int ret;
  1776. u32 cid;
  1777. req = (struct fcoe_kwqe_stat *) kwqe;
  1778. cid = BNX2X_HW_CID(cp, cp->fcoe_init_cid);
  1779. fcoe_stat = cnic_get_kwqe_16_data(cp, BNX2X_FCOE_L5_CID_BASE, &l5_data);
  1780. if (!fcoe_stat)
  1781. return -ENOMEM;
  1782. memset(fcoe_stat, 0, sizeof(*fcoe_stat));
  1783. memcpy(&fcoe_stat->stat_kwqe, req, sizeof(*req));
  1784. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_STAT, cid,
  1785. FCOE_CONNECTION_TYPE, &l5_data);
  1786. return ret;
  1787. }
  1788. static int cnic_bnx2x_fcoe_init1(struct cnic_dev *dev, struct kwqe *wqes[],
  1789. u32 num, int *work)
  1790. {
  1791. int ret;
  1792. struct cnic_local *cp = dev->cnic_priv;
  1793. u32 cid;
  1794. struct fcoe_init_ramrod_params *fcoe_init;
  1795. struct fcoe_kwqe_init1 *req1;
  1796. struct fcoe_kwqe_init2 *req2;
  1797. struct fcoe_kwqe_init3 *req3;
  1798. union l5cm_specific_data l5_data;
  1799. if (num < 3) {
  1800. *work = num;
  1801. return -EINVAL;
  1802. }
  1803. req1 = (struct fcoe_kwqe_init1 *) wqes[0];
  1804. req2 = (struct fcoe_kwqe_init2 *) wqes[1];
  1805. req3 = (struct fcoe_kwqe_init3 *) wqes[2];
  1806. if (req2->hdr.op_code != FCOE_KWQE_OPCODE_INIT2) {
  1807. *work = 1;
  1808. return -EINVAL;
  1809. }
  1810. if (req3->hdr.op_code != FCOE_KWQE_OPCODE_INIT3) {
  1811. *work = 2;
  1812. return -EINVAL;
  1813. }
  1814. if (sizeof(*fcoe_init) > CNIC_KWQ16_DATA_SIZE) {
  1815. netdev_err(dev->netdev, "fcoe_init size too big\n");
  1816. return -ENOMEM;
  1817. }
  1818. fcoe_init = cnic_get_kwqe_16_data(cp, BNX2X_FCOE_L5_CID_BASE, &l5_data);
  1819. if (!fcoe_init)
  1820. return -ENOMEM;
  1821. memset(fcoe_init, 0, sizeof(*fcoe_init));
  1822. memcpy(&fcoe_init->init_kwqe1, req1, sizeof(*req1));
  1823. memcpy(&fcoe_init->init_kwqe2, req2, sizeof(*req2));
  1824. memcpy(&fcoe_init->init_kwqe3, req3, sizeof(*req3));
  1825. fcoe_init->eq_addr.lo = cp->kcq2.dma.pg_map_arr[0] & 0xffffffff;
  1826. fcoe_init->eq_addr.hi = (u64) cp->kcq2.dma.pg_map_arr[0] >> 32;
  1827. fcoe_init->eq_next_page_addr.lo =
  1828. cp->kcq2.dma.pg_map_arr[1] & 0xffffffff;
  1829. fcoe_init->eq_next_page_addr.hi =
  1830. (u64) cp->kcq2.dma.pg_map_arr[1] >> 32;
  1831. fcoe_init->sb_num = cp->status_blk_num;
  1832. fcoe_init->eq_prod = MAX_KCQ_IDX;
  1833. fcoe_init->sb_id = HC_INDEX_FCOE_EQ_CONS;
  1834. cp->kcq2.sw_prod_idx = 0;
  1835. cid = BNX2X_HW_CID(cp, cp->fcoe_init_cid);
  1836. printk(KERN_ERR "bdbg: submitting INIT RAMROD \n");
  1837. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_INIT, cid,
  1838. FCOE_CONNECTION_TYPE, &l5_data);
  1839. *work = 3;
  1840. return ret;
  1841. }
  1842. static int cnic_bnx2x_fcoe_ofld1(struct cnic_dev *dev, struct kwqe *wqes[],
  1843. u32 num, int *work)
  1844. {
  1845. int ret = 0;
  1846. u32 cid = -1, l5_cid;
  1847. struct cnic_local *cp = dev->cnic_priv;
  1848. struct fcoe_kwqe_conn_offload1 *req1;
  1849. struct fcoe_kwqe_conn_offload2 *req2;
  1850. struct fcoe_kwqe_conn_offload3 *req3;
  1851. struct fcoe_kwqe_conn_offload4 *req4;
  1852. struct fcoe_conn_offload_ramrod_params *fcoe_offload;
  1853. struct cnic_context *ctx;
  1854. struct fcoe_context *fctx;
  1855. struct regpair ctx_addr;
  1856. union l5cm_specific_data l5_data;
  1857. struct fcoe_kcqe kcqe;
  1858. struct kcqe *cqes[1];
  1859. if (num < 4) {
  1860. *work = num;
  1861. return -EINVAL;
  1862. }
  1863. req1 = (struct fcoe_kwqe_conn_offload1 *) wqes[0];
  1864. req2 = (struct fcoe_kwqe_conn_offload2 *) wqes[1];
  1865. req3 = (struct fcoe_kwqe_conn_offload3 *) wqes[2];
  1866. req4 = (struct fcoe_kwqe_conn_offload4 *) wqes[3];
  1867. *work = 4;
  1868. l5_cid = req1->fcoe_conn_id;
  1869. if (l5_cid >= BNX2X_FCOE_NUM_CONNECTIONS)
  1870. goto err_reply;
  1871. l5_cid += BNX2X_FCOE_L5_CID_BASE;
  1872. ctx = &cp->ctx_tbl[l5_cid];
  1873. if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags))
  1874. goto err_reply;
  1875. ret = cnic_alloc_bnx2x_conn_resc(dev, l5_cid);
  1876. if (ret) {
  1877. ret = 0;
  1878. goto err_reply;
  1879. }
  1880. cid = ctx->cid;
  1881. fctx = cnic_get_bnx2x_ctx(dev, cid, 1, &ctx_addr);
  1882. if (fctx) {
  1883. u32 hw_cid = BNX2X_HW_CID(cp, cid);
  1884. u32 val;
  1885. val = CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_XCM_AG,
  1886. FCOE_CONNECTION_TYPE);
  1887. fctx->xstorm_ag_context.cdu_reserved = val;
  1888. val = CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_UCM_AG,
  1889. FCOE_CONNECTION_TYPE);
  1890. fctx->ustorm_ag_context.cdu_usage = val;
  1891. }
  1892. if (sizeof(*fcoe_offload) > CNIC_KWQ16_DATA_SIZE) {
  1893. netdev_err(dev->netdev, "fcoe_offload size too big\n");
  1894. goto err_reply;
  1895. }
  1896. fcoe_offload = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1897. if (!fcoe_offload)
  1898. goto err_reply;
  1899. memset(fcoe_offload, 0, sizeof(*fcoe_offload));
  1900. memcpy(&fcoe_offload->offload_kwqe1, req1, sizeof(*req1));
  1901. memcpy(&fcoe_offload->offload_kwqe2, req2, sizeof(*req2));
  1902. memcpy(&fcoe_offload->offload_kwqe3, req3, sizeof(*req3));
  1903. memcpy(&fcoe_offload->offload_kwqe4, req4, sizeof(*req4));
  1904. cid = BNX2X_HW_CID(cp, cid);
  1905. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_OFFLOAD_CONN, cid,
  1906. FCOE_CONNECTION_TYPE, &l5_data);
  1907. if (!ret)
  1908. set_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags);
  1909. return ret;
  1910. err_reply:
  1911. if (cid != -1)
  1912. cnic_free_bnx2x_conn_resc(dev, l5_cid);
  1913. memset(&kcqe, 0, sizeof(kcqe));
  1914. kcqe.op_code = FCOE_KCQE_OPCODE_OFFLOAD_CONN;
  1915. kcqe.fcoe_conn_id = req1->fcoe_conn_id;
  1916. kcqe.completion_status = FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE;
  1917. cqes[0] = (struct kcqe *) &kcqe;
  1918. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_FCOE, cqes, 1);
  1919. return ret;
  1920. }
  1921. static int cnic_bnx2x_fcoe_enable(struct cnic_dev *dev, struct kwqe *kwqe)
  1922. {
  1923. struct fcoe_kwqe_conn_enable_disable *req;
  1924. struct fcoe_conn_enable_disable_ramrod_params *fcoe_enable;
  1925. union l5cm_specific_data l5_data;
  1926. int ret;
  1927. u32 cid, l5_cid;
  1928. struct cnic_local *cp = dev->cnic_priv;
  1929. req = (struct fcoe_kwqe_conn_enable_disable *) kwqe;
  1930. cid = req->context_id;
  1931. l5_cid = req->conn_id + BNX2X_FCOE_L5_CID_BASE;
  1932. if (sizeof(*fcoe_enable) > CNIC_KWQ16_DATA_SIZE) {
  1933. netdev_err(dev->netdev, "fcoe_enable size too big\n");
  1934. return -ENOMEM;
  1935. }
  1936. fcoe_enable = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1937. if (!fcoe_enable)
  1938. return -ENOMEM;
  1939. memset(fcoe_enable, 0, sizeof(*fcoe_enable));
  1940. memcpy(&fcoe_enable->enable_disable_kwqe, req, sizeof(*req));
  1941. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_ENABLE_CONN, cid,
  1942. FCOE_CONNECTION_TYPE, &l5_data);
  1943. return ret;
  1944. }
  1945. static int cnic_bnx2x_fcoe_disable(struct cnic_dev *dev, struct kwqe *kwqe)
  1946. {
  1947. struct fcoe_kwqe_conn_enable_disable *req;
  1948. struct fcoe_conn_enable_disable_ramrod_params *fcoe_disable;
  1949. union l5cm_specific_data l5_data;
  1950. int ret;
  1951. u32 cid, l5_cid;
  1952. struct cnic_local *cp = dev->cnic_priv;
  1953. req = (struct fcoe_kwqe_conn_enable_disable *) kwqe;
  1954. cid = req->context_id;
  1955. l5_cid = req->conn_id;
  1956. if (l5_cid >= BNX2X_FCOE_NUM_CONNECTIONS)
  1957. return -EINVAL;
  1958. l5_cid += BNX2X_FCOE_L5_CID_BASE;
  1959. if (sizeof(*fcoe_disable) > CNIC_KWQ16_DATA_SIZE) {
  1960. netdev_err(dev->netdev, "fcoe_disable size too big\n");
  1961. return -ENOMEM;
  1962. }
  1963. fcoe_disable = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1964. if (!fcoe_disable)
  1965. return -ENOMEM;
  1966. memset(fcoe_disable, 0, sizeof(*fcoe_disable));
  1967. memcpy(&fcoe_disable->enable_disable_kwqe, req, sizeof(*req));
  1968. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_DISABLE_CONN, cid,
  1969. FCOE_CONNECTION_TYPE, &l5_data);
  1970. return ret;
  1971. }
  1972. static int cnic_bnx2x_fcoe_destroy(struct cnic_dev *dev, struct kwqe *kwqe)
  1973. {
  1974. struct fcoe_kwqe_conn_destroy *req;
  1975. union l5cm_specific_data l5_data;
  1976. int ret;
  1977. u32 cid, l5_cid;
  1978. struct cnic_local *cp = dev->cnic_priv;
  1979. struct cnic_context *ctx;
  1980. struct fcoe_kcqe kcqe;
  1981. struct kcqe *cqes[1];
  1982. req = (struct fcoe_kwqe_conn_destroy *) kwqe;
  1983. cid = req->context_id;
  1984. l5_cid = req->conn_id;
  1985. if (l5_cid >= BNX2X_FCOE_NUM_CONNECTIONS)
  1986. return -EINVAL;
  1987. l5_cid += BNX2X_FCOE_L5_CID_BASE;
  1988. ctx = &cp->ctx_tbl[l5_cid];
  1989. init_waitqueue_head(&ctx->waitq);
  1990. ctx->wait_cond = 0;
  1991. memset(&l5_data, 0, sizeof(l5_data));
  1992. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_TERMINATE_CONN, cid,
  1993. FCOE_CONNECTION_TYPE, &l5_data);
  1994. if (ret == 0) {
  1995. wait_event(ctx->waitq, ctx->wait_cond);
  1996. set_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags);
  1997. queue_delayed_work(cnic_wq, &cp->delete_task,
  1998. msecs_to_jiffies(2000));
  1999. }
  2000. memset(&kcqe, 0, sizeof(kcqe));
  2001. kcqe.op_code = FCOE_KCQE_OPCODE_DESTROY_CONN;
  2002. kcqe.fcoe_conn_id = req->conn_id;
  2003. kcqe.fcoe_conn_context_id = cid;
  2004. cqes[0] = (struct kcqe *) &kcqe;
  2005. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_FCOE, cqes, 1);
  2006. return ret;
  2007. }
  2008. static int cnic_bnx2x_fcoe_fw_destroy(struct cnic_dev *dev, struct kwqe *kwqe)
  2009. {
  2010. struct fcoe_kwqe_destroy *req;
  2011. union l5cm_specific_data l5_data;
  2012. struct cnic_local *cp = dev->cnic_priv;
  2013. int ret;
  2014. u32 cid;
  2015. req = (struct fcoe_kwqe_destroy *) kwqe;
  2016. cid = BNX2X_HW_CID(cp, cp->fcoe_init_cid);
  2017. memset(&l5_data, 0, sizeof(l5_data));
  2018. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_DESTROY, cid,
  2019. FCOE_CONNECTION_TYPE, &l5_data);
  2020. return ret;
  2021. }
  2022. static int cnic_submit_bnx2x_iscsi_kwqes(struct cnic_dev *dev,
  2023. struct kwqe *wqes[], u32 num_wqes)
  2024. {
  2025. int i, work, ret;
  2026. u32 opcode;
  2027. struct kwqe *kwqe;
  2028. if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
  2029. return -EAGAIN; /* bnx2 is down */
  2030. for (i = 0; i < num_wqes; ) {
  2031. kwqe = wqes[i];
  2032. opcode = KWQE_OPCODE(kwqe->kwqe_op_flag);
  2033. work = 1;
  2034. switch (opcode) {
  2035. case ISCSI_KWQE_OPCODE_INIT1:
  2036. ret = cnic_bnx2x_iscsi_init1(dev, kwqe);
  2037. break;
  2038. case ISCSI_KWQE_OPCODE_INIT2:
  2039. ret = cnic_bnx2x_iscsi_init2(dev, kwqe);
  2040. break;
  2041. case ISCSI_KWQE_OPCODE_OFFLOAD_CONN1:
  2042. ret = cnic_bnx2x_iscsi_ofld1(dev, &wqes[i],
  2043. num_wqes - i, &work);
  2044. break;
  2045. case ISCSI_KWQE_OPCODE_UPDATE_CONN:
  2046. ret = cnic_bnx2x_iscsi_update(dev, kwqe);
  2047. break;
  2048. case ISCSI_KWQE_OPCODE_DESTROY_CONN:
  2049. ret = cnic_bnx2x_iscsi_destroy(dev, kwqe);
  2050. break;
  2051. case L4_KWQE_OPCODE_VALUE_CONNECT1:
  2052. ret = cnic_bnx2x_connect(dev, &wqes[i], num_wqes - i,
  2053. &work);
  2054. break;
  2055. case L4_KWQE_OPCODE_VALUE_CLOSE:
  2056. ret = cnic_bnx2x_close(dev, kwqe);
  2057. break;
  2058. case L4_KWQE_OPCODE_VALUE_RESET:
  2059. ret = cnic_bnx2x_reset(dev, kwqe);
  2060. break;
  2061. case L4_KWQE_OPCODE_VALUE_OFFLOAD_PG:
  2062. ret = cnic_bnx2x_offload_pg(dev, kwqe);
  2063. break;
  2064. case L4_KWQE_OPCODE_VALUE_UPDATE_PG:
  2065. ret = cnic_bnx2x_update_pg(dev, kwqe);
  2066. break;
  2067. case L4_KWQE_OPCODE_VALUE_UPLOAD_PG:
  2068. ret = 0;
  2069. break;
  2070. default:
  2071. ret = 0;
  2072. netdev_err(dev->netdev, "Unknown type of KWQE(0x%x)\n",
  2073. opcode);
  2074. break;
  2075. }
  2076. if (ret < 0)
  2077. netdev_err(dev->netdev, "KWQE(0x%x) failed\n",
  2078. opcode);
  2079. i += work;
  2080. }
  2081. return 0;
  2082. }
  2083. static int cnic_submit_bnx2x_fcoe_kwqes(struct cnic_dev *dev,
  2084. struct kwqe *wqes[], u32 num_wqes)
  2085. {
  2086. struct cnic_local *cp = dev->cnic_priv;
  2087. int i, work, ret;
  2088. u32 opcode;
  2089. struct kwqe *kwqe;
  2090. if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
  2091. return -EAGAIN; /* bnx2 is down */
  2092. if (BNX2X_CHIP_NUM(cp->chip_id) == BNX2X_CHIP_NUM_57710)
  2093. return -EINVAL;
  2094. for (i = 0; i < num_wqes; ) {
  2095. kwqe = wqes[i];
  2096. opcode = KWQE_OPCODE(kwqe->kwqe_op_flag);
  2097. work = 1;
  2098. switch (opcode) {
  2099. case FCOE_KWQE_OPCODE_INIT1:
  2100. ret = cnic_bnx2x_fcoe_init1(dev, &wqes[i],
  2101. num_wqes - i, &work);
  2102. break;
  2103. case FCOE_KWQE_OPCODE_OFFLOAD_CONN1:
  2104. ret = cnic_bnx2x_fcoe_ofld1(dev, &wqes[i],
  2105. num_wqes - i, &work);
  2106. break;
  2107. case FCOE_KWQE_OPCODE_ENABLE_CONN:
  2108. ret = cnic_bnx2x_fcoe_enable(dev, kwqe);
  2109. break;
  2110. case FCOE_KWQE_OPCODE_DISABLE_CONN:
  2111. ret = cnic_bnx2x_fcoe_disable(dev, kwqe);
  2112. break;
  2113. case FCOE_KWQE_OPCODE_DESTROY_CONN:
  2114. ret = cnic_bnx2x_fcoe_destroy(dev, kwqe);
  2115. break;
  2116. case FCOE_KWQE_OPCODE_DESTROY:
  2117. ret = cnic_bnx2x_fcoe_fw_destroy(dev, kwqe);
  2118. break;
  2119. case FCOE_KWQE_OPCODE_STAT:
  2120. ret = cnic_bnx2x_fcoe_stat(dev, kwqe);
  2121. break;
  2122. default:
  2123. ret = 0;
  2124. netdev_err(dev->netdev, "Unknown type of KWQE(0x%x)\n",
  2125. opcode);
  2126. break;
  2127. }
  2128. if (ret < 0)
  2129. netdev_err(dev->netdev, "KWQE(0x%x) failed\n",
  2130. opcode);
  2131. i += work;
  2132. }
  2133. return 0;
  2134. }
  2135. static int cnic_submit_bnx2x_kwqes(struct cnic_dev *dev, struct kwqe *wqes[],
  2136. u32 num_wqes)
  2137. {
  2138. int ret = -EINVAL;
  2139. u32 layer_code;
  2140. if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
  2141. return -EAGAIN; /* bnx2x is down */
  2142. if (!num_wqes)
  2143. return 0;
  2144. layer_code = wqes[0]->kwqe_op_flag & KWQE_LAYER_MASK;
  2145. switch (layer_code) {
  2146. case KWQE_FLAGS_LAYER_MASK_L5_ISCSI:
  2147. case KWQE_FLAGS_LAYER_MASK_L4:
  2148. case KWQE_FLAGS_LAYER_MASK_L2:
  2149. ret = cnic_submit_bnx2x_iscsi_kwqes(dev, wqes, num_wqes);
  2150. break;
  2151. case KWQE_FLAGS_LAYER_MASK_L5_FCOE:
  2152. ret = cnic_submit_bnx2x_fcoe_kwqes(dev, wqes, num_wqes);
  2153. break;
  2154. }
  2155. return ret;
  2156. }
  2157. static inline u32 cnic_get_kcqe_layer_mask(u32 opflag)
  2158. {
  2159. if (unlikely(KCQE_OPCODE(opflag) == FCOE_RAMROD_CMD_ID_TERMINATE_CONN))
  2160. return KCQE_FLAGS_LAYER_MASK_L4;
  2161. return opflag & KCQE_FLAGS_LAYER_MASK;
  2162. }
  2163. static void service_kcqes(struct cnic_dev *dev, int num_cqes)
  2164. {
  2165. struct cnic_local *cp = dev->cnic_priv;
  2166. int i, j, comp = 0;
  2167. i = 0;
  2168. j = 1;
  2169. while (num_cqes) {
  2170. struct cnic_ulp_ops *ulp_ops;
  2171. int ulp_type;
  2172. u32 kcqe_op_flag = cp->completed_kcq[i]->kcqe_op_flag;
  2173. u32 kcqe_layer = cnic_get_kcqe_layer_mask(kcqe_op_flag);
  2174. if (unlikely(kcqe_op_flag & KCQE_RAMROD_COMPLETION))
  2175. comp++;
  2176. while (j < num_cqes) {
  2177. u32 next_op = cp->completed_kcq[i + j]->kcqe_op_flag;
  2178. if (cnic_get_kcqe_layer_mask(next_op) != kcqe_layer)
  2179. break;
  2180. if (unlikely(next_op & KCQE_RAMROD_COMPLETION))
  2181. comp++;
  2182. j++;
  2183. }
  2184. if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_RDMA)
  2185. ulp_type = CNIC_ULP_RDMA;
  2186. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_ISCSI)
  2187. ulp_type = CNIC_ULP_ISCSI;
  2188. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_FCOE)
  2189. ulp_type = CNIC_ULP_FCOE;
  2190. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L4)
  2191. ulp_type = CNIC_ULP_L4;
  2192. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L2)
  2193. goto end;
  2194. else {
  2195. netdev_err(dev->netdev, "Unknown type of KCQE(0x%x)\n",
  2196. kcqe_op_flag);
  2197. goto end;
  2198. }
  2199. rcu_read_lock();
  2200. ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
  2201. if (likely(ulp_ops)) {
  2202. ulp_ops->indicate_kcqes(cp->ulp_handle[ulp_type],
  2203. cp->completed_kcq + i, j);
  2204. }
  2205. rcu_read_unlock();
  2206. end:
  2207. num_cqes -= j;
  2208. i += j;
  2209. j = 1;
  2210. }
  2211. if (unlikely(comp))
  2212. cnic_spq_completion(dev, DRV_CTL_RET_L5_SPQ_CREDIT_CMD, comp);
  2213. }
  2214. static u16 cnic_bnx2_next_idx(u16 idx)
  2215. {
  2216. return idx + 1;
  2217. }
  2218. static u16 cnic_bnx2_hw_idx(u16 idx)
  2219. {
  2220. return idx;
  2221. }
  2222. static u16 cnic_bnx2x_next_idx(u16 idx)
  2223. {
  2224. idx++;
  2225. if ((idx & MAX_KCQE_CNT) == MAX_KCQE_CNT)
  2226. idx++;
  2227. return idx;
  2228. }
  2229. static u16 cnic_bnx2x_hw_idx(u16 idx)
  2230. {
  2231. if ((idx & MAX_KCQE_CNT) == MAX_KCQE_CNT)
  2232. idx++;
  2233. return idx;
  2234. }
  2235. static int cnic_get_kcqes(struct cnic_dev *dev, struct kcq_info *info)
  2236. {
  2237. struct cnic_local *cp = dev->cnic_priv;
  2238. u16 i, ri, hw_prod, last;
  2239. struct kcqe *kcqe;
  2240. int kcqe_cnt = 0, last_cnt = 0;
  2241. i = ri = last = info->sw_prod_idx;
  2242. ri &= MAX_KCQ_IDX;
  2243. hw_prod = *info->hw_prod_idx_ptr;
  2244. hw_prod = cp->hw_idx(hw_prod);
  2245. while ((i != hw_prod) && (kcqe_cnt < MAX_COMPLETED_KCQE)) {
  2246. kcqe = &info->kcq[KCQ_PG(ri)][KCQ_IDX(ri)];
  2247. cp->completed_kcq[kcqe_cnt++] = kcqe;
  2248. i = cp->next_idx(i);
  2249. ri = i & MAX_KCQ_IDX;
  2250. if (likely(!(kcqe->kcqe_op_flag & KCQE_FLAGS_NEXT))) {
  2251. last_cnt = kcqe_cnt;
  2252. last = i;
  2253. }
  2254. }
  2255. info->sw_prod_idx = last;
  2256. return last_cnt;
  2257. }
  2258. static int cnic_l2_completion(struct cnic_local *cp)
  2259. {
  2260. u16 hw_cons, sw_cons;
  2261. struct cnic_uio_dev *udev = cp->udev;
  2262. union eth_rx_cqe *cqe, *cqe_ring = (union eth_rx_cqe *)
  2263. (udev->l2_ring + (2 * BCM_PAGE_SIZE));
  2264. u32 cmd;
  2265. int comp = 0;
  2266. if (!test_bit(CNIC_F_BNX2X_CLASS, &cp->dev->flags))
  2267. return 0;
  2268. hw_cons = *cp->rx_cons_ptr;
  2269. if ((hw_cons & BNX2X_MAX_RCQ_DESC_CNT) == BNX2X_MAX_RCQ_DESC_CNT)
  2270. hw_cons++;
  2271. sw_cons = cp->rx_cons;
  2272. while (sw_cons != hw_cons) {
  2273. u8 cqe_fp_flags;
  2274. cqe = &cqe_ring[sw_cons & BNX2X_MAX_RCQ_DESC_CNT];
  2275. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  2276. if (cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE) {
  2277. cmd = le32_to_cpu(cqe->ramrod_cqe.conn_and_cmd_data);
  2278. cmd >>= COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT;
  2279. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP ||
  2280. cmd == RAMROD_CMD_ID_ETH_HALT)
  2281. comp++;
  2282. }
  2283. sw_cons = BNX2X_NEXT_RCQE(sw_cons);
  2284. }
  2285. return comp;
  2286. }
  2287. static void cnic_chk_pkt_rings(struct cnic_local *cp)
  2288. {
  2289. u16 rx_cons, tx_cons;
  2290. int comp = 0;
  2291. if (!test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags))
  2292. return;
  2293. rx_cons = *cp->rx_cons_ptr;
  2294. tx_cons = *cp->tx_cons_ptr;
  2295. if (cp->tx_cons != tx_cons || cp->rx_cons != rx_cons) {
  2296. if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags))
  2297. comp = cnic_l2_completion(cp);
  2298. cp->tx_cons = tx_cons;
  2299. cp->rx_cons = rx_cons;
  2300. if (cp->udev)
  2301. uio_event_notify(&cp->udev->cnic_uinfo);
  2302. }
  2303. if (comp)
  2304. clear_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags);
  2305. }
  2306. static u32 cnic_service_bnx2_queues(struct cnic_dev *dev)
  2307. {
  2308. struct cnic_local *cp = dev->cnic_priv;
  2309. u32 status_idx = (u16) *cp->kcq1.status_idx_ptr;
  2310. int kcqe_cnt;
  2311. cp->kwq_con_idx = *cp->kwq_con_idx_ptr;
  2312. while ((kcqe_cnt = cnic_get_kcqes(dev, &cp->kcq1))) {
  2313. service_kcqes(dev, kcqe_cnt);
  2314. /* Tell compiler that status_blk fields can change. */
  2315. barrier();
  2316. if (status_idx != *cp->kcq1.status_idx_ptr) {
  2317. status_idx = (u16) *cp->kcq1.status_idx_ptr;
  2318. cp->kwq_con_idx = *cp->kwq_con_idx_ptr;
  2319. } else
  2320. break;
  2321. }
  2322. CNIC_WR16(dev, cp->kcq1.io_addr, cp->kcq1.sw_prod_idx);
  2323. cnic_chk_pkt_rings(cp);
  2324. return status_idx;
  2325. }
  2326. static int cnic_service_bnx2(void *data, void *status_blk)
  2327. {
  2328. struct cnic_dev *dev = data;
  2329. if (unlikely(!test_bit(CNIC_F_CNIC_UP, &dev->flags))) {
  2330. struct status_block *sblk = status_blk;
  2331. return sblk->status_idx;
  2332. }
  2333. return cnic_service_bnx2_queues(dev);
  2334. }
  2335. static void cnic_service_bnx2_msix(unsigned long data)
  2336. {
  2337. struct cnic_dev *dev = (struct cnic_dev *) data;
  2338. struct cnic_local *cp = dev->cnic_priv;
  2339. cp->last_status_idx = cnic_service_bnx2_queues(dev);
  2340. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  2341. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx);
  2342. }
  2343. static void cnic_doirq(struct cnic_dev *dev)
  2344. {
  2345. struct cnic_local *cp = dev->cnic_priv;
  2346. if (likely(test_bit(CNIC_F_CNIC_UP, &dev->flags))) {
  2347. u16 prod = cp->kcq1.sw_prod_idx & MAX_KCQ_IDX;
  2348. prefetch(cp->status_blk.gen);
  2349. prefetch(&cp->kcq1.kcq[KCQ_PG(prod)][KCQ_IDX(prod)]);
  2350. tasklet_schedule(&cp->cnic_irq_task);
  2351. }
  2352. }
  2353. static irqreturn_t cnic_irq(int irq, void *dev_instance)
  2354. {
  2355. struct cnic_dev *dev = dev_instance;
  2356. struct cnic_local *cp = dev->cnic_priv;
  2357. if (cp->ack_int)
  2358. cp->ack_int(dev);
  2359. cnic_doirq(dev);
  2360. return IRQ_HANDLED;
  2361. }
  2362. static inline void cnic_ack_bnx2x_int(struct cnic_dev *dev, u8 id, u8 storm,
  2363. u16 index, u8 op, u8 update)
  2364. {
  2365. struct cnic_local *cp = dev->cnic_priv;
  2366. u32 hc_addr = (HC_REG_COMMAND_REG + CNIC_PORT(cp) * 32 +
  2367. COMMAND_REG_INT_ACK);
  2368. struct igu_ack_register igu_ack;
  2369. igu_ack.status_block_index = index;
  2370. igu_ack.sb_id_and_flags =
  2371. ((id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
  2372. (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
  2373. (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
  2374. (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
  2375. CNIC_WR(dev, hc_addr, (*(u32 *)&igu_ack));
  2376. }
  2377. static void cnic_ack_igu_sb(struct cnic_dev *dev, u8 igu_sb_id, u8 segment,
  2378. u16 index, u8 op, u8 update)
  2379. {
  2380. struct igu_regular cmd_data;
  2381. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id) * 8;
  2382. cmd_data.sb_id_and_flags =
  2383. (index << IGU_REGULAR_SB_INDEX_SHIFT) |
  2384. (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
  2385. (update << IGU_REGULAR_BUPDATE_SHIFT) |
  2386. (op << IGU_REGULAR_ENABLE_INT_SHIFT);
  2387. CNIC_WR(dev, igu_addr, cmd_data.sb_id_and_flags);
  2388. }
  2389. static void cnic_ack_bnx2x_msix(struct cnic_dev *dev)
  2390. {
  2391. struct cnic_local *cp = dev->cnic_priv;
  2392. cnic_ack_bnx2x_int(dev, cp->bnx2x_igu_sb_id, CSTORM_ID, 0,
  2393. IGU_INT_DISABLE, 0);
  2394. }
  2395. static void cnic_ack_bnx2x_e2_msix(struct cnic_dev *dev)
  2396. {
  2397. struct cnic_local *cp = dev->cnic_priv;
  2398. cnic_ack_igu_sb(dev, cp->bnx2x_igu_sb_id, IGU_SEG_ACCESS_DEF, 0,
  2399. IGU_INT_DISABLE, 0);
  2400. }
  2401. static u32 cnic_service_bnx2x_kcq(struct cnic_dev *dev, struct kcq_info *info)
  2402. {
  2403. u32 last_status = *info->status_idx_ptr;
  2404. int kcqe_cnt;
  2405. while ((kcqe_cnt = cnic_get_kcqes(dev, info))) {
  2406. service_kcqes(dev, kcqe_cnt);
  2407. /* Tell compiler that sblk fields can change. */
  2408. barrier();
  2409. if (last_status == *info->status_idx_ptr)
  2410. break;
  2411. last_status = *info->status_idx_ptr;
  2412. }
  2413. return last_status;
  2414. }
  2415. static void cnic_service_bnx2x_bh(unsigned long data)
  2416. {
  2417. struct cnic_dev *dev = (struct cnic_dev *) data;
  2418. struct cnic_local *cp = dev->cnic_priv;
  2419. u32 status_idx;
  2420. if (unlikely(!test_bit(CNIC_F_CNIC_UP, &dev->flags)))
  2421. return;
  2422. status_idx = cnic_service_bnx2x_kcq(dev, &cp->kcq1);
  2423. CNIC_WR16(dev, cp->kcq1.io_addr, cp->kcq1.sw_prod_idx + MAX_KCQ_IDX);
  2424. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  2425. status_idx = cnic_service_bnx2x_kcq(dev, &cp->kcq2);
  2426. CNIC_WR16(dev, cp->kcq2.io_addr, cp->kcq2.sw_prod_idx +
  2427. MAX_KCQ_IDX);
  2428. cnic_ack_igu_sb(dev, cp->bnx2x_igu_sb_id, IGU_SEG_ACCESS_DEF,
  2429. status_idx, IGU_INT_ENABLE, 1);
  2430. } else {
  2431. cnic_ack_bnx2x_int(dev, cp->bnx2x_igu_sb_id, USTORM_ID,
  2432. status_idx, IGU_INT_ENABLE, 1);
  2433. }
  2434. }
  2435. static int cnic_service_bnx2x(void *data, void *status_blk)
  2436. {
  2437. struct cnic_dev *dev = data;
  2438. struct cnic_local *cp = dev->cnic_priv;
  2439. if (!(cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX))
  2440. cnic_doirq(dev);
  2441. cnic_chk_pkt_rings(cp);
  2442. return 0;
  2443. }
  2444. static void cnic_ulp_stop(struct cnic_dev *dev)
  2445. {
  2446. struct cnic_local *cp = dev->cnic_priv;
  2447. int if_type;
  2448. cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
  2449. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  2450. struct cnic_ulp_ops *ulp_ops;
  2451. mutex_lock(&cnic_lock);
  2452. ulp_ops = cp->ulp_ops[if_type];
  2453. if (!ulp_ops) {
  2454. mutex_unlock(&cnic_lock);
  2455. continue;
  2456. }
  2457. set_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
  2458. mutex_unlock(&cnic_lock);
  2459. if (test_and_clear_bit(ULP_F_START, &cp->ulp_flags[if_type]))
  2460. ulp_ops->cnic_stop(cp->ulp_handle[if_type]);
  2461. clear_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
  2462. }
  2463. }
  2464. static void cnic_ulp_start(struct cnic_dev *dev)
  2465. {
  2466. struct cnic_local *cp = dev->cnic_priv;
  2467. int if_type;
  2468. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  2469. struct cnic_ulp_ops *ulp_ops;
  2470. mutex_lock(&cnic_lock);
  2471. ulp_ops = cp->ulp_ops[if_type];
  2472. if (!ulp_ops || !ulp_ops->cnic_start) {
  2473. mutex_unlock(&cnic_lock);
  2474. continue;
  2475. }
  2476. set_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
  2477. mutex_unlock(&cnic_lock);
  2478. if (!test_and_set_bit(ULP_F_START, &cp->ulp_flags[if_type]))
  2479. ulp_ops->cnic_start(cp->ulp_handle[if_type]);
  2480. clear_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
  2481. }
  2482. }
  2483. static int cnic_ctl(void *data, struct cnic_ctl_info *info)
  2484. {
  2485. struct cnic_dev *dev = data;
  2486. switch (info->cmd) {
  2487. case CNIC_CTL_STOP_CMD:
  2488. cnic_hold(dev);
  2489. cnic_ulp_stop(dev);
  2490. cnic_stop_hw(dev);
  2491. cnic_put(dev);
  2492. break;
  2493. case CNIC_CTL_START_CMD:
  2494. cnic_hold(dev);
  2495. if (!cnic_start_hw(dev))
  2496. cnic_ulp_start(dev);
  2497. cnic_put(dev);
  2498. break;
  2499. case CNIC_CTL_COMPLETION_CMD: {
  2500. u32 cid = BNX2X_SW_CID(info->data.comp.cid);
  2501. u32 l5_cid;
  2502. struct cnic_local *cp = dev->cnic_priv;
  2503. if (cnic_get_l5_cid(cp, cid, &l5_cid) == 0) {
  2504. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  2505. ctx->wait_cond = 1;
  2506. wake_up(&ctx->waitq);
  2507. }
  2508. break;
  2509. }
  2510. default:
  2511. return -EINVAL;
  2512. }
  2513. return 0;
  2514. }
  2515. static void cnic_ulp_init(struct cnic_dev *dev)
  2516. {
  2517. int i;
  2518. struct cnic_local *cp = dev->cnic_priv;
  2519. for (i = 0; i < MAX_CNIC_ULP_TYPE_EXT; i++) {
  2520. struct cnic_ulp_ops *ulp_ops;
  2521. mutex_lock(&cnic_lock);
  2522. ulp_ops = cnic_ulp_tbl[i];
  2523. if (!ulp_ops || !ulp_ops->cnic_init) {
  2524. mutex_unlock(&cnic_lock);
  2525. continue;
  2526. }
  2527. ulp_get(ulp_ops);
  2528. mutex_unlock(&cnic_lock);
  2529. if (!test_and_set_bit(ULP_F_INIT, &cp->ulp_flags[i]))
  2530. ulp_ops->cnic_init(dev);
  2531. ulp_put(ulp_ops);
  2532. }
  2533. }
  2534. static void cnic_ulp_exit(struct cnic_dev *dev)
  2535. {
  2536. int i;
  2537. struct cnic_local *cp = dev->cnic_priv;
  2538. for (i = 0; i < MAX_CNIC_ULP_TYPE_EXT; i++) {
  2539. struct cnic_ulp_ops *ulp_ops;
  2540. mutex_lock(&cnic_lock);
  2541. ulp_ops = cnic_ulp_tbl[i];
  2542. if (!ulp_ops || !ulp_ops->cnic_exit) {
  2543. mutex_unlock(&cnic_lock);
  2544. continue;
  2545. }
  2546. ulp_get(ulp_ops);
  2547. mutex_unlock(&cnic_lock);
  2548. if (test_and_clear_bit(ULP_F_INIT, &cp->ulp_flags[i]))
  2549. ulp_ops->cnic_exit(dev);
  2550. ulp_put(ulp_ops);
  2551. }
  2552. }
  2553. static int cnic_cm_offload_pg(struct cnic_sock *csk)
  2554. {
  2555. struct cnic_dev *dev = csk->dev;
  2556. struct l4_kwq_offload_pg *l4kwqe;
  2557. struct kwqe *wqes[1];
  2558. l4kwqe = (struct l4_kwq_offload_pg *) &csk->kwqe1;
  2559. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2560. wqes[0] = (struct kwqe *) l4kwqe;
  2561. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_OFFLOAD_PG;
  2562. l4kwqe->flags =
  2563. L4_LAYER_CODE << L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT;
  2564. l4kwqe->l2hdr_nbytes = ETH_HLEN;
  2565. l4kwqe->da0 = csk->ha[0];
  2566. l4kwqe->da1 = csk->ha[1];
  2567. l4kwqe->da2 = csk->ha[2];
  2568. l4kwqe->da3 = csk->ha[3];
  2569. l4kwqe->da4 = csk->ha[4];
  2570. l4kwqe->da5 = csk->ha[5];
  2571. l4kwqe->sa0 = dev->mac_addr[0];
  2572. l4kwqe->sa1 = dev->mac_addr[1];
  2573. l4kwqe->sa2 = dev->mac_addr[2];
  2574. l4kwqe->sa3 = dev->mac_addr[3];
  2575. l4kwqe->sa4 = dev->mac_addr[4];
  2576. l4kwqe->sa5 = dev->mac_addr[5];
  2577. l4kwqe->etype = ETH_P_IP;
  2578. l4kwqe->ipid_start = DEF_IPID_START;
  2579. l4kwqe->host_opaque = csk->l5_cid;
  2580. if (csk->vlan_id) {
  2581. l4kwqe->pg_flags |= L4_KWQ_OFFLOAD_PG_VLAN_TAGGING;
  2582. l4kwqe->vlan_tag = csk->vlan_id;
  2583. l4kwqe->l2hdr_nbytes += 4;
  2584. }
  2585. return dev->submit_kwqes(dev, wqes, 1);
  2586. }
  2587. static int cnic_cm_update_pg(struct cnic_sock *csk)
  2588. {
  2589. struct cnic_dev *dev = csk->dev;
  2590. struct l4_kwq_update_pg *l4kwqe;
  2591. struct kwqe *wqes[1];
  2592. l4kwqe = (struct l4_kwq_update_pg *) &csk->kwqe1;
  2593. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2594. wqes[0] = (struct kwqe *) l4kwqe;
  2595. l4kwqe->opcode = L4_KWQE_OPCODE_VALUE_UPDATE_PG;
  2596. l4kwqe->flags =
  2597. L4_LAYER_CODE << L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT;
  2598. l4kwqe->pg_cid = csk->pg_cid;
  2599. l4kwqe->da0 = csk->ha[0];
  2600. l4kwqe->da1 = csk->ha[1];
  2601. l4kwqe->da2 = csk->ha[2];
  2602. l4kwqe->da3 = csk->ha[3];
  2603. l4kwqe->da4 = csk->ha[4];
  2604. l4kwqe->da5 = csk->ha[5];
  2605. l4kwqe->pg_host_opaque = csk->l5_cid;
  2606. l4kwqe->pg_valids = L4_KWQ_UPDATE_PG_VALIDS_DA;
  2607. return dev->submit_kwqes(dev, wqes, 1);
  2608. }
  2609. static int cnic_cm_upload_pg(struct cnic_sock *csk)
  2610. {
  2611. struct cnic_dev *dev = csk->dev;
  2612. struct l4_kwq_upload *l4kwqe;
  2613. struct kwqe *wqes[1];
  2614. l4kwqe = (struct l4_kwq_upload *) &csk->kwqe1;
  2615. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2616. wqes[0] = (struct kwqe *) l4kwqe;
  2617. l4kwqe->opcode = L4_KWQE_OPCODE_VALUE_UPLOAD_PG;
  2618. l4kwqe->flags =
  2619. L4_LAYER_CODE << L4_KWQ_UPLOAD_LAYER_CODE_SHIFT;
  2620. l4kwqe->cid = csk->pg_cid;
  2621. return dev->submit_kwqes(dev, wqes, 1);
  2622. }
  2623. static int cnic_cm_conn_req(struct cnic_sock *csk)
  2624. {
  2625. struct cnic_dev *dev = csk->dev;
  2626. struct l4_kwq_connect_req1 *l4kwqe1;
  2627. struct l4_kwq_connect_req2 *l4kwqe2;
  2628. struct l4_kwq_connect_req3 *l4kwqe3;
  2629. struct kwqe *wqes[3];
  2630. u8 tcp_flags = 0;
  2631. int num_wqes = 2;
  2632. l4kwqe1 = (struct l4_kwq_connect_req1 *) &csk->kwqe1;
  2633. l4kwqe2 = (struct l4_kwq_connect_req2 *) &csk->kwqe2;
  2634. l4kwqe3 = (struct l4_kwq_connect_req3 *) &csk->kwqe3;
  2635. memset(l4kwqe1, 0, sizeof(*l4kwqe1));
  2636. memset(l4kwqe2, 0, sizeof(*l4kwqe2));
  2637. memset(l4kwqe3, 0, sizeof(*l4kwqe3));
  2638. l4kwqe3->op_code = L4_KWQE_OPCODE_VALUE_CONNECT3;
  2639. l4kwqe3->flags =
  2640. L4_LAYER_CODE << L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT;
  2641. l4kwqe3->ka_timeout = csk->ka_timeout;
  2642. l4kwqe3->ka_interval = csk->ka_interval;
  2643. l4kwqe3->ka_max_probe_count = csk->ka_max_probe_count;
  2644. l4kwqe3->tos = csk->tos;
  2645. l4kwqe3->ttl = csk->ttl;
  2646. l4kwqe3->snd_seq_scale = csk->snd_seq_scale;
  2647. l4kwqe3->pmtu = csk->mtu;
  2648. l4kwqe3->rcv_buf = csk->rcv_buf;
  2649. l4kwqe3->snd_buf = csk->snd_buf;
  2650. l4kwqe3->seed = csk->seed;
  2651. wqes[0] = (struct kwqe *) l4kwqe1;
  2652. if (test_bit(SK_F_IPV6, &csk->flags)) {
  2653. wqes[1] = (struct kwqe *) l4kwqe2;
  2654. wqes[2] = (struct kwqe *) l4kwqe3;
  2655. num_wqes = 3;
  2656. l4kwqe1->conn_flags = L4_KWQ_CONNECT_REQ1_IP_V6;
  2657. l4kwqe2->op_code = L4_KWQE_OPCODE_VALUE_CONNECT2;
  2658. l4kwqe2->flags =
  2659. L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT |
  2660. L4_LAYER_CODE << L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT;
  2661. l4kwqe2->src_ip_v6_2 = be32_to_cpu(csk->src_ip[1]);
  2662. l4kwqe2->src_ip_v6_3 = be32_to_cpu(csk->src_ip[2]);
  2663. l4kwqe2->src_ip_v6_4 = be32_to_cpu(csk->src_ip[3]);
  2664. l4kwqe2->dst_ip_v6_2 = be32_to_cpu(csk->dst_ip[1]);
  2665. l4kwqe2->dst_ip_v6_3 = be32_to_cpu(csk->dst_ip[2]);
  2666. l4kwqe2->dst_ip_v6_4 = be32_to_cpu(csk->dst_ip[3]);
  2667. l4kwqe3->mss = l4kwqe3->pmtu - sizeof(struct ipv6hdr) -
  2668. sizeof(struct tcphdr);
  2669. } else {
  2670. wqes[1] = (struct kwqe *) l4kwqe3;
  2671. l4kwqe3->mss = l4kwqe3->pmtu - sizeof(struct iphdr) -
  2672. sizeof(struct tcphdr);
  2673. }
  2674. l4kwqe1->op_code = L4_KWQE_OPCODE_VALUE_CONNECT1;
  2675. l4kwqe1->flags =
  2676. (L4_LAYER_CODE << L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT) |
  2677. L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT;
  2678. l4kwqe1->cid = csk->cid;
  2679. l4kwqe1->pg_cid = csk->pg_cid;
  2680. l4kwqe1->src_ip = be32_to_cpu(csk->src_ip[0]);
  2681. l4kwqe1->dst_ip = be32_to_cpu(csk->dst_ip[0]);
  2682. l4kwqe1->src_port = be16_to_cpu(csk->src_port);
  2683. l4kwqe1->dst_port = be16_to_cpu(csk->dst_port);
  2684. if (csk->tcp_flags & SK_TCP_NO_DELAY_ACK)
  2685. tcp_flags |= L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK;
  2686. if (csk->tcp_flags & SK_TCP_KEEP_ALIVE)
  2687. tcp_flags |= L4_KWQ_CONNECT_REQ1_KEEP_ALIVE;
  2688. if (csk->tcp_flags & SK_TCP_NAGLE)
  2689. tcp_flags |= L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE;
  2690. if (csk->tcp_flags & SK_TCP_TIMESTAMP)
  2691. tcp_flags |= L4_KWQ_CONNECT_REQ1_TIME_STAMP;
  2692. if (csk->tcp_flags & SK_TCP_SACK)
  2693. tcp_flags |= L4_KWQ_CONNECT_REQ1_SACK;
  2694. if (csk->tcp_flags & SK_TCP_SEG_SCALING)
  2695. tcp_flags |= L4_KWQ_CONNECT_REQ1_SEG_SCALING;
  2696. l4kwqe1->tcp_flags = tcp_flags;
  2697. return dev->submit_kwqes(dev, wqes, num_wqes);
  2698. }
  2699. static int cnic_cm_close_req(struct cnic_sock *csk)
  2700. {
  2701. struct cnic_dev *dev = csk->dev;
  2702. struct l4_kwq_close_req *l4kwqe;
  2703. struct kwqe *wqes[1];
  2704. l4kwqe = (struct l4_kwq_close_req *) &csk->kwqe2;
  2705. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2706. wqes[0] = (struct kwqe *) l4kwqe;
  2707. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_CLOSE;
  2708. l4kwqe->flags = L4_LAYER_CODE << L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT;
  2709. l4kwqe->cid = csk->cid;
  2710. return dev->submit_kwqes(dev, wqes, 1);
  2711. }
  2712. static int cnic_cm_abort_req(struct cnic_sock *csk)
  2713. {
  2714. struct cnic_dev *dev = csk->dev;
  2715. struct l4_kwq_reset_req *l4kwqe;
  2716. struct kwqe *wqes[1];
  2717. l4kwqe = (struct l4_kwq_reset_req *) &csk->kwqe2;
  2718. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2719. wqes[0] = (struct kwqe *) l4kwqe;
  2720. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_RESET;
  2721. l4kwqe->flags = L4_LAYER_CODE << L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT;
  2722. l4kwqe->cid = csk->cid;
  2723. return dev->submit_kwqes(dev, wqes, 1);
  2724. }
  2725. static int cnic_cm_create(struct cnic_dev *dev, int ulp_type, u32 cid,
  2726. u32 l5_cid, struct cnic_sock **csk, void *context)
  2727. {
  2728. struct cnic_local *cp = dev->cnic_priv;
  2729. struct cnic_sock *csk1;
  2730. if (l5_cid >= MAX_CM_SK_TBL_SZ)
  2731. return -EINVAL;
  2732. if (cp->ctx_tbl) {
  2733. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  2734. if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags))
  2735. return -EAGAIN;
  2736. }
  2737. csk1 = &cp->csk_tbl[l5_cid];
  2738. if (atomic_read(&csk1->ref_count))
  2739. return -EAGAIN;
  2740. if (test_and_set_bit(SK_F_INUSE, &csk1->flags))
  2741. return -EBUSY;
  2742. csk1->dev = dev;
  2743. csk1->cid = cid;
  2744. csk1->l5_cid = l5_cid;
  2745. csk1->ulp_type = ulp_type;
  2746. csk1->context = context;
  2747. csk1->ka_timeout = DEF_KA_TIMEOUT;
  2748. csk1->ka_interval = DEF_KA_INTERVAL;
  2749. csk1->ka_max_probe_count = DEF_KA_MAX_PROBE_COUNT;
  2750. csk1->tos = DEF_TOS;
  2751. csk1->ttl = DEF_TTL;
  2752. csk1->snd_seq_scale = DEF_SND_SEQ_SCALE;
  2753. csk1->rcv_buf = DEF_RCV_BUF;
  2754. csk1->snd_buf = DEF_SND_BUF;
  2755. csk1->seed = DEF_SEED;
  2756. *csk = csk1;
  2757. return 0;
  2758. }
  2759. static void cnic_cm_cleanup(struct cnic_sock *csk)
  2760. {
  2761. if (csk->src_port) {
  2762. struct cnic_dev *dev = csk->dev;
  2763. struct cnic_local *cp = dev->cnic_priv;
  2764. cnic_free_id(&cp->csk_port_tbl, be16_to_cpu(csk->src_port));
  2765. csk->src_port = 0;
  2766. }
  2767. }
  2768. static void cnic_close_conn(struct cnic_sock *csk)
  2769. {
  2770. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags)) {
  2771. cnic_cm_upload_pg(csk);
  2772. clear_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags);
  2773. }
  2774. cnic_cm_cleanup(csk);
  2775. }
  2776. static int cnic_cm_destroy(struct cnic_sock *csk)
  2777. {
  2778. if (!cnic_in_use(csk))
  2779. return -EINVAL;
  2780. csk_hold(csk);
  2781. clear_bit(SK_F_INUSE, &csk->flags);
  2782. smp_mb__after_clear_bit();
  2783. while (atomic_read(&csk->ref_count) != 1)
  2784. msleep(1);
  2785. cnic_cm_cleanup(csk);
  2786. csk->flags = 0;
  2787. csk_put(csk);
  2788. return 0;
  2789. }
  2790. static inline u16 cnic_get_vlan(struct net_device *dev,
  2791. struct net_device **vlan_dev)
  2792. {
  2793. if (dev->priv_flags & IFF_802_1Q_VLAN) {
  2794. *vlan_dev = vlan_dev_real_dev(dev);
  2795. return vlan_dev_vlan_id(dev);
  2796. }
  2797. *vlan_dev = dev;
  2798. return 0;
  2799. }
  2800. static int cnic_get_v4_route(struct sockaddr_in *dst_addr,
  2801. struct dst_entry **dst)
  2802. {
  2803. #if defined(CONFIG_INET)
  2804. struct flowi fl;
  2805. int err;
  2806. struct rtable *rt;
  2807. memset(&fl, 0, sizeof(fl));
  2808. fl.nl_u.ip4_u.daddr = dst_addr->sin_addr.s_addr;
  2809. err = ip_route_output_key(&init_net, &rt, &fl);
  2810. if (!err)
  2811. *dst = &rt->dst;
  2812. return err;
  2813. #else
  2814. return -ENETUNREACH;
  2815. #endif
  2816. }
  2817. static int cnic_get_v6_route(struct sockaddr_in6 *dst_addr,
  2818. struct dst_entry **dst)
  2819. {
  2820. #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
  2821. struct flowi fl;
  2822. memset(&fl, 0, sizeof(fl));
  2823. ipv6_addr_copy(&fl.fl6_dst, &dst_addr->sin6_addr);
  2824. if (ipv6_addr_type(&fl.fl6_dst) & IPV6_ADDR_LINKLOCAL)
  2825. fl.oif = dst_addr->sin6_scope_id;
  2826. *dst = ip6_route_output(&init_net, NULL, &fl);
  2827. if (*dst)
  2828. return 0;
  2829. #endif
  2830. return -ENETUNREACH;
  2831. }
  2832. static struct cnic_dev *cnic_cm_select_dev(struct sockaddr_in *dst_addr,
  2833. int ulp_type)
  2834. {
  2835. struct cnic_dev *dev = NULL;
  2836. struct dst_entry *dst;
  2837. struct net_device *netdev = NULL;
  2838. int err = -ENETUNREACH;
  2839. if (dst_addr->sin_family == AF_INET)
  2840. err = cnic_get_v4_route(dst_addr, &dst);
  2841. else if (dst_addr->sin_family == AF_INET6) {
  2842. struct sockaddr_in6 *dst_addr6 =
  2843. (struct sockaddr_in6 *) dst_addr;
  2844. err = cnic_get_v6_route(dst_addr6, &dst);
  2845. } else
  2846. return NULL;
  2847. if (err)
  2848. return NULL;
  2849. if (!dst->dev)
  2850. goto done;
  2851. cnic_get_vlan(dst->dev, &netdev);
  2852. dev = cnic_from_netdev(netdev);
  2853. done:
  2854. dst_release(dst);
  2855. if (dev)
  2856. cnic_put(dev);
  2857. return dev;
  2858. }
  2859. static int cnic_resolve_addr(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  2860. {
  2861. struct cnic_dev *dev = csk->dev;
  2862. struct cnic_local *cp = dev->cnic_priv;
  2863. return cnic_send_nlmsg(cp, ISCSI_KEVENT_PATH_REQ, csk);
  2864. }
  2865. static int cnic_get_route(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  2866. {
  2867. struct cnic_dev *dev = csk->dev;
  2868. struct cnic_local *cp = dev->cnic_priv;
  2869. int is_v6, rc = 0;
  2870. struct dst_entry *dst = NULL;
  2871. struct net_device *realdev;
  2872. __be16 local_port;
  2873. u32 port_id;
  2874. if (saddr->local.v6.sin6_family == AF_INET6 &&
  2875. saddr->remote.v6.sin6_family == AF_INET6)
  2876. is_v6 = 1;
  2877. else if (saddr->local.v4.sin_family == AF_INET &&
  2878. saddr->remote.v4.sin_family == AF_INET)
  2879. is_v6 = 0;
  2880. else
  2881. return -EINVAL;
  2882. clear_bit(SK_F_IPV6, &csk->flags);
  2883. if (is_v6) {
  2884. set_bit(SK_F_IPV6, &csk->flags);
  2885. cnic_get_v6_route(&saddr->remote.v6, &dst);
  2886. memcpy(&csk->dst_ip[0], &saddr->remote.v6.sin6_addr,
  2887. sizeof(struct in6_addr));
  2888. csk->dst_port = saddr->remote.v6.sin6_port;
  2889. local_port = saddr->local.v6.sin6_port;
  2890. } else {
  2891. cnic_get_v4_route(&saddr->remote.v4, &dst);
  2892. csk->dst_ip[0] = saddr->remote.v4.sin_addr.s_addr;
  2893. csk->dst_port = saddr->remote.v4.sin_port;
  2894. local_port = saddr->local.v4.sin_port;
  2895. }
  2896. csk->vlan_id = 0;
  2897. csk->mtu = dev->netdev->mtu;
  2898. if (dst && dst->dev) {
  2899. u16 vlan = cnic_get_vlan(dst->dev, &realdev);
  2900. if (realdev == dev->netdev) {
  2901. csk->vlan_id = vlan;
  2902. csk->mtu = dst_mtu(dst);
  2903. }
  2904. }
  2905. port_id = be16_to_cpu(local_port);
  2906. if (port_id >= CNIC_LOCAL_PORT_MIN &&
  2907. port_id < CNIC_LOCAL_PORT_MAX) {
  2908. if (cnic_alloc_id(&cp->csk_port_tbl, port_id))
  2909. port_id = 0;
  2910. } else
  2911. port_id = 0;
  2912. if (!port_id) {
  2913. port_id = cnic_alloc_new_id(&cp->csk_port_tbl);
  2914. if (port_id == -1) {
  2915. rc = -ENOMEM;
  2916. goto err_out;
  2917. }
  2918. local_port = cpu_to_be16(port_id);
  2919. }
  2920. csk->src_port = local_port;
  2921. err_out:
  2922. dst_release(dst);
  2923. return rc;
  2924. }
  2925. static void cnic_init_csk_state(struct cnic_sock *csk)
  2926. {
  2927. csk->state = 0;
  2928. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  2929. clear_bit(SK_F_CLOSING, &csk->flags);
  2930. }
  2931. static int cnic_cm_connect(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  2932. {
  2933. int err = 0;
  2934. if (!cnic_in_use(csk))
  2935. return -EINVAL;
  2936. if (test_and_set_bit(SK_F_CONNECT_START, &csk->flags))
  2937. return -EINVAL;
  2938. cnic_init_csk_state(csk);
  2939. err = cnic_get_route(csk, saddr);
  2940. if (err)
  2941. goto err_out;
  2942. err = cnic_resolve_addr(csk, saddr);
  2943. if (!err)
  2944. return 0;
  2945. err_out:
  2946. clear_bit(SK_F_CONNECT_START, &csk->flags);
  2947. return err;
  2948. }
  2949. static int cnic_cm_abort(struct cnic_sock *csk)
  2950. {
  2951. struct cnic_local *cp = csk->dev->cnic_priv;
  2952. u32 opcode = L4_KCQE_OPCODE_VALUE_RESET_COMP;
  2953. if (!cnic_in_use(csk))
  2954. return -EINVAL;
  2955. if (cnic_abort_prep(csk))
  2956. return cnic_cm_abort_req(csk);
  2957. /* Getting here means that we haven't started connect, or
  2958. * connect was not successful.
  2959. */
  2960. cp->close_conn(csk, opcode);
  2961. if (csk->state != opcode)
  2962. return -EALREADY;
  2963. return 0;
  2964. }
  2965. static int cnic_cm_close(struct cnic_sock *csk)
  2966. {
  2967. if (!cnic_in_use(csk))
  2968. return -EINVAL;
  2969. if (cnic_close_prep(csk)) {
  2970. csk->state = L4_KCQE_OPCODE_VALUE_CLOSE_COMP;
  2971. return cnic_cm_close_req(csk);
  2972. } else {
  2973. return -EALREADY;
  2974. }
  2975. return 0;
  2976. }
  2977. static void cnic_cm_upcall(struct cnic_local *cp, struct cnic_sock *csk,
  2978. u8 opcode)
  2979. {
  2980. struct cnic_ulp_ops *ulp_ops;
  2981. int ulp_type = csk->ulp_type;
  2982. rcu_read_lock();
  2983. ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
  2984. if (ulp_ops) {
  2985. if (opcode == L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE)
  2986. ulp_ops->cm_connect_complete(csk);
  2987. else if (opcode == L4_KCQE_OPCODE_VALUE_CLOSE_COMP)
  2988. ulp_ops->cm_close_complete(csk);
  2989. else if (opcode == L4_KCQE_OPCODE_VALUE_RESET_RECEIVED)
  2990. ulp_ops->cm_remote_abort(csk);
  2991. else if (opcode == L4_KCQE_OPCODE_VALUE_RESET_COMP)
  2992. ulp_ops->cm_abort_complete(csk);
  2993. else if (opcode == L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED)
  2994. ulp_ops->cm_remote_close(csk);
  2995. }
  2996. rcu_read_unlock();
  2997. }
  2998. static int cnic_cm_set_pg(struct cnic_sock *csk)
  2999. {
  3000. if (cnic_offld_prep(csk)) {
  3001. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags))
  3002. cnic_cm_update_pg(csk);
  3003. else
  3004. cnic_cm_offload_pg(csk);
  3005. }
  3006. return 0;
  3007. }
  3008. static void cnic_cm_process_offld_pg(struct cnic_dev *dev, struct l4_kcq *kcqe)
  3009. {
  3010. struct cnic_local *cp = dev->cnic_priv;
  3011. u32 l5_cid = kcqe->pg_host_opaque;
  3012. u8 opcode = kcqe->op_code;
  3013. struct cnic_sock *csk = &cp->csk_tbl[l5_cid];
  3014. csk_hold(csk);
  3015. if (!cnic_in_use(csk))
  3016. goto done;
  3017. if (opcode == L4_KCQE_OPCODE_VALUE_UPDATE_PG) {
  3018. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  3019. goto done;
  3020. }
  3021. /* Possible PG kcqe status: SUCCESS, OFFLOADED_PG, or CTX_ALLOC_FAIL */
  3022. if (kcqe->status == L4_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAIL) {
  3023. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  3024. cnic_cm_upcall(cp, csk,
  3025. L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE);
  3026. goto done;
  3027. }
  3028. csk->pg_cid = kcqe->pg_cid;
  3029. set_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags);
  3030. cnic_cm_conn_req(csk);
  3031. done:
  3032. csk_put(csk);
  3033. }
  3034. static void cnic_process_fcoe_term_conn(struct cnic_dev *dev, struct kcqe *kcqe)
  3035. {
  3036. struct cnic_local *cp = dev->cnic_priv;
  3037. struct fcoe_kcqe *fc_kcqe = (struct fcoe_kcqe *) kcqe;
  3038. u32 l5_cid = fc_kcqe->fcoe_conn_id + BNX2X_FCOE_L5_CID_BASE;
  3039. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  3040. ctx->timestamp = jiffies;
  3041. ctx->wait_cond = 1;
  3042. wake_up(&ctx->waitq);
  3043. }
  3044. static void cnic_cm_process_kcqe(struct cnic_dev *dev, struct kcqe *kcqe)
  3045. {
  3046. struct cnic_local *cp = dev->cnic_priv;
  3047. struct l4_kcq *l4kcqe = (struct l4_kcq *) kcqe;
  3048. u8 opcode = l4kcqe->op_code;
  3049. u32 l5_cid;
  3050. struct cnic_sock *csk;
  3051. if (opcode == FCOE_RAMROD_CMD_ID_TERMINATE_CONN) {
  3052. cnic_process_fcoe_term_conn(dev, kcqe);
  3053. return;
  3054. }
  3055. if (opcode == L4_KCQE_OPCODE_VALUE_OFFLOAD_PG ||
  3056. opcode == L4_KCQE_OPCODE_VALUE_UPDATE_PG) {
  3057. cnic_cm_process_offld_pg(dev, l4kcqe);
  3058. return;
  3059. }
  3060. l5_cid = l4kcqe->conn_id;
  3061. if (opcode & 0x80)
  3062. l5_cid = l4kcqe->cid;
  3063. if (l5_cid >= MAX_CM_SK_TBL_SZ)
  3064. return;
  3065. csk = &cp->csk_tbl[l5_cid];
  3066. csk_hold(csk);
  3067. if (!cnic_in_use(csk)) {
  3068. csk_put(csk);
  3069. return;
  3070. }
  3071. switch (opcode) {
  3072. case L5CM_RAMROD_CMD_ID_TCP_CONNECT:
  3073. if (l4kcqe->status != 0) {
  3074. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  3075. cnic_cm_upcall(cp, csk,
  3076. L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE);
  3077. }
  3078. break;
  3079. case L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE:
  3080. if (l4kcqe->status == 0)
  3081. set_bit(SK_F_OFFLD_COMPLETE, &csk->flags);
  3082. smp_mb__before_clear_bit();
  3083. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  3084. cnic_cm_upcall(cp, csk, opcode);
  3085. break;
  3086. case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED:
  3087. case L4_KCQE_OPCODE_VALUE_CLOSE_COMP:
  3088. case L4_KCQE_OPCODE_VALUE_RESET_COMP:
  3089. case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE:
  3090. case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD:
  3091. cp->close_conn(csk, opcode);
  3092. break;
  3093. case L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED:
  3094. cnic_cm_upcall(cp, csk, opcode);
  3095. break;
  3096. }
  3097. csk_put(csk);
  3098. }
  3099. static void cnic_cm_indicate_kcqe(void *data, struct kcqe *kcqe[], u32 num)
  3100. {
  3101. struct cnic_dev *dev = data;
  3102. int i;
  3103. for (i = 0; i < num; i++)
  3104. cnic_cm_process_kcqe(dev, kcqe[i]);
  3105. }
  3106. static struct cnic_ulp_ops cm_ulp_ops = {
  3107. .indicate_kcqes = cnic_cm_indicate_kcqe,
  3108. };
  3109. static void cnic_cm_free_mem(struct cnic_dev *dev)
  3110. {
  3111. struct cnic_local *cp = dev->cnic_priv;
  3112. kfree(cp->csk_tbl);
  3113. cp->csk_tbl = NULL;
  3114. cnic_free_id_tbl(&cp->csk_port_tbl);
  3115. }
  3116. static int cnic_cm_alloc_mem(struct cnic_dev *dev)
  3117. {
  3118. struct cnic_local *cp = dev->cnic_priv;
  3119. cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ,
  3120. GFP_KERNEL);
  3121. if (!cp->csk_tbl)
  3122. return -ENOMEM;
  3123. if (cnic_init_id_tbl(&cp->csk_port_tbl, CNIC_LOCAL_PORT_RANGE,
  3124. CNIC_LOCAL_PORT_MIN)) {
  3125. cnic_cm_free_mem(dev);
  3126. return -ENOMEM;
  3127. }
  3128. return 0;
  3129. }
  3130. static int cnic_ready_to_close(struct cnic_sock *csk, u32 opcode)
  3131. {
  3132. if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) {
  3133. /* Unsolicited RESET_COMP or RESET_RECEIVED */
  3134. opcode = L4_KCQE_OPCODE_VALUE_RESET_RECEIVED;
  3135. csk->state = opcode;
  3136. }
  3137. /* 1. If event opcode matches the expected event in csk->state
  3138. * 2. If the expected event is CLOSE_COMP, we accept any event
  3139. * 3. If the expected event is 0, meaning the connection was never
  3140. * never established, we accept the opcode from cm_abort.
  3141. */
  3142. if (opcode == csk->state || csk->state == 0 ||
  3143. csk->state == L4_KCQE_OPCODE_VALUE_CLOSE_COMP) {
  3144. if (!test_and_set_bit(SK_F_CLOSING, &csk->flags)) {
  3145. if (csk->state == 0)
  3146. csk->state = opcode;
  3147. return 1;
  3148. }
  3149. }
  3150. return 0;
  3151. }
  3152. static void cnic_close_bnx2_conn(struct cnic_sock *csk, u32 opcode)
  3153. {
  3154. struct cnic_dev *dev = csk->dev;
  3155. struct cnic_local *cp = dev->cnic_priv;
  3156. if (opcode == L4_KCQE_OPCODE_VALUE_RESET_RECEIVED) {
  3157. cnic_cm_upcall(cp, csk, opcode);
  3158. return;
  3159. }
  3160. clear_bit(SK_F_CONNECT_START, &csk->flags);
  3161. cnic_close_conn(csk);
  3162. csk->state = opcode;
  3163. cnic_cm_upcall(cp, csk, opcode);
  3164. }
  3165. static void cnic_cm_stop_bnx2_hw(struct cnic_dev *dev)
  3166. {
  3167. }
  3168. static int cnic_cm_init_bnx2_hw(struct cnic_dev *dev)
  3169. {
  3170. u32 seed;
  3171. get_random_bytes(&seed, 4);
  3172. cnic_ctx_wr(dev, 45, 0, seed);
  3173. return 0;
  3174. }
  3175. static void cnic_close_bnx2x_conn(struct cnic_sock *csk, u32 opcode)
  3176. {
  3177. struct cnic_dev *dev = csk->dev;
  3178. struct cnic_local *cp = dev->cnic_priv;
  3179. struct cnic_context *ctx = &cp->ctx_tbl[csk->l5_cid];
  3180. union l5cm_specific_data l5_data;
  3181. u32 cmd = 0;
  3182. int close_complete = 0;
  3183. switch (opcode) {
  3184. case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED:
  3185. case L4_KCQE_OPCODE_VALUE_CLOSE_COMP:
  3186. case L4_KCQE_OPCODE_VALUE_RESET_COMP:
  3187. if (cnic_ready_to_close(csk, opcode)) {
  3188. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags))
  3189. cmd = L5CM_RAMROD_CMD_ID_SEARCHER_DELETE;
  3190. else
  3191. close_complete = 1;
  3192. }
  3193. break;
  3194. case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE:
  3195. cmd = L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD;
  3196. break;
  3197. case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD:
  3198. close_complete = 1;
  3199. break;
  3200. }
  3201. if (cmd) {
  3202. memset(&l5_data, 0, sizeof(l5_data));
  3203. cnic_submit_kwqe_16(dev, cmd, csk->cid, ISCSI_CONNECTION_TYPE,
  3204. &l5_data);
  3205. } else if (close_complete) {
  3206. ctx->timestamp = jiffies;
  3207. cnic_close_conn(csk);
  3208. cnic_cm_upcall(cp, csk, csk->state);
  3209. }
  3210. }
  3211. static void cnic_cm_stop_bnx2x_hw(struct cnic_dev *dev)
  3212. {
  3213. struct cnic_local *cp = dev->cnic_priv;
  3214. int i;
  3215. if (!cp->ctx_tbl)
  3216. return;
  3217. if (!netif_running(dev->netdev))
  3218. return;
  3219. for (i = 0; i < cp->max_cid_space; i++) {
  3220. struct cnic_context *ctx = &cp->ctx_tbl[i];
  3221. while (test_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags))
  3222. msleep(10);
  3223. if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags))
  3224. netdev_warn(dev->netdev, "CID %x not deleted\n",
  3225. ctx->cid);
  3226. }
  3227. cancel_delayed_work(&cp->delete_task);
  3228. flush_workqueue(cnic_wq);
  3229. if (atomic_read(&cp->iscsi_conn) != 0)
  3230. netdev_warn(dev->netdev, "%d iSCSI connections not destroyed\n",
  3231. atomic_read(&cp->iscsi_conn));
  3232. }
  3233. static int cnic_cm_init_bnx2x_hw(struct cnic_dev *dev)
  3234. {
  3235. struct cnic_local *cp = dev->cnic_priv;
  3236. u32 pfid = cp->pfid;
  3237. u32 port = CNIC_PORT(cp);
  3238. cnic_init_bnx2x_mac(dev);
  3239. cnic_bnx2x_set_tcp_timestamp(dev, 1);
  3240. CNIC_WR16(dev, BAR_XSTRORM_INTMEM +
  3241. XSTORM_ISCSI_LOCAL_VLAN_OFFSET(pfid), 0);
  3242. CNIC_WR(dev, BAR_XSTRORM_INTMEM +
  3243. XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_ENABLED_OFFSET(port), 1);
  3244. CNIC_WR(dev, BAR_XSTRORM_INTMEM +
  3245. XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_MAX_COUNT_OFFSET(port),
  3246. DEF_MAX_DA_COUNT);
  3247. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  3248. XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(pfid), DEF_TTL);
  3249. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  3250. XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(pfid), DEF_TOS);
  3251. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  3252. XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(pfid), 2);
  3253. CNIC_WR(dev, BAR_XSTRORM_INTMEM +
  3254. XSTORM_TCP_TX_SWS_TIMER_VAL_OFFSET(pfid), DEF_SWS_TIMER);
  3255. CNIC_WR(dev, BAR_TSTRORM_INTMEM + TSTORM_TCP_MAX_CWND_OFFSET(pfid),
  3256. DEF_MAX_CWND);
  3257. return 0;
  3258. }
  3259. static void cnic_delete_task(struct work_struct *work)
  3260. {
  3261. struct cnic_local *cp;
  3262. struct cnic_dev *dev;
  3263. u32 i;
  3264. int need_resched = 0;
  3265. cp = container_of(work, struct cnic_local, delete_task.work);
  3266. dev = cp->dev;
  3267. for (i = 0; i < cp->max_cid_space; i++) {
  3268. struct cnic_context *ctx = &cp->ctx_tbl[i];
  3269. if (!test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags) ||
  3270. !test_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags))
  3271. continue;
  3272. if (!time_after(jiffies, ctx->timestamp + (2 * HZ))) {
  3273. need_resched = 1;
  3274. continue;
  3275. }
  3276. if (!test_and_clear_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags))
  3277. continue;
  3278. cnic_bnx2x_destroy_ramrod(dev, i);
  3279. cnic_free_bnx2x_conn_resc(dev, i);
  3280. if (ctx->ulp_proto_id == CNIC_ULP_ISCSI)
  3281. atomic_dec(&cp->iscsi_conn);
  3282. clear_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags);
  3283. }
  3284. if (need_resched)
  3285. queue_delayed_work(cnic_wq, &cp->delete_task,
  3286. msecs_to_jiffies(10));
  3287. }
  3288. static int cnic_cm_open(struct cnic_dev *dev)
  3289. {
  3290. struct cnic_local *cp = dev->cnic_priv;
  3291. int err;
  3292. err = cnic_cm_alloc_mem(dev);
  3293. if (err)
  3294. return err;
  3295. err = cp->start_cm(dev);
  3296. if (err)
  3297. goto err_out;
  3298. INIT_DELAYED_WORK(&cp->delete_task, cnic_delete_task);
  3299. dev->cm_create = cnic_cm_create;
  3300. dev->cm_destroy = cnic_cm_destroy;
  3301. dev->cm_connect = cnic_cm_connect;
  3302. dev->cm_abort = cnic_cm_abort;
  3303. dev->cm_close = cnic_cm_close;
  3304. dev->cm_select_dev = cnic_cm_select_dev;
  3305. cp->ulp_handle[CNIC_ULP_L4] = dev;
  3306. rcu_assign_pointer(cp->ulp_ops[CNIC_ULP_L4], &cm_ulp_ops);
  3307. return 0;
  3308. err_out:
  3309. cnic_cm_free_mem(dev);
  3310. return err;
  3311. }
  3312. static int cnic_cm_shutdown(struct cnic_dev *dev)
  3313. {
  3314. struct cnic_local *cp = dev->cnic_priv;
  3315. int i;
  3316. cp->stop_cm(dev);
  3317. if (!cp->csk_tbl)
  3318. return 0;
  3319. for (i = 0; i < MAX_CM_SK_TBL_SZ; i++) {
  3320. struct cnic_sock *csk = &cp->csk_tbl[i];
  3321. clear_bit(SK_F_INUSE, &csk->flags);
  3322. cnic_cm_cleanup(csk);
  3323. }
  3324. cnic_cm_free_mem(dev);
  3325. return 0;
  3326. }
  3327. static void cnic_init_context(struct cnic_dev *dev, u32 cid)
  3328. {
  3329. u32 cid_addr;
  3330. int i;
  3331. cid_addr = GET_CID_ADDR(cid);
  3332. for (i = 0; i < CTX_SIZE; i += 4)
  3333. cnic_ctx_wr(dev, cid_addr, i, 0);
  3334. }
  3335. static int cnic_setup_5709_context(struct cnic_dev *dev, int valid)
  3336. {
  3337. struct cnic_local *cp = dev->cnic_priv;
  3338. int ret = 0, i;
  3339. u32 valid_bit = valid ? BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID : 0;
  3340. if (CHIP_NUM(cp) != CHIP_NUM_5709)
  3341. return 0;
  3342. for (i = 0; i < cp->ctx_blks; i++) {
  3343. int j;
  3344. u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk;
  3345. u32 val;
  3346. memset(cp->ctx_arr[i].ctx, 0, BCM_PAGE_SIZE);
  3347. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA0,
  3348. (cp->ctx_arr[i].mapping & 0xffffffff) | valid_bit);
  3349. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA1,
  3350. (u64) cp->ctx_arr[i].mapping >> 32);
  3351. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_CTRL, idx |
  3352. BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
  3353. for (j = 0; j < 10; j++) {
  3354. val = CNIC_RD(dev, BNX2_CTX_HOST_PAGE_TBL_CTRL);
  3355. if (!(val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ))
  3356. break;
  3357. udelay(5);
  3358. }
  3359. if (val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) {
  3360. ret = -EBUSY;
  3361. break;
  3362. }
  3363. }
  3364. return ret;
  3365. }
  3366. static void cnic_free_irq(struct cnic_dev *dev)
  3367. {
  3368. struct cnic_local *cp = dev->cnic_priv;
  3369. struct cnic_eth_dev *ethdev = cp->ethdev;
  3370. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3371. cp->disable_int_sync(dev);
  3372. tasklet_kill(&cp->cnic_irq_task);
  3373. free_irq(ethdev->irq_arr[0].vector, dev);
  3374. }
  3375. }
  3376. static int cnic_request_irq(struct cnic_dev *dev)
  3377. {
  3378. struct cnic_local *cp = dev->cnic_priv;
  3379. struct cnic_eth_dev *ethdev = cp->ethdev;
  3380. int err;
  3381. err = request_irq(ethdev->irq_arr[0].vector, cnic_irq, 0, "cnic", dev);
  3382. if (err)
  3383. tasklet_disable(&cp->cnic_irq_task);
  3384. return err;
  3385. }
  3386. static int cnic_init_bnx2_irq(struct cnic_dev *dev)
  3387. {
  3388. struct cnic_local *cp = dev->cnic_priv;
  3389. struct cnic_eth_dev *ethdev = cp->ethdev;
  3390. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3391. int err, i = 0;
  3392. int sblk_num = cp->status_blk_num;
  3393. u32 base = ((sblk_num - 1) * BNX2_HC_SB_CONFIG_SIZE) +
  3394. BNX2_HC_SB_CONFIG_1;
  3395. CNIC_WR(dev, base, BNX2_HC_SB_CONFIG_1_ONE_SHOT);
  3396. CNIC_WR(dev, base + BNX2_HC_COMP_PROD_TRIP_OFF, (2 << 16) | 8);
  3397. CNIC_WR(dev, base + BNX2_HC_COM_TICKS_OFF, (64 << 16) | 220);
  3398. CNIC_WR(dev, base + BNX2_HC_CMD_TICKS_OFF, (64 << 16) | 220);
  3399. cp->last_status_idx = cp->status_blk.bnx2->status_idx;
  3400. tasklet_init(&cp->cnic_irq_task, cnic_service_bnx2_msix,
  3401. (unsigned long) dev);
  3402. err = cnic_request_irq(dev);
  3403. if (err)
  3404. return err;
  3405. while (cp->status_blk.bnx2->status_completion_producer_index &&
  3406. i < 10) {
  3407. CNIC_WR(dev, BNX2_HC_COALESCE_NOW,
  3408. 1 << (11 + sblk_num));
  3409. udelay(10);
  3410. i++;
  3411. barrier();
  3412. }
  3413. if (cp->status_blk.bnx2->status_completion_producer_index) {
  3414. cnic_free_irq(dev);
  3415. goto failed;
  3416. }
  3417. } else {
  3418. struct status_block *sblk = cp->status_blk.gen;
  3419. u32 hc_cmd = CNIC_RD(dev, BNX2_HC_COMMAND);
  3420. int i = 0;
  3421. while (sblk->status_completion_producer_index && i < 10) {
  3422. CNIC_WR(dev, BNX2_HC_COMMAND,
  3423. hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3424. udelay(10);
  3425. i++;
  3426. barrier();
  3427. }
  3428. if (sblk->status_completion_producer_index)
  3429. goto failed;
  3430. }
  3431. return 0;
  3432. failed:
  3433. netdev_err(dev->netdev, "KCQ index not resetting to 0\n");
  3434. return -EBUSY;
  3435. }
  3436. static void cnic_enable_bnx2_int(struct cnic_dev *dev)
  3437. {
  3438. struct cnic_local *cp = dev->cnic_priv;
  3439. struct cnic_eth_dev *ethdev = cp->ethdev;
  3440. if (!(ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX))
  3441. return;
  3442. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  3443. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx);
  3444. }
  3445. static void cnic_disable_bnx2_int_sync(struct cnic_dev *dev)
  3446. {
  3447. struct cnic_local *cp = dev->cnic_priv;
  3448. struct cnic_eth_dev *ethdev = cp->ethdev;
  3449. if (!(ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX))
  3450. return;
  3451. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  3452. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  3453. CNIC_RD(dev, BNX2_PCICFG_INT_ACK_CMD);
  3454. synchronize_irq(ethdev->irq_arr[0].vector);
  3455. }
  3456. static void cnic_init_bnx2_tx_ring(struct cnic_dev *dev)
  3457. {
  3458. struct cnic_local *cp = dev->cnic_priv;
  3459. struct cnic_eth_dev *ethdev = cp->ethdev;
  3460. struct cnic_uio_dev *udev = cp->udev;
  3461. u32 cid_addr, tx_cid, sb_id;
  3462. u32 val, offset0, offset1, offset2, offset3;
  3463. int i;
  3464. struct tx_bd *txbd;
  3465. dma_addr_t buf_map, ring_map = udev->l2_ring_map;
  3466. struct status_block *s_blk = cp->status_blk.gen;
  3467. sb_id = cp->status_blk_num;
  3468. tx_cid = 20;
  3469. cp->tx_cons_ptr = &s_blk->status_tx_quick_consumer_index2;
  3470. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3471. struct status_block_msix *sblk = cp->status_blk.bnx2;
  3472. tx_cid = TX_TSS_CID + sb_id - 1;
  3473. CNIC_WR(dev, BNX2_TSCH_TSS_CFG, (sb_id << 24) |
  3474. (TX_TSS_CID << 7));
  3475. cp->tx_cons_ptr = &sblk->status_tx_quick_consumer_index;
  3476. }
  3477. cp->tx_cons = *cp->tx_cons_ptr;
  3478. cid_addr = GET_CID_ADDR(tx_cid);
  3479. if (CHIP_NUM(cp) == CHIP_NUM_5709) {
  3480. u32 cid_addr2 = GET_CID_ADDR(tx_cid + 4) + 0x40;
  3481. for (i = 0; i < PHY_CTX_SIZE; i += 4)
  3482. cnic_ctx_wr(dev, cid_addr2, i, 0);
  3483. offset0 = BNX2_L2CTX_TYPE_XI;
  3484. offset1 = BNX2_L2CTX_CMD_TYPE_XI;
  3485. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI_XI;
  3486. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO_XI;
  3487. } else {
  3488. cnic_init_context(dev, tx_cid);
  3489. cnic_init_context(dev, tx_cid + 1);
  3490. offset0 = BNX2_L2CTX_TYPE;
  3491. offset1 = BNX2_L2CTX_CMD_TYPE;
  3492. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI;
  3493. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO;
  3494. }
  3495. val = BNX2_L2CTX_TYPE_TYPE_L2 | BNX2_L2CTX_TYPE_SIZE_L2;
  3496. cnic_ctx_wr(dev, cid_addr, offset0, val);
  3497. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
  3498. cnic_ctx_wr(dev, cid_addr, offset1, val);
  3499. txbd = (struct tx_bd *) udev->l2_ring;
  3500. buf_map = udev->l2_buf_map;
  3501. for (i = 0; i < MAX_TX_DESC_CNT; i++, txbd++) {
  3502. txbd->tx_bd_haddr_hi = (u64) buf_map >> 32;
  3503. txbd->tx_bd_haddr_lo = (u64) buf_map & 0xffffffff;
  3504. }
  3505. val = (u64) ring_map >> 32;
  3506. cnic_ctx_wr(dev, cid_addr, offset2, val);
  3507. txbd->tx_bd_haddr_hi = val;
  3508. val = (u64) ring_map & 0xffffffff;
  3509. cnic_ctx_wr(dev, cid_addr, offset3, val);
  3510. txbd->tx_bd_haddr_lo = val;
  3511. }
  3512. static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev)
  3513. {
  3514. struct cnic_local *cp = dev->cnic_priv;
  3515. struct cnic_eth_dev *ethdev = cp->ethdev;
  3516. struct cnic_uio_dev *udev = cp->udev;
  3517. u32 cid_addr, sb_id, val, coal_reg, coal_val;
  3518. int i;
  3519. struct rx_bd *rxbd;
  3520. struct status_block *s_blk = cp->status_blk.gen;
  3521. dma_addr_t ring_map = udev->l2_ring_map;
  3522. sb_id = cp->status_blk_num;
  3523. cnic_init_context(dev, 2);
  3524. cp->rx_cons_ptr = &s_blk->status_rx_quick_consumer_index2;
  3525. coal_reg = BNX2_HC_COMMAND;
  3526. coal_val = CNIC_RD(dev, coal_reg);
  3527. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3528. struct status_block_msix *sblk = cp->status_blk.bnx2;
  3529. cp->rx_cons_ptr = &sblk->status_rx_quick_consumer_index;
  3530. coal_reg = BNX2_HC_COALESCE_NOW;
  3531. coal_val = 1 << (11 + sb_id);
  3532. }
  3533. i = 0;
  3534. while (!(*cp->rx_cons_ptr != 0) && i < 10) {
  3535. CNIC_WR(dev, coal_reg, coal_val);
  3536. udelay(10);
  3537. i++;
  3538. barrier();
  3539. }
  3540. cp->rx_cons = *cp->rx_cons_ptr;
  3541. cid_addr = GET_CID_ADDR(2);
  3542. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
  3543. BNX2_L2CTX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
  3544. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_CTX_TYPE, val);
  3545. if (sb_id == 0)
  3546. val = 2 << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT;
  3547. else
  3548. val = BNX2_L2CTX_L2_STATUSB_NUM(sb_id);
  3549. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val);
  3550. rxbd = (struct rx_bd *) (udev->l2_ring + BCM_PAGE_SIZE);
  3551. for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) {
  3552. dma_addr_t buf_map;
  3553. int n = (i % cp->l2_rx_ring_size) + 1;
  3554. buf_map = udev->l2_buf_map + (n * cp->l2_single_buf_size);
  3555. rxbd->rx_bd_len = cp->l2_single_buf_size;
  3556. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  3557. rxbd->rx_bd_haddr_hi = (u64) buf_map >> 32;
  3558. rxbd->rx_bd_haddr_lo = (u64) buf_map & 0xffffffff;
  3559. }
  3560. val = (u64) (ring_map + BCM_PAGE_SIZE) >> 32;
  3561. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val);
  3562. rxbd->rx_bd_haddr_hi = val;
  3563. val = (u64) (ring_map + BCM_PAGE_SIZE) & 0xffffffff;
  3564. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val);
  3565. rxbd->rx_bd_haddr_lo = val;
  3566. val = cnic_reg_rd_ind(dev, BNX2_RXP_SCRATCH_RXP_FLOOD);
  3567. cnic_reg_wr_ind(dev, BNX2_RXP_SCRATCH_RXP_FLOOD, val | (1 << 2));
  3568. }
  3569. static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev *dev)
  3570. {
  3571. struct kwqe *wqes[1], l2kwqe;
  3572. memset(&l2kwqe, 0, sizeof(l2kwqe));
  3573. wqes[0] = &l2kwqe;
  3574. l2kwqe.kwqe_op_flag = (L2_LAYER_CODE << KWQE_LAYER_SHIFT) |
  3575. (L2_KWQE_OPCODE_VALUE_FLUSH <<
  3576. KWQE_OPCODE_SHIFT) | 2;
  3577. dev->submit_kwqes(dev, wqes, 1);
  3578. }
  3579. static void cnic_set_bnx2_mac(struct cnic_dev *dev)
  3580. {
  3581. struct cnic_local *cp = dev->cnic_priv;
  3582. u32 val;
  3583. val = cp->func << 2;
  3584. cp->shmem_base = cnic_reg_rd_ind(dev, BNX2_SHM_HDR_ADDR_0 + val);
  3585. val = cnic_reg_rd_ind(dev, cp->shmem_base +
  3586. BNX2_PORT_HW_CFG_ISCSI_MAC_UPPER);
  3587. dev->mac_addr[0] = (u8) (val >> 8);
  3588. dev->mac_addr[1] = (u8) val;
  3589. CNIC_WR(dev, BNX2_EMAC_MAC_MATCH4, val);
  3590. val = cnic_reg_rd_ind(dev, cp->shmem_base +
  3591. BNX2_PORT_HW_CFG_ISCSI_MAC_LOWER);
  3592. dev->mac_addr[2] = (u8) (val >> 24);
  3593. dev->mac_addr[3] = (u8) (val >> 16);
  3594. dev->mac_addr[4] = (u8) (val >> 8);
  3595. dev->mac_addr[5] = (u8) val;
  3596. CNIC_WR(dev, BNX2_EMAC_MAC_MATCH5, val);
  3597. val = 4 | BNX2_RPM_SORT_USER2_BC_EN;
  3598. if (CHIP_NUM(cp) != CHIP_NUM_5709)
  3599. val |= BNX2_RPM_SORT_USER2_PROM_VLAN;
  3600. CNIC_WR(dev, BNX2_RPM_SORT_USER2, 0x0);
  3601. CNIC_WR(dev, BNX2_RPM_SORT_USER2, val);
  3602. CNIC_WR(dev, BNX2_RPM_SORT_USER2, val | BNX2_RPM_SORT_USER2_ENA);
  3603. }
  3604. static int cnic_start_bnx2_hw(struct cnic_dev *dev)
  3605. {
  3606. struct cnic_local *cp = dev->cnic_priv;
  3607. struct cnic_eth_dev *ethdev = cp->ethdev;
  3608. struct status_block *sblk = cp->status_blk.gen;
  3609. u32 val, kcq_cid_addr, kwq_cid_addr;
  3610. int err;
  3611. cnic_set_bnx2_mac(dev);
  3612. val = CNIC_RD(dev, BNX2_MQ_CONFIG);
  3613. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  3614. if (BCM_PAGE_BITS > 12)
  3615. val |= (12 - 8) << 4;
  3616. else
  3617. val |= (BCM_PAGE_BITS - 8) << 4;
  3618. CNIC_WR(dev, BNX2_MQ_CONFIG, val);
  3619. CNIC_WR(dev, BNX2_HC_COMP_PROD_TRIP, (2 << 16) | 8);
  3620. CNIC_WR(dev, BNX2_HC_COM_TICKS, (64 << 16) | 220);
  3621. CNIC_WR(dev, BNX2_HC_CMD_TICKS, (64 << 16) | 220);
  3622. err = cnic_setup_5709_context(dev, 1);
  3623. if (err)
  3624. return err;
  3625. cnic_init_context(dev, KWQ_CID);
  3626. cnic_init_context(dev, KCQ_CID);
  3627. kwq_cid_addr = GET_CID_ADDR(KWQ_CID);
  3628. cp->kwq_io_addr = MB_GET_CID_ADDR(KWQ_CID) + L5_KRNLQ_HOST_QIDX;
  3629. cp->max_kwq_idx = MAX_KWQ_IDX;
  3630. cp->kwq_prod_idx = 0;
  3631. cp->kwq_con_idx = 0;
  3632. set_bit(CNIC_LCL_FL_KWQ_INIT, &cp->cnic_local_flags);
  3633. if (CHIP_NUM(cp) == CHIP_NUM_5706 || CHIP_NUM(cp) == CHIP_NUM_5708)
  3634. cp->kwq_con_idx_ptr = &sblk->status_rx_quick_consumer_index15;
  3635. else
  3636. cp->kwq_con_idx_ptr = &sblk->status_cmd_consumer_index;
  3637. /* Initialize the kernel work queue context. */
  3638. val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
  3639. (BCM_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
  3640. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_TYPE, val);
  3641. val = (BCM_PAGE_SIZE / sizeof(struct kwqe) - 1) << 16;
  3642. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
  3643. val = ((BCM_PAGE_SIZE / sizeof(struct kwqe)) << 16) | KWQ_PAGE_CNT;
  3644. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
  3645. val = (u32) ((u64) cp->kwq_info.pgtbl_map >> 32);
  3646. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_HADDR_HI, val);
  3647. val = (u32) cp->kwq_info.pgtbl_map;
  3648. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_HADDR_LO, val);
  3649. kcq_cid_addr = GET_CID_ADDR(KCQ_CID);
  3650. cp->kcq1.io_addr = MB_GET_CID_ADDR(KCQ_CID) + L5_KRNLQ_HOST_QIDX;
  3651. cp->kcq1.sw_prod_idx = 0;
  3652. cp->kcq1.hw_prod_idx_ptr =
  3653. (u16 *) &sblk->status_completion_producer_index;
  3654. cp->kcq1.status_idx_ptr = (u16 *) &sblk->status_idx;
  3655. /* Initialize the kernel complete queue context. */
  3656. val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
  3657. (BCM_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
  3658. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_TYPE, val);
  3659. val = (BCM_PAGE_SIZE / sizeof(struct kcqe) - 1) << 16;
  3660. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
  3661. val = ((BCM_PAGE_SIZE / sizeof(struct kcqe)) << 16) | KCQ_PAGE_CNT;
  3662. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
  3663. val = (u32) ((u64) cp->kcq1.dma.pgtbl_map >> 32);
  3664. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_HADDR_HI, val);
  3665. val = (u32) cp->kcq1.dma.pgtbl_map;
  3666. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_HADDR_LO, val);
  3667. cp->int_num = 0;
  3668. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3669. struct status_block_msix *msblk = cp->status_blk.bnx2;
  3670. u32 sb_id = cp->status_blk_num;
  3671. u32 sb = BNX2_L2CTX_L5_STATUSB_NUM(sb_id);
  3672. cp->kcq1.hw_prod_idx_ptr =
  3673. (u16 *) &msblk->status_completion_producer_index;
  3674. cp->kcq1.status_idx_ptr = (u16 *) &msblk->status_idx;
  3675. cp->kwq_con_idx_ptr = (u16 *) &msblk->status_cmd_consumer_index;
  3676. cp->int_num = sb_id << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT;
  3677. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_HOST_QIDX, sb);
  3678. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_HOST_QIDX, sb);
  3679. }
  3680. /* Enable Commnad Scheduler notification when we write to the
  3681. * host producer index of the kernel contexts. */
  3682. CNIC_WR(dev, BNX2_MQ_KNL_CMD_MASK1, 2);
  3683. /* Enable Command Scheduler notification when we write to either
  3684. * the Send Queue or Receive Queue producer indexes of the kernel
  3685. * bypass contexts. */
  3686. CNIC_WR(dev, BNX2_MQ_KNL_BYP_CMD_MASK1, 7);
  3687. CNIC_WR(dev, BNX2_MQ_KNL_BYP_WRITE_MASK1, 7);
  3688. /* Notify COM when the driver post an application buffer. */
  3689. CNIC_WR(dev, BNX2_MQ_KNL_RX_V2P_MASK2, 0x2000);
  3690. /* Set the CP and COM doorbells. These two processors polls the
  3691. * doorbell for a non zero value before running. This must be done
  3692. * after setting up the kernel queue contexts. */
  3693. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 1);
  3694. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 1);
  3695. cnic_init_bnx2_tx_ring(dev);
  3696. cnic_init_bnx2_rx_ring(dev);
  3697. err = cnic_init_bnx2_irq(dev);
  3698. if (err) {
  3699. netdev_err(dev->netdev, "cnic_init_irq failed\n");
  3700. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 0);
  3701. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 0);
  3702. return err;
  3703. }
  3704. return 0;
  3705. }
  3706. static void cnic_setup_bnx2x_context(struct cnic_dev *dev)
  3707. {
  3708. struct cnic_local *cp = dev->cnic_priv;
  3709. struct cnic_eth_dev *ethdev = cp->ethdev;
  3710. u32 start_offset = ethdev->ctx_tbl_offset;
  3711. int i;
  3712. for (i = 0; i < cp->ctx_blks; i++) {
  3713. struct cnic_ctx *ctx = &cp->ctx_arr[i];
  3714. dma_addr_t map = ctx->mapping;
  3715. if (cp->ctx_align) {
  3716. unsigned long mask = cp->ctx_align - 1;
  3717. map = (map + mask) & ~mask;
  3718. }
  3719. cnic_ctx_tbl_wr(dev, start_offset + i, map);
  3720. }
  3721. }
  3722. static int cnic_init_bnx2x_irq(struct cnic_dev *dev)
  3723. {
  3724. struct cnic_local *cp = dev->cnic_priv;
  3725. struct cnic_eth_dev *ethdev = cp->ethdev;
  3726. int err = 0;
  3727. tasklet_init(&cp->cnic_irq_task, cnic_service_bnx2x_bh,
  3728. (unsigned long) dev);
  3729. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)
  3730. err = cnic_request_irq(dev);
  3731. return err;
  3732. }
  3733. static inline void cnic_storm_memset_hc_disable(struct cnic_dev *dev,
  3734. u16 sb_id, u8 sb_index,
  3735. u8 disable)
  3736. {
  3737. u32 addr = BAR_CSTRORM_INTMEM +
  3738. CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id) +
  3739. offsetof(struct hc_status_block_data_e1x, index_data) +
  3740. sizeof(struct hc_index_data)*sb_index +
  3741. offsetof(struct hc_index_data, flags);
  3742. u16 flags = CNIC_RD16(dev, addr);
  3743. /* clear and set */
  3744. flags &= ~HC_INDEX_DATA_HC_ENABLED;
  3745. flags |= (((~disable) << HC_INDEX_DATA_HC_ENABLED_SHIFT) &
  3746. HC_INDEX_DATA_HC_ENABLED);
  3747. CNIC_WR16(dev, addr, flags);
  3748. }
  3749. static void cnic_enable_bnx2x_int(struct cnic_dev *dev)
  3750. {
  3751. struct cnic_local *cp = dev->cnic_priv;
  3752. u8 sb_id = cp->status_blk_num;
  3753. CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
  3754. CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id) +
  3755. offsetof(struct hc_status_block_data_e1x, index_data) +
  3756. sizeof(struct hc_index_data)*HC_INDEX_ISCSI_EQ_CONS +
  3757. offsetof(struct hc_index_data, timeout), 64 / 12);
  3758. cnic_storm_memset_hc_disable(dev, sb_id, HC_INDEX_ISCSI_EQ_CONS, 0);
  3759. }
  3760. static void cnic_disable_bnx2x_int_sync(struct cnic_dev *dev)
  3761. {
  3762. }
  3763. static void cnic_init_bnx2x_tx_ring(struct cnic_dev *dev,
  3764. struct client_init_ramrod_data *data)
  3765. {
  3766. struct cnic_local *cp = dev->cnic_priv;
  3767. struct cnic_uio_dev *udev = cp->udev;
  3768. union eth_tx_bd_types *txbd = (union eth_tx_bd_types *) udev->l2_ring;
  3769. dma_addr_t buf_map, ring_map = udev->l2_ring_map;
  3770. struct host_sp_status_block *sb = cp->bnx2x_def_status_blk;
  3771. int port = CNIC_PORT(cp);
  3772. int i;
  3773. u32 cli = cp->ethdev->iscsi_l2_client_id;
  3774. u32 val;
  3775. memset(txbd, 0, BCM_PAGE_SIZE);
  3776. buf_map = udev->l2_buf_map;
  3777. for (i = 0; i < MAX_TX_DESC_CNT; i += 3, txbd += 3) {
  3778. struct eth_tx_start_bd *start_bd = &txbd->start_bd;
  3779. struct eth_tx_bd *reg_bd = &((txbd + 2)->reg_bd);
  3780. start_bd->addr_hi = cpu_to_le32((u64) buf_map >> 32);
  3781. start_bd->addr_lo = cpu_to_le32(buf_map & 0xffffffff);
  3782. reg_bd->addr_hi = start_bd->addr_hi;
  3783. reg_bd->addr_lo = start_bd->addr_lo + 0x10;
  3784. start_bd->nbytes = cpu_to_le16(0x10);
  3785. start_bd->nbd = cpu_to_le16(3);
  3786. start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  3787. start_bd->general_data = (UNICAST_ADDRESS <<
  3788. ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT);
  3789. start_bd->general_data |= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
  3790. }
  3791. val = (u64) ring_map >> 32;
  3792. txbd->next_bd.addr_hi = cpu_to_le32(val);
  3793. data->tx.tx_bd_page_base.hi = cpu_to_le32(val);
  3794. val = (u64) ring_map & 0xffffffff;
  3795. txbd->next_bd.addr_lo = cpu_to_le32(val);
  3796. data->tx.tx_bd_page_base.lo = cpu_to_le32(val);
  3797. /* Other ramrod params */
  3798. data->tx.tx_sb_index_number = HC_SP_INDEX_ETH_ISCSI_CQ_CONS;
  3799. data->tx.tx_status_block_id = BNX2X_DEF_SB_ID;
  3800. /* reset xstorm per client statistics */
  3801. if (cli < MAX_STAT_COUNTER_ID) {
  3802. val = BAR_XSTRORM_INTMEM +
  3803. XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli);
  3804. for (i = 0; i < sizeof(struct xstorm_per_client_stats) / 4; i++)
  3805. CNIC_WR(dev, val + i * 4, 0);
  3806. }
  3807. cp->tx_cons_ptr =
  3808. &sb->sp_sb.index_values[HC_SP_INDEX_ETH_ISCSI_CQ_CONS];
  3809. }
  3810. static void cnic_init_bnx2x_rx_ring(struct cnic_dev *dev,
  3811. struct client_init_ramrod_data *data)
  3812. {
  3813. struct cnic_local *cp = dev->cnic_priv;
  3814. struct cnic_uio_dev *udev = cp->udev;
  3815. struct eth_rx_bd *rxbd = (struct eth_rx_bd *) (udev->l2_ring +
  3816. BCM_PAGE_SIZE);
  3817. struct eth_rx_cqe_next_page *rxcqe = (struct eth_rx_cqe_next_page *)
  3818. (udev->l2_ring + (2 * BCM_PAGE_SIZE));
  3819. struct host_sp_status_block *sb = cp->bnx2x_def_status_blk;
  3820. int i;
  3821. int port = CNIC_PORT(cp);
  3822. u32 cli = cp->ethdev->iscsi_l2_client_id;
  3823. int cl_qzone_id = BNX2X_CL_QZONE_ID(cp, cli);
  3824. u32 val;
  3825. dma_addr_t ring_map = udev->l2_ring_map;
  3826. /* General data */
  3827. data->general.client_id = cli;
  3828. data->general.statistics_en_flg = 1;
  3829. data->general.statistics_counter_id = cli;
  3830. data->general.activate_flg = 1;
  3831. data->general.sp_client_id = cli;
  3832. for (i = 0; i < BNX2X_MAX_RX_DESC_CNT; i++, rxbd++) {
  3833. dma_addr_t buf_map;
  3834. int n = (i % cp->l2_rx_ring_size) + 1;
  3835. buf_map = udev->l2_buf_map + (n * cp->l2_single_buf_size);
  3836. rxbd->addr_hi = cpu_to_le32((u64) buf_map >> 32);
  3837. rxbd->addr_lo = cpu_to_le32(buf_map & 0xffffffff);
  3838. }
  3839. val = (u64) (ring_map + BCM_PAGE_SIZE) >> 32;
  3840. rxbd->addr_hi = cpu_to_le32(val);
  3841. data->rx.bd_page_base.hi = cpu_to_le32(val);
  3842. val = (u64) (ring_map + BCM_PAGE_SIZE) & 0xffffffff;
  3843. rxbd->addr_lo = cpu_to_le32(val);
  3844. data->rx.bd_page_base.lo = cpu_to_le32(val);
  3845. rxcqe += BNX2X_MAX_RCQ_DESC_CNT;
  3846. val = (u64) (ring_map + (2 * BCM_PAGE_SIZE)) >> 32;
  3847. rxcqe->addr_hi = cpu_to_le32(val);
  3848. data->rx.cqe_page_base.hi = cpu_to_le32(val);
  3849. val = (u64) (ring_map + (2 * BCM_PAGE_SIZE)) & 0xffffffff;
  3850. rxcqe->addr_lo = cpu_to_le32(val);
  3851. data->rx.cqe_page_base.lo = cpu_to_le32(val);
  3852. /* Other ramrod params */
  3853. data->rx.client_qzone_id = cl_qzone_id;
  3854. data->rx.rx_sb_index_number = HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS;
  3855. data->rx.status_block_id = BNX2X_DEF_SB_ID;
  3856. data->rx.cache_line_alignment_log_size = L1_CACHE_SHIFT;
  3857. data->rx.bd_buff_size = cpu_to_le16(cp->l2_single_buf_size);
  3858. data->rx.mtu = cpu_to_le16(cp->l2_single_buf_size - 14);
  3859. data->rx.outer_vlan_removal_enable_flg = 1;
  3860. /* reset tstorm and ustorm per client statistics */
  3861. if (cli < MAX_STAT_COUNTER_ID) {
  3862. val = BAR_TSTRORM_INTMEM +
  3863. TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli);
  3864. for (i = 0; i < sizeof(struct tstorm_per_client_stats) / 4; i++)
  3865. CNIC_WR(dev, val + i * 4, 0);
  3866. val = BAR_USTRORM_INTMEM +
  3867. USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli);
  3868. for (i = 0; i < sizeof(struct ustorm_per_client_stats) / 4; i++)
  3869. CNIC_WR(dev, val + i * 4, 0);
  3870. }
  3871. cp->rx_cons_ptr =
  3872. &sb->sp_sb.index_values[HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS];
  3873. cp->rx_cons = *cp->rx_cons_ptr;
  3874. }
  3875. static int cnic_read_bnx2x_iscsi_mac(struct cnic_dev *dev, u32 upper_addr,
  3876. u32 lower_addr)
  3877. {
  3878. u32 val;
  3879. u8 mac[6];
  3880. val = CNIC_RD(dev, upper_addr);
  3881. mac[0] = (u8) (val >> 8);
  3882. mac[1] = (u8) val;
  3883. val = CNIC_RD(dev, lower_addr);
  3884. mac[2] = (u8) (val >> 24);
  3885. mac[3] = (u8) (val >> 16);
  3886. mac[4] = (u8) (val >> 8);
  3887. mac[5] = (u8) val;
  3888. if (is_valid_ether_addr(mac)) {
  3889. memcpy(dev->mac_addr, mac, 6);
  3890. return 0;
  3891. } else {
  3892. return -EINVAL;
  3893. }
  3894. }
  3895. static void cnic_get_bnx2x_iscsi_info(struct cnic_dev *dev)
  3896. {
  3897. struct cnic_local *cp = dev->cnic_priv;
  3898. u32 base, base2, addr, addr1, val;
  3899. int port = CNIC_PORT(cp);
  3900. dev->max_iscsi_conn = 0;
  3901. base = CNIC_RD(dev, MISC_REG_SHARED_MEM_ADDR);
  3902. if (base == 0)
  3903. return;
  3904. base2 = CNIC_RD(dev, (CNIC_PATH(cp) ? MISC_REG_GENERIC_CR_1 :
  3905. MISC_REG_GENERIC_CR_0));
  3906. addr = BNX2X_SHMEM_ADDR(base,
  3907. dev_info.port_hw_config[port].iscsi_mac_upper);
  3908. addr1 = BNX2X_SHMEM_ADDR(base,
  3909. dev_info.port_hw_config[port].iscsi_mac_lower);
  3910. cnic_read_bnx2x_iscsi_mac(dev, addr, addr1);
  3911. addr = BNX2X_SHMEM_ADDR(base, validity_map[port]);
  3912. val = CNIC_RD(dev, addr);
  3913. if (!(val & SHR_MEM_VALIDITY_LIC_NO_KEY_IN_EFFECT)) {
  3914. u16 val16;
  3915. addr = BNX2X_SHMEM_ADDR(base,
  3916. drv_lic_key[port].max_iscsi_init_conn);
  3917. val16 = CNIC_RD16(dev, addr);
  3918. if (val16)
  3919. val16 ^= 0x1e1e;
  3920. dev->max_iscsi_conn = val16;
  3921. }
  3922. if (BNX2X_CHIP_IS_E2(cp->chip_id))
  3923. dev->max_fcoe_conn = BNX2X_FCOE_NUM_CONNECTIONS;
  3924. if (BNX2X_CHIP_IS_E1H(cp->chip_id) || BNX2X_CHIP_IS_E2(cp->chip_id)) {
  3925. int func = CNIC_FUNC(cp);
  3926. u32 mf_cfg_addr;
  3927. if (BNX2X_SHMEM2_HAS(base2, mf_cfg_addr))
  3928. mf_cfg_addr = CNIC_RD(dev, BNX2X_SHMEM2_ADDR(base2,
  3929. mf_cfg_addr));
  3930. else
  3931. mf_cfg_addr = base + BNX2X_SHMEM_MF_BLK_OFFSET;
  3932. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  3933. /* Must determine if the MF is SD vs SI mode */
  3934. addr = BNX2X_SHMEM_ADDR(base,
  3935. dev_info.shared_feature_config.config);
  3936. val = CNIC_RD(dev, addr);
  3937. if ((val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK) ==
  3938. SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT) {
  3939. int rc;
  3940. /* MULTI_FUNCTION_SI mode */
  3941. addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
  3942. func_ext_config[func].func_cfg);
  3943. val = CNIC_RD(dev, addr);
  3944. if (!(val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD))
  3945. dev->max_iscsi_conn = 0;
  3946. if (!(val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  3947. dev->max_fcoe_conn = 0;
  3948. addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
  3949. func_ext_config[func].
  3950. iscsi_mac_addr_upper);
  3951. addr1 = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
  3952. func_ext_config[func].
  3953. iscsi_mac_addr_lower);
  3954. rc = cnic_read_bnx2x_iscsi_mac(dev, addr,
  3955. addr1);
  3956. if (rc && func > 1)
  3957. dev->max_iscsi_conn = 0;
  3958. return;
  3959. }
  3960. }
  3961. addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
  3962. func_mf_config[func].e1hov_tag);
  3963. val = CNIC_RD(dev, addr);
  3964. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  3965. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  3966. dev->max_fcoe_conn = 0;
  3967. dev->max_iscsi_conn = 0;
  3968. }
  3969. }
  3970. if (!is_valid_ether_addr(dev->mac_addr))
  3971. dev->max_iscsi_conn = 0;
  3972. }
  3973. static void cnic_init_bnx2x_kcq(struct cnic_dev *dev)
  3974. {
  3975. struct cnic_local *cp = dev->cnic_priv;
  3976. u32 pfid = cp->pfid;
  3977. cp->kcq1.io_addr = BAR_CSTRORM_INTMEM +
  3978. CSTORM_ISCSI_EQ_PROD_OFFSET(pfid, 0);
  3979. cp->kcq1.sw_prod_idx = 0;
  3980. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  3981. struct host_hc_status_block_e2 *sb = cp->status_blk.gen;
  3982. cp->kcq1.hw_prod_idx_ptr =
  3983. &sb->sb.index_values[HC_INDEX_ISCSI_EQ_CONS];
  3984. cp->kcq1.status_idx_ptr =
  3985. &sb->sb.running_index[SM_RX_ID];
  3986. } else {
  3987. struct host_hc_status_block_e1x *sb = cp->status_blk.gen;
  3988. cp->kcq1.hw_prod_idx_ptr =
  3989. &sb->sb.index_values[HC_INDEX_ISCSI_EQ_CONS];
  3990. cp->kcq1.status_idx_ptr =
  3991. &sb->sb.running_index[SM_RX_ID];
  3992. }
  3993. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  3994. struct host_hc_status_block_e2 *sb = cp->status_blk.gen;
  3995. cp->kcq2.io_addr = BAR_USTRORM_INTMEM +
  3996. USTORM_FCOE_EQ_PROD_OFFSET(pfid);
  3997. cp->kcq2.sw_prod_idx = 0;
  3998. cp->kcq2.hw_prod_idx_ptr =
  3999. &sb->sb.index_values[HC_INDEX_FCOE_EQ_CONS];
  4000. cp->kcq2.status_idx_ptr =
  4001. &sb->sb.running_index[SM_RX_ID];
  4002. }
  4003. }
  4004. static int cnic_start_bnx2x_hw(struct cnic_dev *dev)
  4005. {
  4006. struct cnic_local *cp = dev->cnic_priv;
  4007. struct cnic_eth_dev *ethdev = cp->ethdev;
  4008. int func = CNIC_FUNC(cp), ret, i;
  4009. u32 pfid;
  4010. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  4011. u32 val = CNIC_RD(dev, MISC_REG_PORT4MODE_EN_OVWR);
  4012. if (!(val & 1))
  4013. val = CNIC_RD(dev, MISC_REG_PORT4MODE_EN);
  4014. else
  4015. val = (val >> 1) & 1;
  4016. if (val)
  4017. cp->pfid = func >> 1;
  4018. else
  4019. cp->pfid = func & 0x6;
  4020. } else {
  4021. cp->pfid = func;
  4022. }
  4023. pfid = cp->pfid;
  4024. ret = cnic_init_id_tbl(&cp->cid_tbl, MAX_ISCSI_TBL_SZ,
  4025. cp->iscsi_start_cid);
  4026. if (ret)
  4027. return -ENOMEM;
  4028. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  4029. ret = cnic_init_id_tbl(&cp->fcoe_cid_tbl,
  4030. BNX2X_FCOE_NUM_CONNECTIONS,
  4031. cp->fcoe_start_cid);
  4032. if (ret)
  4033. return -ENOMEM;
  4034. }
  4035. cp->bnx2x_igu_sb_id = ethdev->irq_arr[0].status_blk_num2;
  4036. cnic_init_bnx2x_kcq(dev);
  4037. cnic_get_bnx2x_iscsi_info(dev);
  4038. /* Only 1 EQ */
  4039. CNIC_WR16(dev, cp->kcq1.io_addr, MAX_KCQ_IDX);
  4040. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4041. CSTORM_ISCSI_EQ_CONS_OFFSET(pfid, 0), 0);
  4042. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4043. CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid, 0),
  4044. cp->kcq1.dma.pg_map_arr[1] & 0xffffffff);
  4045. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4046. CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid, 0) + 4,
  4047. (u64) cp->kcq1.dma.pg_map_arr[1] >> 32);
  4048. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4049. CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid, 0),
  4050. cp->kcq1.dma.pg_map_arr[0] & 0xffffffff);
  4051. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4052. CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid, 0) + 4,
  4053. (u64) cp->kcq1.dma.pg_map_arr[0] >> 32);
  4054. CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
  4055. CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(pfid, 0), 1);
  4056. CNIC_WR16(dev, BAR_CSTRORM_INTMEM +
  4057. CSTORM_ISCSI_EQ_SB_NUM_OFFSET(pfid, 0), cp->status_blk_num);
  4058. CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
  4059. CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(pfid, 0),
  4060. HC_INDEX_ISCSI_EQ_CONS);
  4061. for (i = 0; i < cp->conn_buf_info.num_pages; i++) {
  4062. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  4063. TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(pfid, i),
  4064. cp->conn_buf_info.pgtbl[2 * i]);
  4065. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  4066. TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(pfid, i) + 4,
  4067. cp->conn_buf_info.pgtbl[(2 * i) + 1]);
  4068. }
  4069. CNIC_WR(dev, BAR_USTRORM_INTMEM +
  4070. USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid),
  4071. cp->gbl_buf_info.pg_map_arr[0] & 0xffffffff);
  4072. CNIC_WR(dev, BAR_USTRORM_INTMEM +
  4073. USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid) + 4,
  4074. (u64) cp->gbl_buf_info.pg_map_arr[0] >> 32);
  4075. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  4076. TSTORM_ISCSI_TCP_LOCAL_ADV_WND_OFFSET(pfid), DEF_RCV_BUF);
  4077. cnic_setup_bnx2x_context(dev);
  4078. ret = cnic_init_bnx2x_irq(dev);
  4079. if (ret)
  4080. return ret;
  4081. return 0;
  4082. }
  4083. static void cnic_init_rings(struct cnic_dev *dev)
  4084. {
  4085. struct cnic_local *cp = dev->cnic_priv;
  4086. struct cnic_uio_dev *udev = cp->udev;
  4087. if (test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags))
  4088. return;
  4089. if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
  4090. cnic_init_bnx2_tx_ring(dev);
  4091. cnic_init_bnx2_rx_ring(dev);
  4092. set_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags);
  4093. } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
  4094. u32 cli = cp->ethdev->iscsi_l2_client_id;
  4095. u32 cid = cp->ethdev->iscsi_l2_cid;
  4096. u32 cl_qzone_id, type;
  4097. struct client_init_ramrod_data *data;
  4098. union l5cm_specific_data l5_data;
  4099. struct ustorm_eth_rx_producers rx_prods = {0};
  4100. u32 off, i;
  4101. rx_prods.bd_prod = 0;
  4102. rx_prods.cqe_prod = BNX2X_MAX_RCQ_DESC_CNT;
  4103. barrier();
  4104. cl_qzone_id = BNX2X_CL_QZONE_ID(cp, cli);
  4105. off = BAR_USTRORM_INTMEM +
  4106. (BNX2X_CHIP_IS_E2(cp->chip_id) ?
  4107. USTORM_RX_PRODS_E2_OFFSET(cl_qzone_id) :
  4108. USTORM_RX_PRODS_E1X_OFFSET(CNIC_PORT(cp), cli));
  4109. for (i = 0; i < sizeof(struct ustorm_eth_rx_producers) / 4; i++)
  4110. CNIC_WR(dev, off + i * 4, ((u32 *) &rx_prods)[i]);
  4111. set_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags);
  4112. data = udev->l2_buf;
  4113. memset(data, 0, sizeof(*data));
  4114. cnic_init_bnx2x_tx_ring(dev, data);
  4115. cnic_init_bnx2x_rx_ring(dev, data);
  4116. l5_data.phy_address.lo = udev->l2_buf_map & 0xffffffff;
  4117. l5_data.phy_address.hi = (u64) udev->l2_buf_map >> 32;
  4118. type = (ETH_CONNECTION_TYPE << SPE_HDR_CONN_TYPE_SHIFT)
  4119. & SPE_HDR_CONN_TYPE;
  4120. type |= ((cp->pfid << SPE_HDR_FUNCTION_ID_SHIFT) &
  4121. SPE_HDR_FUNCTION_ID);
  4122. set_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags);
  4123. cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_ETH_CLIENT_SETUP,
  4124. cid, type, &l5_data);
  4125. i = 0;
  4126. while (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags) &&
  4127. ++i < 10)
  4128. msleep(1);
  4129. if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags))
  4130. netdev_err(dev->netdev,
  4131. "iSCSI CLIENT_SETUP did not complete\n");
  4132. cnic_spq_completion(dev, DRV_CTL_RET_L2_SPQ_CREDIT_CMD, 1);
  4133. cnic_ring_ctl(dev, cid, cli, 1);
  4134. }
  4135. }
  4136. static void cnic_shutdown_rings(struct cnic_dev *dev)
  4137. {
  4138. struct cnic_local *cp = dev->cnic_priv;
  4139. if (!test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags))
  4140. return;
  4141. if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
  4142. cnic_shutdown_bnx2_rx_ring(dev);
  4143. } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
  4144. struct cnic_local *cp = dev->cnic_priv;
  4145. u32 cli = cp->ethdev->iscsi_l2_client_id;
  4146. u32 cid = cp->ethdev->iscsi_l2_cid;
  4147. union l5cm_specific_data l5_data;
  4148. int i;
  4149. u32 type;
  4150. cnic_ring_ctl(dev, cid, cli, 0);
  4151. set_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags);
  4152. l5_data.phy_address.lo = cli;
  4153. l5_data.phy_address.hi = 0;
  4154. cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_ETH_HALT,
  4155. cid, ETH_CONNECTION_TYPE, &l5_data);
  4156. i = 0;
  4157. while (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags) &&
  4158. ++i < 10)
  4159. msleep(1);
  4160. if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags))
  4161. netdev_err(dev->netdev,
  4162. "iSCSI CLIENT_HALT did not complete\n");
  4163. cnic_spq_completion(dev, DRV_CTL_RET_L2_SPQ_CREDIT_CMD, 1);
  4164. memset(&l5_data, 0, sizeof(l5_data));
  4165. type = (NONE_CONNECTION_TYPE << SPE_HDR_CONN_TYPE_SHIFT)
  4166. & SPE_HDR_CONN_TYPE;
  4167. type |= ((cp->pfid << SPE_HDR_FUNCTION_ID_SHIFT) &
  4168. SPE_HDR_FUNCTION_ID);
  4169. cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_COMMON_CFC_DEL,
  4170. cid, type, &l5_data);
  4171. msleep(10);
  4172. }
  4173. clear_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags);
  4174. }
  4175. static int cnic_register_netdev(struct cnic_dev *dev)
  4176. {
  4177. struct cnic_local *cp = dev->cnic_priv;
  4178. struct cnic_eth_dev *ethdev = cp->ethdev;
  4179. int err;
  4180. if (!ethdev)
  4181. return -ENODEV;
  4182. if (ethdev->drv_state & CNIC_DRV_STATE_REGD)
  4183. return 0;
  4184. err = ethdev->drv_register_cnic(dev->netdev, cp->cnic_ops, dev);
  4185. if (err)
  4186. netdev_err(dev->netdev, "register_cnic failed\n");
  4187. return err;
  4188. }
  4189. static void cnic_unregister_netdev(struct cnic_dev *dev)
  4190. {
  4191. struct cnic_local *cp = dev->cnic_priv;
  4192. struct cnic_eth_dev *ethdev = cp->ethdev;
  4193. if (!ethdev)
  4194. return;
  4195. ethdev->drv_unregister_cnic(dev->netdev);
  4196. }
  4197. static int cnic_start_hw(struct cnic_dev *dev)
  4198. {
  4199. struct cnic_local *cp = dev->cnic_priv;
  4200. struct cnic_eth_dev *ethdev = cp->ethdev;
  4201. int err;
  4202. if (test_bit(CNIC_F_CNIC_UP, &dev->flags))
  4203. return -EALREADY;
  4204. dev->regview = ethdev->io_base;
  4205. pci_dev_get(dev->pcidev);
  4206. cp->func = PCI_FUNC(dev->pcidev->devfn);
  4207. cp->status_blk.gen = ethdev->irq_arr[0].status_blk;
  4208. cp->status_blk_num = ethdev->irq_arr[0].status_blk_num;
  4209. err = cp->alloc_resc(dev);
  4210. if (err) {
  4211. netdev_err(dev->netdev, "allocate resource failure\n");
  4212. goto err1;
  4213. }
  4214. err = cp->start_hw(dev);
  4215. if (err)
  4216. goto err1;
  4217. err = cnic_cm_open(dev);
  4218. if (err)
  4219. goto err1;
  4220. set_bit(CNIC_F_CNIC_UP, &dev->flags);
  4221. cp->enable_int(dev);
  4222. return 0;
  4223. err1:
  4224. cp->free_resc(dev);
  4225. pci_dev_put(dev->pcidev);
  4226. return err;
  4227. }
  4228. static void cnic_stop_bnx2_hw(struct cnic_dev *dev)
  4229. {
  4230. cnic_disable_bnx2_int_sync(dev);
  4231. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 0);
  4232. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 0);
  4233. cnic_init_context(dev, KWQ_CID);
  4234. cnic_init_context(dev, KCQ_CID);
  4235. cnic_setup_5709_context(dev, 0);
  4236. cnic_free_irq(dev);
  4237. cnic_free_resc(dev);
  4238. }
  4239. static void cnic_stop_bnx2x_hw(struct cnic_dev *dev)
  4240. {
  4241. struct cnic_local *cp = dev->cnic_priv;
  4242. cnic_free_irq(dev);
  4243. *cp->kcq1.hw_prod_idx_ptr = 0;
  4244. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4245. CSTORM_ISCSI_EQ_CONS_OFFSET(cp->pfid, 0), 0);
  4246. CNIC_WR16(dev, cp->kcq1.io_addr, 0);
  4247. cnic_free_resc(dev);
  4248. }
  4249. static void cnic_stop_hw(struct cnic_dev *dev)
  4250. {
  4251. if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) {
  4252. struct cnic_local *cp = dev->cnic_priv;
  4253. int i = 0;
  4254. /* Need to wait for the ring shutdown event to complete
  4255. * before clearing the CNIC_UP flag.
  4256. */
  4257. while (cp->udev->uio_dev != -1 && i < 15) {
  4258. msleep(100);
  4259. i++;
  4260. }
  4261. cnic_shutdown_rings(dev);
  4262. clear_bit(CNIC_F_CNIC_UP, &dev->flags);
  4263. rcu_assign_pointer(cp->ulp_ops[CNIC_ULP_L4], NULL);
  4264. synchronize_rcu();
  4265. cnic_cm_shutdown(dev);
  4266. cp->stop_hw(dev);
  4267. pci_dev_put(dev->pcidev);
  4268. }
  4269. }
  4270. static void cnic_free_dev(struct cnic_dev *dev)
  4271. {
  4272. int i = 0;
  4273. while ((atomic_read(&dev->ref_count) != 0) && i < 10) {
  4274. msleep(100);
  4275. i++;
  4276. }
  4277. if (atomic_read(&dev->ref_count) != 0)
  4278. netdev_err(dev->netdev, "Failed waiting for ref count to go to zero\n");
  4279. netdev_info(dev->netdev, "Removed CNIC device\n");
  4280. dev_put(dev->netdev);
  4281. kfree(dev);
  4282. }
  4283. static struct cnic_dev *cnic_alloc_dev(struct net_device *dev,
  4284. struct pci_dev *pdev)
  4285. {
  4286. struct cnic_dev *cdev;
  4287. struct cnic_local *cp;
  4288. int alloc_size;
  4289. alloc_size = sizeof(struct cnic_dev) + sizeof(struct cnic_local);
  4290. cdev = kzalloc(alloc_size , GFP_KERNEL);
  4291. if (cdev == NULL) {
  4292. netdev_err(dev, "allocate dev struct failure\n");
  4293. return NULL;
  4294. }
  4295. cdev->netdev = dev;
  4296. cdev->cnic_priv = (char *)cdev + sizeof(struct cnic_dev);
  4297. cdev->register_device = cnic_register_device;
  4298. cdev->unregister_device = cnic_unregister_device;
  4299. cdev->iscsi_nl_msg_recv = cnic_iscsi_nl_msg_recv;
  4300. cp = cdev->cnic_priv;
  4301. cp->dev = cdev;
  4302. cp->l2_single_buf_size = 0x400;
  4303. cp->l2_rx_ring_size = 3;
  4304. spin_lock_init(&cp->cnic_ulp_lock);
  4305. netdev_info(dev, "Added CNIC device\n");
  4306. return cdev;
  4307. }
  4308. static struct cnic_dev *init_bnx2_cnic(struct net_device *dev)
  4309. {
  4310. struct pci_dev *pdev;
  4311. struct cnic_dev *cdev;
  4312. struct cnic_local *cp;
  4313. struct cnic_eth_dev *ethdev = NULL;
  4314. struct cnic_eth_dev *(*probe)(struct net_device *) = NULL;
  4315. probe = symbol_get(bnx2_cnic_probe);
  4316. if (probe) {
  4317. ethdev = (*probe)(dev);
  4318. symbol_put(bnx2_cnic_probe);
  4319. }
  4320. if (!ethdev)
  4321. return NULL;
  4322. pdev = ethdev->pdev;
  4323. if (!pdev)
  4324. return NULL;
  4325. dev_hold(dev);
  4326. pci_dev_get(pdev);
  4327. if (pdev->device == PCI_DEVICE_ID_NX2_5709 ||
  4328. pdev->device == PCI_DEVICE_ID_NX2_5709S) {
  4329. u8 rev;
  4330. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  4331. if (rev < 0x10) {
  4332. pci_dev_put(pdev);
  4333. goto cnic_err;
  4334. }
  4335. }
  4336. pci_dev_put(pdev);
  4337. cdev = cnic_alloc_dev(dev, pdev);
  4338. if (cdev == NULL)
  4339. goto cnic_err;
  4340. set_bit(CNIC_F_BNX2_CLASS, &cdev->flags);
  4341. cdev->submit_kwqes = cnic_submit_bnx2_kwqes;
  4342. cp = cdev->cnic_priv;
  4343. cp->ethdev = ethdev;
  4344. cdev->pcidev = pdev;
  4345. cp->chip_id = ethdev->chip_id;
  4346. cp->cnic_ops = &cnic_bnx2_ops;
  4347. cp->start_hw = cnic_start_bnx2_hw;
  4348. cp->stop_hw = cnic_stop_bnx2_hw;
  4349. cp->setup_pgtbl = cnic_setup_page_tbl;
  4350. cp->alloc_resc = cnic_alloc_bnx2_resc;
  4351. cp->free_resc = cnic_free_resc;
  4352. cp->start_cm = cnic_cm_init_bnx2_hw;
  4353. cp->stop_cm = cnic_cm_stop_bnx2_hw;
  4354. cp->enable_int = cnic_enable_bnx2_int;
  4355. cp->disable_int_sync = cnic_disable_bnx2_int_sync;
  4356. cp->close_conn = cnic_close_bnx2_conn;
  4357. cp->next_idx = cnic_bnx2_next_idx;
  4358. cp->hw_idx = cnic_bnx2_hw_idx;
  4359. return cdev;
  4360. cnic_err:
  4361. dev_put(dev);
  4362. return NULL;
  4363. }
  4364. static struct cnic_dev *init_bnx2x_cnic(struct net_device *dev)
  4365. {
  4366. struct pci_dev *pdev;
  4367. struct cnic_dev *cdev;
  4368. struct cnic_local *cp;
  4369. struct cnic_eth_dev *ethdev = NULL;
  4370. struct cnic_eth_dev *(*probe)(struct net_device *) = NULL;
  4371. probe = symbol_get(bnx2x_cnic_probe);
  4372. if (probe) {
  4373. ethdev = (*probe)(dev);
  4374. symbol_put(bnx2x_cnic_probe);
  4375. }
  4376. if (!ethdev)
  4377. return NULL;
  4378. pdev = ethdev->pdev;
  4379. if (!pdev)
  4380. return NULL;
  4381. dev_hold(dev);
  4382. cdev = cnic_alloc_dev(dev, pdev);
  4383. if (cdev == NULL) {
  4384. dev_put(dev);
  4385. return NULL;
  4386. }
  4387. set_bit(CNIC_F_BNX2X_CLASS, &cdev->flags);
  4388. cdev->submit_kwqes = cnic_submit_bnx2x_kwqes;
  4389. cp = cdev->cnic_priv;
  4390. cp->ethdev = ethdev;
  4391. cdev->pcidev = pdev;
  4392. cp->chip_id = ethdev->chip_id;
  4393. cp->cnic_ops = &cnic_bnx2x_ops;
  4394. cp->start_hw = cnic_start_bnx2x_hw;
  4395. cp->stop_hw = cnic_stop_bnx2x_hw;
  4396. cp->setup_pgtbl = cnic_setup_page_tbl_le;
  4397. cp->alloc_resc = cnic_alloc_bnx2x_resc;
  4398. cp->free_resc = cnic_free_resc;
  4399. cp->start_cm = cnic_cm_init_bnx2x_hw;
  4400. cp->stop_cm = cnic_cm_stop_bnx2x_hw;
  4401. cp->enable_int = cnic_enable_bnx2x_int;
  4402. cp->disable_int_sync = cnic_disable_bnx2x_int_sync;
  4403. if (BNX2X_CHIP_IS_E2(cp->chip_id))
  4404. cp->ack_int = cnic_ack_bnx2x_e2_msix;
  4405. else
  4406. cp->ack_int = cnic_ack_bnx2x_msix;
  4407. cp->close_conn = cnic_close_bnx2x_conn;
  4408. cp->next_idx = cnic_bnx2x_next_idx;
  4409. cp->hw_idx = cnic_bnx2x_hw_idx;
  4410. return cdev;
  4411. }
  4412. static struct cnic_dev *is_cnic_dev(struct net_device *dev)
  4413. {
  4414. struct ethtool_drvinfo drvinfo;
  4415. struct cnic_dev *cdev = NULL;
  4416. if (dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) {
  4417. memset(&drvinfo, 0, sizeof(drvinfo));
  4418. dev->ethtool_ops->get_drvinfo(dev, &drvinfo);
  4419. if (!strcmp(drvinfo.driver, "bnx2"))
  4420. cdev = init_bnx2_cnic(dev);
  4421. if (!strcmp(drvinfo.driver, "bnx2x"))
  4422. cdev = init_bnx2x_cnic(dev);
  4423. if (cdev) {
  4424. write_lock(&cnic_dev_lock);
  4425. list_add(&cdev->list, &cnic_dev_list);
  4426. write_unlock(&cnic_dev_lock);
  4427. }
  4428. }
  4429. return cdev;
  4430. }
  4431. /**
  4432. * netdev event handler
  4433. */
  4434. static int cnic_netdev_event(struct notifier_block *this, unsigned long event,
  4435. void *ptr)
  4436. {
  4437. struct net_device *netdev = ptr;
  4438. struct cnic_dev *dev;
  4439. int if_type;
  4440. int new_dev = 0;
  4441. dev = cnic_from_netdev(netdev);
  4442. if (!dev && (event == NETDEV_REGISTER || event == NETDEV_UP)) {
  4443. /* Check for the hot-plug device */
  4444. dev = is_cnic_dev(netdev);
  4445. if (dev) {
  4446. new_dev = 1;
  4447. cnic_hold(dev);
  4448. }
  4449. }
  4450. if (dev) {
  4451. struct cnic_local *cp = dev->cnic_priv;
  4452. if (new_dev)
  4453. cnic_ulp_init(dev);
  4454. else if (event == NETDEV_UNREGISTER)
  4455. cnic_ulp_exit(dev);
  4456. if (event == NETDEV_UP) {
  4457. if (cnic_register_netdev(dev) != 0) {
  4458. cnic_put(dev);
  4459. goto done;
  4460. }
  4461. if (!cnic_start_hw(dev))
  4462. cnic_ulp_start(dev);
  4463. }
  4464. rcu_read_lock();
  4465. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  4466. struct cnic_ulp_ops *ulp_ops;
  4467. void *ctx;
  4468. ulp_ops = rcu_dereference(cp->ulp_ops[if_type]);
  4469. if (!ulp_ops || !ulp_ops->indicate_netevent)
  4470. continue;
  4471. ctx = cp->ulp_handle[if_type];
  4472. ulp_ops->indicate_netevent(ctx, event);
  4473. }
  4474. rcu_read_unlock();
  4475. if (event == NETDEV_GOING_DOWN) {
  4476. cnic_ulp_stop(dev);
  4477. cnic_stop_hw(dev);
  4478. cnic_unregister_netdev(dev);
  4479. } else if (event == NETDEV_UNREGISTER) {
  4480. write_lock(&cnic_dev_lock);
  4481. list_del_init(&dev->list);
  4482. write_unlock(&cnic_dev_lock);
  4483. cnic_put(dev);
  4484. cnic_free_dev(dev);
  4485. goto done;
  4486. }
  4487. cnic_put(dev);
  4488. }
  4489. done:
  4490. return NOTIFY_DONE;
  4491. }
  4492. static struct notifier_block cnic_netdev_notifier = {
  4493. .notifier_call = cnic_netdev_event
  4494. };
  4495. static void cnic_release(void)
  4496. {
  4497. struct cnic_dev *dev;
  4498. struct cnic_uio_dev *udev;
  4499. while (!list_empty(&cnic_dev_list)) {
  4500. dev = list_entry(cnic_dev_list.next, struct cnic_dev, list);
  4501. if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) {
  4502. cnic_ulp_stop(dev);
  4503. cnic_stop_hw(dev);
  4504. }
  4505. cnic_ulp_exit(dev);
  4506. cnic_unregister_netdev(dev);
  4507. list_del_init(&dev->list);
  4508. cnic_free_dev(dev);
  4509. }
  4510. while (!list_empty(&cnic_udev_list)) {
  4511. udev = list_entry(cnic_udev_list.next, struct cnic_uio_dev,
  4512. list);
  4513. cnic_free_uio(udev);
  4514. }
  4515. }
  4516. static int __init cnic_init(void)
  4517. {
  4518. int rc = 0;
  4519. pr_info("%s", version);
  4520. rc = register_netdevice_notifier(&cnic_netdev_notifier);
  4521. if (rc) {
  4522. cnic_release();
  4523. return rc;
  4524. }
  4525. cnic_wq = create_singlethread_workqueue("cnic_wq");
  4526. if (!cnic_wq) {
  4527. cnic_release();
  4528. unregister_netdevice_notifier(&cnic_netdev_notifier);
  4529. return -ENOMEM;
  4530. }
  4531. return 0;
  4532. }
  4533. static void __exit cnic_exit(void)
  4534. {
  4535. unregister_netdevice_notifier(&cnic_netdev_notifier);
  4536. cnic_release();
  4537. destroy_workqueue(cnic_wq);
  4538. }
  4539. module_init(cnic_init);
  4540. module_exit(cnic_exit);