cnic.c 140 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518
  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. u16 type_16;
  1056. int ret;
  1057. kwqe.hdr.conn_and_cmd_data =
  1058. cpu_to_le32(((cmd << SPE_HDR_CMD_ID_SHIFT) |
  1059. BNX2X_HW_CID(cp, cid)));
  1060. type_16 = (type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  1061. type_16 |= (cp->pfid << SPE_HDR_FUNCTION_ID_SHIFT) &
  1062. SPE_HDR_FUNCTION_ID;
  1063. kwqe.hdr.type = cpu_to_le16(type_16);
  1064. kwqe.hdr.reserved1 = 0;
  1065. kwqe.data.phy_address.lo = cpu_to_le32(l5_data->phy_address.lo);
  1066. kwqe.data.phy_address.hi = cpu_to_le32(l5_data->phy_address.hi);
  1067. kwq[0] = (struct kwqe_16 *) &kwqe;
  1068. spin_lock_bh(&cp->cnic_ulp_lock);
  1069. ret = cp->ethdev->drv_submit_kwqes_16(dev->netdev, kwq, 1);
  1070. spin_unlock_bh(&cp->cnic_ulp_lock);
  1071. if (ret == 1)
  1072. return 0;
  1073. return -EBUSY;
  1074. }
  1075. static void cnic_reply_bnx2x_kcqes(struct cnic_dev *dev, int ulp_type,
  1076. struct kcqe *cqes[], u32 num_cqes)
  1077. {
  1078. struct cnic_local *cp = dev->cnic_priv;
  1079. struct cnic_ulp_ops *ulp_ops;
  1080. rcu_read_lock();
  1081. ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
  1082. if (likely(ulp_ops)) {
  1083. ulp_ops->indicate_kcqes(cp->ulp_handle[ulp_type],
  1084. cqes, num_cqes);
  1085. }
  1086. rcu_read_unlock();
  1087. }
  1088. static int cnic_bnx2x_iscsi_init1(struct cnic_dev *dev, struct kwqe *kwqe)
  1089. {
  1090. struct cnic_local *cp = dev->cnic_priv;
  1091. struct iscsi_kwqe_init1 *req1 = (struct iscsi_kwqe_init1 *) kwqe;
  1092. int hq_bds, pages;
  1093. u32 pfid = cp->pfid;
  1094. cp->num_iscsi_tasks = req1->num_tasks_per_conn;
  1095. cp->num_ccells = req1->num_ccells_per_conn;
  1096. cp->task_array_size = BNX2X_ISCSI_TASK_CONTEXT_SIZE *
  1097. cp->num_iscsi_tasks;
  1098. cp->r2tq_size = cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS *
  1099. BNX2X_ISCSI_R2TQE_SIZE;
  1100. cp->hq_size = cp->num_ccells * BNX2X_ISCSI_HQ_BD_SIZE;
  1101. pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE;
  1102. hq_bds = pages * (PAGE_SIZE / BNX2X_ISCSI_HQ_BD_SIZE);
  1103. cp->num_cqs = req1->num_cqs;
  1104. if (!dev->max_iscsi_conn)
  1105. return 0;
  1106. /* init Tstorm RAM */
  1107. CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_RQ_SIZE_OFFSET(pfid),
  1108. req1->rq_num_wqes);
  1109. CNIC_WR16(dev, BAR_TSTRORM_INTMEM + TSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
  1110. PAGE_SIZE);
  1111. CNIC_WR8(dev, BAR_TSTRORM_INTMEM +
  1112. TSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT);
  1113. CNIC_WR16(dev, BAR_TSTRORM_INTMEM +
  1114. TSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
  1115. req1->num_tasks_per_conn);
  1116. /* init Ustorm RAM */
  1117. CNIC_WR16(dev, BAR_USTRORM_INTMEM +
  1118. USTORM_ISCSI_RQ_BUFFER_SIZE_OFFSET(pfid),
  1119. req1->rq_buffer_size);
  1120. CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
  1121. PAGE_SIZE);
  1122. CNIC_WR8(dev, BAR_USTRORM_INTMEM +
  1123. USTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT);
  1124. CNIC_WR16(dev, BAR_USTRORM_INTMEM +
  1125. USTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
  1126. req1->num_tasks_per_conn);
  1127. CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_RQ_SIZE_OFFSET(pfid),
  1128. req1->rq_num_wqes);
  1129. CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_CQ_SIZE_OFFSET(pfid),
  1130. req1->cq_num_wqes);
  1131. CNIC_WR16(dev, BAR_USTRORM_INTMEM + USTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid),
  1132. cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS);
  1133. /* init Xstorm RAM */
  1134. CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
  1135. PAGE_SIZE);
  1136. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  1137. XSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT);
  1138. CNIC_WR16(dev, BAR_XSTRORM_INTMEM +
  1139. XSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
  1140. req1->num_tasks_per_conn);
  1141. CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_HQ_SIZE_OFFSET(pfid),
  1142. hq_bds);
  1143. CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_SQ_SIZE_OFFSET(pfid),
  1144. req1->num_tasks_per_conn);
  1145. CNIC_WR16(dev, BAR_XSTRORM_INTMEM + XSTORM_ISCSI_R2TQ_SIZE_OFFSET(pfid),
  1146. cp->num_iscsi_tasks * BNX2X_ISCSI_MAX_PENDING_R2TS);
  1147. /* init Cstorm RAM */
  1148. CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_PAGE_SIZE_OFFSET(pfid),
  1149. PAGE_SIZE);
  1150. CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
  1151. CSTORM_ISCSI_PAGE_SIZE_LOG_OFFSET(pfid), PAGE_SHIFT);
  1152. CNIC_WR16(dev, BAR_CSTRORM_INTMEM +
  1153. CSTORM_ISCSI_NUM_OF_TASKS_OFFSET(pfid),
  1154. req1->num_tasks_per_conn);
  1155. CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_CQ_SIZE_OFFSET(pfid),
  1156. req1->cq_num_wqes);
  1157. CNIC_WR16(dev, BAR_CSTRORM_INTMEM + CSTORM_ISCSI_HQ_SIZE_OFFSET(pfid),
  1158. hq_bds);
  1159. return 0;
  1160. }
  1161. static int cnic_bnx2x_iscsi_init2(struct cnic_dev *dev, struct kwqe *kwqe)
  1162. {
  1163. struct iscsi_kwqe_init2 *req2 = (struct iscsi_kwqe_init2 *) kwqe;
  1164. struct cnic_local *cp = dev->cnic_priv;
  1165. u32 pfid = cp->pfid;
  1166. struct iscsi_kcqe kcqe;
  1167. struct kcqe *cqes[1];
  1168. memset(&kcqe, 0, sizeof(kcqe));
  1169. if (!dev->max_iscsi_conn) {
  1170. kcqe.completion_status =
  1171. ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED;
  1172. goto done;
  1173. }
  1174. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  1175. TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid), req2->error_bit_map[0]);
  1176. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  1177. TSTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid) + 4,
  1178. req2->error_bit_map[1]);
  1179. CNIC_WR16(dev, BAR_USTRORM_INTMEM +
  1180. USTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid), req2->max_cq_sqn);
  1181. CNIC_WR(dev, BAR_USTRORM_INTMEM +
  1182. USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid), req2->error_bit_map[0]);
  1183. CNIC_WR(dev, BAR_USTRORM_INTMEM +
  1184. USTORM_ISCSI_ERROR_BITMAP_OFFSET(pfid) + 4,
  1185. req2->error_bit_map[1]);
  1186. CNIC_WR16(dev, BAR_CSTRORM_INTMEM +
  1187. CSTORM_ISCSI_CQ_SQN_SIZE_OFFSET(pfid), req2->max_cq_sqn);
  1188. kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_SUCCESS;
  1189. done:
  1190. kcqe.op_code = ISCSI_KCQE_OPCODE_INIT;
  1191. cqes[0] = (struct kcqe *) &kcqe;
  1192. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_ISCSI, cqes, 1);
  1193. return 0;
  1194. }
  1195. static void cnic_free_bnx2x_conn_resc(struct cnic_dev *dev, u32 l5_cid)
  1196. {
  1197. struct cnic_local *cp = dev->cnic_priv;
  1198. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1199. if (ctx->ulp_proto_id == CNIC_ULP_ISCSI) {
  1200. struct cnic_iscsi *iscsi = ctx->proto.iscsi;
  1201. cnic_free_dma(dev, &iscsi->hq_info);
  1202. cnic_free_dma(dev, &iscsi->r2tq_info);
  1203. cnic_free_dma(dev, &iscsi->task_array_info);
  1204. cnic_free_id(&cp->cid_tbl, ctx->cid);
  1205. } else {
  1206. cnic_free_id(&cp->fcoe_cid_tbl, ctx->cid);
  1207. }
  1208. ctx->cid = 0;
  1209. }
  1210. static int cnic_alloc_bnx2x_conn_resc(struct cnic_dev *dev, u32 l5_cid)
  1211. {
  1212. u32 cid;
  1213. int ret, pages;
  1214. struct cnic_local *cp = dev->cnic_priv;
  1215. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1216. struct cnic_iscsi *iscsi = ctx->proto.iscsi;
  1217. if (ctx->ulp_proto_id == CNIC_ULP_FCOE) {
  1218. cid = cnic_alloc_new_id(&cp->fcoe_cid_tbl);
  1219. if (cid == -1) {
  1220. ret = -ENOMEM;
  1221. goto error;
  1222. }
  1223. ctx->cid = cid;
  1224. return 0;
  1225. }
  1226. cid = cnic_alloc_new_id(&cp->cid_tbl);
  1227. if (cid == -1) {
  1228. ret = -ENOMEM;
  1229. goto error;
  1230. }
  1231. ctx->cid = cid;
  1232. pages = PAGE_ALIGN(cp->task_array_size) / PAGE_SIZE;
  1233. ret = cnic_alloc_dma(dev, &iscsi->task_array_info, pages, 1);
  1234. if (ret)
  1235. goto error;
  1236. pages = PAGE_ALIGN(cp->r2tq_size) / PAGE_SIZE;
  1237. ret = cnic_alloc_dma(dev, &iscsi->r2tq_info, pages, 1);
  1238. if (ret)
  1239. goto error;
  1240. pages = PAGE_ALIGN(cp->hq_size) / PAGE_SIZE;
  1241. ret = cnic_alloc_dma(dev, &iscsi->hq_info, pages, 1);
  1242. if (ret)
  1243. goto error;
  1244. return 0;
  1245. error:
  1246. cnic_free_bnx2x_conn_resc(dev, l5_cid);
  1247. return ret;
  1248. }
  1249. static void *cnic_get_bnx2x_ctx(struct cnic_dev *dev, u32 cid, int init,
  1250. struct regpair *ctx_addr)
  1251. {
  1252. struct cnic_local *cp = dev->cnic_priv;
  1253. struct cnic_eth_dev *ethdev = cp->ethdev;
  1254. int blk = (cid - ethdev->starting_cid) / cp->cids_per_blk;
  1255. int off = (cid - ethdev->starting_cid) % cp->cids_per_blk;
  1256. unsigned long align_off = 0;
  1257. dma_addr_t ctx_map;
  1258. void *ctx;
  1259. if (cp->ctx_align) {
  1260. unsigned long mask = cp->ctx_align - 1;
  1261. if (cp->ctx_arr[blk].mapping & mask)
  1262. align_off = cp->ctx_align -
  1263. (cp->ctx_arr[blk].mapping & mask);
  1264. }
  1265. ctx_map = cp->ctx_arr[blk].mapping + align_off +
  1266. (off * BNX2X_CONTEXT_MEM_SIZE);
  1267. ctx = cp->ctx_arr[blk].ctx + align_off +
  1268. (off * BNX2X_CONTEXT_MEM_SIZE);
  1269. if (init)
  1270. memset(ctx, 0, BNX2X_CONTEXT_MEM_SIZE);
  1271. ctx_addr->lo = ctx_map & 0xffffffff;
  1272. ctx_addr->hi = (u64) ctx_map >> 32;
  1273. return ctx;
  1274. }
  1275. static int cnic_setup_bnx2x_ctx(struct cnic_dev *dev, struct kwqe *wqes[],
  1276. u32 num)
  1277. {
  1278. struct cnic_local *cp = dev->cnic_priv;
  1279. struct iscsi_kwqe_conn_offload1 *req1 =
  1280. (struct iscsi_kwqe_conn_offload1 *) wqes[0];
  1281. struct iscsi_kwqe_conn_offload2 *req2 =
  1282. (struct iscsi_kwqe_conn_offload2 *) wqes[1];
  1283. struct iscsi_kwqe_conn_offload3 *req3;
  1284. struct cnic_context *ctx = &cp->ctx_tbl[req1->iscsi_conn_id];
  1285. struct cnic_iscsi *iscsi = ctx->proto.iscsi;
  1286. u32 cid = ctx->cid;
  1287. u32 hw_cid = BNX2X_HW_CID(cp, cid);
  1288. struct iscsi_context *ictx;
  1289. struct regpair context_addr;
  1290. int i, j, n = 2, n_max;
  1291. ctx->ctx_flags = 0;
  1292. if (!req2->num_additional_wqes)
  1293. return -EINVAL;
  1294. n_max = req2->num_additional_wqes + 2;
  1295. ictx = cnic_get_bnx2x_ctx(dev, cid, 1, &context_addr);
  1296. if (ictx == NULL)
  1297. return -ENOMEM;
  1298. req3 = (struct iscsi_kwqe_conn_offload3 *) wqes[n++];
  1299. ictx->xstorm_ag_context.hq_prod = 1;
  1300. ictx->xstorm_st_context.iscsi.first_burst_length =
  1301. ISCSI_DEF_FIRST_BURST_LEN;
  1302. ictx->xstorm_st_context.iscsi.max_send_pdu_length =
  1303. ISCSI_DEF_MAX_RECV_SEG_LEN;
  1304. ictx->xstorm_st_context.iscsi.sq_pbl_base.lo =
  1305. req1->sq_page_table_addr_lo;
  1306. ictx->xstorm_st_context.iscsi.sq_pbl_base.hi =
  1307. req1->sq_page_table_addr_hi;
  1308. ictx->xstorm_st_context.iscsi.sq_curr_pbe.lo = req2->sq_first_pte.hi;
  1309. ictx->xstorm_st_context.iscsi.sq_curr_pbe.hi = req2->sq_first_pte.lo;
  1310. ictx->xstorm_st_context.iscsi.hq_pbl_base.lo =
  1311. iscsi->hq_info.pgtbl_map & 0xffffffff;
  1312. ictx->xstorm_st_context.iscsi.hq_pbl_base.hi =
  1313. (u64) iscsi->hq_info.pgtbl_map >> 32;
  1314. ictx->xstorm_st_context.iscsi.hq_curr_pbe_base.lo =
  1315. iscsi->hq_info.pgtbl[0];
  1316. ictx->xstorm_st_context.iscsi.hq_curr_pbe_base.hi =
  1317. iscsi->hq_info.pgtbl[1];
  1318. ictx->xstorm_st_context.iscsi.r2tq_pbl_base.lo =
  1319. iscsi->r2tq_info.pgtbl_map & 0xffffffff;
  1320. ictx->xstorm_st_context.iscsi.r2tq_pbl_base.hi =
  1321. (u64) iscsi->r2tq_info.pgtbl_map >> 32;
  1322. ictx->xstorm_st_context.iscsi.r2tq_curr_pbe_base.lo =
  1323. iscsi->r2tq_info.pgtbl[0];
  1324. ictx->xstorm_st_context.iscsi.r2tq_curr_pbe_base.hi =
  1325. iscsi->r2tq_info.pgtbl[1];
  1326. ictx->xstorm_st_context.iscsi.task_pbl_base.lo =
  1327. iscsi->task_array_info.pgtbl_map & 0xffffffff;
  1328. ictx->xstorm_st_context.iscsi.task_pbl_base.hi =
  1329. (u64) iscsi->task_array_info.pgtbl_map >> 32;
  1330. ictx->xstorm_st_context.iscsi.task_pbl_cache_idx =
  1331. BNX2X_ISCSI_PBL_NOT_CACHED;
  1332. ictx->xstorm_st_context.iscsi.flags.flags |=
  1333. XSTORM_ISCSI_CONTEXT_FLAGS_B_IMMEDIATE_DATA;
  1334. ictx->xstorm_st_context.iscsi.flags.flags |=
  1335. XSTORM_ISCSI_CONTEXT_FLAGS_B_INITIAL_R2T;
  1336. ictx->tstorm_st_context.iscsi.hdr_bytes_2_fetch = ISCSI_HEADER_SIZE;
  1337. /* TSTORM requires the base address of RQ DB & not PTE */
  1338. ictx->tstorm_st_context.iscsi.rq_db_phy_addr.lo =
  1339. req2->rq_page_table_addr_lo & PAGE_MASK;
  1340. ictx->tstorm_st_context.iscsi.rq_db_phy_addr.hi =
  1341. req2->rq_page_table_addr_hi;
  1342. ictx->tstorm_st_context.iscsi.iscsi_conn_id = req1->iscsi_conn_id;
  1343. ictx->tstorm_st_context.tcp.cwnd = 0x5A8;
  1344. ictx->tstorm_st_context.tcp.flags2 |=
  1345. TSTORM_TCP_ST_CONTEXT_SECTION_DA_EN;
  1346. ictx->tstorm_st_context.tcp.ooo_support_mode =
  1347. TCP_TSTORM_OOO_DROP_AND_PROC_ACK;
  1348. ictx->timers_context.flags |= TIMERS_BLOCK_CONTEXT_CONN_VALID_FLG;
  1349. ictx->ustorm_st_context.ring.rq.pbl_base.lo =
  1350. req2->rq_page_table_addr_lo;
  1351. ictx->ustorm_st_context.ring.rq.pbl_base.hi =
  1352. req2->rq_page_table_addr_hi;
  1353. ictx->ustorm_st_context.ring.rq.curr_pbe.lo = req3->qp_first_pte[0].hi;
  1354. ictx->ustorm_st_context.ring.rq.curr_pbe.hi = req3->qp_first_pte[0].lo;
  1355. ictx->ustorm_st_context.ring.r2tq.pbl_base.lo =
  1356. iscsi->r2tq_info.pgtbl_map & 0xffffffff;
  1357. ictx->ustorm_st_context.ring.r2tq.pbl_base.hi =
  1358. (u64) iscsi->r2tq_info.pgtbl_map >> 32;
  1359. ictx->ustorm_st_context.ring.r2tq.curr_pbe.lo =
  1360. iscsi->r2tq_info.pgtbl[0];
  1361. ictx->ustorm_st_context.ring.r2tq.curr_pbe.hi =
  1362. iscsi->r2tq_info.pgtbl[1];
  1363. ictx->ustorm_st_context.ring.cq_pbl_base.lo =
  1364. req1->cq_page_table_addr_lo;
  1365. ictx->ustorm_st_context.ring.cq_pbl_base.hi =
  1366. req1->cq_page_table_addr_hi;
  1367. ictx->ustorm_st_context.ring.cq[0].cq_sn = ISCSI_INITIAL_SN;
  1368. ictx->ustorm_st_context.ring.cq[0].curr_pbe.lo = req2->cq_first_pte.hi;
  1369. ictx->ustorm_st_context.ring.cq[0].curr_pbe.hi = req2->cq_first_pte.lo;
  1370. ictx->ustorm_st_context.task_pbe_cache_index =
  1371. BNX2X_ISCSI_PBL_NOT_CACHED;
  1372. ictx->ustorm_st_context.task_pdu_cache_index =
  1373. BNX2X_ISCSI_PDU_HEADER_NOT_CACHED;
  1374. for (i = 1, j = 1; i < cp->num_cqs; i++, j++) {
  1375. if (j == 3) {
  1376. if (n >= n_max)
  1377. break;
  1378. req3 = (struct iscsi_kwqe_conn_offload3 *) wqes[n++];
  1379. j = 0;
  1380. }
  1381. ictx->ustorm_st_context.ring.cq[i].cq_sn = ISCSI_INITIAL_SN;
  1382. ictx->ustorm_st_context.ring.cq[i].curr_pbe.lo =
  1383. req3->qp_first_pte[j].hi;
  1384. ictx->ustorm_st_context.ring.cq[i].curr_pbe.hi =
  1385. req3->qp_first_pte[j].lo;
  1386. }
  1387. ictx->ustorm_st_context.task_pbl_base.lo =
  1388. iscsi->task_array_info.pgtbl_map & 0xffffffff;
  1389. ictx->ustorm_st_context.task_pbl_base.hi =
  1390. (u64) iscsi->task_array_info.pgtbl_map >> 32;
  1391. ictx->ustorm_st_context.tce_phy_addr.lo =
  1392. iscsi->task_array_info.pgtbl[0];
  1393. ictx->ustorm_st_context.tce_phy_addr.hi =
  1394. iscsi->task_array_info.pgtbl[1];
  1395. ictx->ustorm_st_context.iscsi_conn_id = req1->iscsi_conn_id;
  1396. ictx->ustorm_st_context.num_cqs = cp->num_cqs;
  1397. ictx->ustorm_st_context.negotiated_rx |= ISCSI_DEF_MAX_RECV_SEG_LEN;
  1398. ictx->ustorm_st_context.negotiated_rx_and_flags |=
  1399. ISCSI_DEF_MAX_BURST_LEN;
  1400. ictx->ustorm_st_context.negotiated_rx |=
  1401. ISCSI_DEFAULT_MAX_OUTSTANDING_R2T <<
  1402. USTORM_ISCSI_ST_CONTEXT_MAX_OUTSTANDING_R2TS_SHIFT;
  1403. ictx->cstorm_st_context.hq_pbl_base.lo =
  1404. iscsi->hq_info.pgtbl_map & 0xffffffff;
  1405. ictx->cstorm_st_context.hq_pbl_base.hi =
  1406. (u64) iscsi->hq_info.pgtbl_map >> 32;
  1407. ictx->cstorm_st_context.hq_curr_pbe.lo = iscsi->hq_info.pgtbl[0];
  1408. ictx->cstorm_st_context.hq_curr_pbe.hi = iscsi->hq_info.pgtbl[1];
  1409. ictx->cstorm_st_context.task_pbl_base.lo =
  1410. iscsi->task_array_info.pgtbl_map & 0xffffffff;
  1411. ictx->cstorm_st_context.task_pbl_base.hi =
  1412. (u64) iscsi->task_array_info.pgtbl_map >> 32;
  1413. /* CSTORM and USTORM initialization is different, CSTORM requires
  1414. * CQ DB base & not PTE addr */
  1415. ictx->cstorm_st_context.cq_db_base.lo =
  1416. req1->cq_page_table_addr_lo & PAGE_MASK;
  1417. ictx->cstorm_st_context.cq_db_base.hi = req1->cq_page_table_addr_hi;
  1418. ictx->cstorm_st_context.iscsi_conn_id = req1->iscsi_conn_id;
  1419. ictx->cstorm_st_context.cq_proc_en_bit_map = (1 << cp->num_cqs) - 1;
  1420. for (i = 0; i < cp->num_cqs; i++) {
  1421. ictx->cstorm_st_context.cq_c_prod_sqn_arr.sqn[i] =
  1422. ISCSI_INITIAL_SN;
  1423. ictx->cstorm_st_context.cq_c_sqn_2_notify_arr.sqn[i] =
  1424. ISCSI_INITIAL_SN;
  1425. }
  1426. ictx->xstorm_ag_context.cdu_reserved =
  1427. CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_XCM_AG,
  1428. ISCSI_CONNECTION_TYPE);
  1429. ictx->ustorm_ag_context.cdu_usage =
  1430. CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_UCM_AG,
  1431. ISCSI_CONNECTION_TYPE);
  1432. return 0;
  1433. }
  1434. static int cnic_bnx2x_iscsi_ofld1(struct cnic_dev *dev, struct kwqe *wqes[],
  1435. u32 num, int *work)
  1436. {
  1437. struct iscsi_kwqe_conn_offload1 *req1;
  1438. struct iscsi_kwqe_conn_offload2 *req2;
  1439. struct cnic_local *cp = dev->cnic_priv;
  1440. struct cnic_context *ctx;
  1441. struct iscsi_kcqe kcqe;
  1442. struct kcqe *cqes[1];
  1443. u32 l5_cid;
  1444. int ret = 0;
  1445. if (num < 2) {
  1446. *work = num;
  1447. return -EINVAL;
  1448. }
  1449. req1 = (struct iscsi_kwqe_conn_offload1 *) wqes[0];
  1450. req2 = (struct iscsi_kwqe_conn_offload2 *) wqes[1];
  1451. if ((num - 2) < req2->num_additional_wqes) {
  1452. *work = num;
  1453. return -EINVAL;
  1454. }
  1455. *work = 2 + req2->num_additional_wqes;
  1456. l5_cid = req1->iscsi_conn_id;
  1457. if (l5_cid >= MAX_ISCSI_TBL_SZ)
  1458. return -EINVAL;
  1459. memset(&kcqe, 0, sizeof(kcqe));
  1460. kcqe.op_code = ISCSI_KCQE_OPCODE_OFFLOAD_CONN;
  1461. kcqe.iscsi_conn_id = l5_cid;
  1462. kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE;
  1463. ctx = &cp->ctx_tbl[l5_cid];
  1464. if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags)) {
  1465. kcqe.completion_status =
  1466. ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY;
  1467. goto done;
  1468. }
  1469. if (atomic_inc_return(&cp->iscsi_conn) > dev->max_iscsi_conn) {
  1470. atomic_dec(&cp->iscsi_conn);
  1471. goto done;
  1472. }
  1473. ret = cnic_alloc_bnx2x_conn_resc(dev, l5_cid);
  1474. if (ret) {
  1475. atomic_dec(&cp->iscsi_conn);
  1476. ret = 0;
  1477. goto done;
  1478. }
  1479. ret = cnic_setup_bnx2x_ctx(dev, wqes, num);
  1480. if (ret < 0) {
  1481. cnic_free_bnx2x_conn_resc(dev, l5_cid);
  1482. atomic_dec(&cp->iscsi_conn);
  1483. goto done;
  1484. }
  1485. kcqe.completion_status = ISCSI_KCQE_COMPLETION_STATUS_SUCCESS;
  1486. kcqe.iscsi_conn_context_id = BNX2X_HW_CID(cp, cp->ctx_tbl[l5_cid].cid);
  1487. done:
  1488. cqes[0] = (struct kcqe *) &kcqe;
  1489. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_ISCSI, cqes, 1);
  1490. return ret;
  1491. }
  1492. static int cnic_bnx2x_iscsi_update(struct cnic_dev *dev, struct kwqe *kwqe)
  1493. {
  1494. struct cnic_local *cp = dev->cnic_priv;
  1495. struct iscsi_kwqe_conn_update *req =
  1496. (struct iscsi_kwqe_conn_update *) kwqe;
  1497. void *data;
  1498. union l5cm_specific_data l5_data;
  1499. u32 l5_cid, cid = BNX2X_SW_CID(req->context_id);
  1500. int ret;
  1501. if (cnic_get_l5_cid(cp, cid, &l5_cid) != 0)
  1502. return -EINVAL;
  1503. data = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1504. if (!data)
  1505. return -ENOMEM;
  1506. memcpy(data, kwqe, sizeof(struct kwqe));
  1507. ret = cnic_submit_kwqe_16(dev, ISCSI_RAMROD_CMD_ID_UPDATE_CONN,
  1508. req->context_id, ISCSI_CONNECTION_TYPE, &l5_data);
  1509. return ret;
  1510. }
  1511. static int cnic_bnx2x_destroy_ramrod(struct cnic_dev *dev, u32 l5_cid)
  1512. {
  1513. struct cnic_local *cp = dev->cnic_priv;
  1514. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  1515. union l5cm_specific_data l5_data;
  1516. int ret;
  1517. u32 hw_cid;
  1518. init_waitqueue_head(&ctx->waitq);
  1519. ctx->wait_cond = 0;
  1520. memset(&l5_data, 0, sizeof(l5_data));
  1521. hw_cid = BNX2X_HW_CID(cp, ctx->cid);
  1522. ret = cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_COMMON_CFC_DEL,
  1523. hw_cid, NONE_CONNECTION_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. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_INIT, cid,
  1837. FCOE_CONNECTION_TYPE, &l5_data);
  1838. *work = 3;
  1839. return ret;
  1840. }
  1841. static int cnic_bnx2x_fcoe_ofld1(struct cnic_dev *dev, struct kwqe *wqes[],
  1842. u32 num, int *work)
  1843. {
  1844. int ret = 0;
  1845. u32 cid = -1, l5_cid;
  1846. struct cnic_local *cp = dev->cnic_priv;
  1847. struct fcoe_kwqe_conn_offload1 *req1;
  1848. struct fcoe_kwqe_conn_offload2 *req2;
  1849. struct fcoe_kwqe_conn_offload3 *req3;
  1850. struct fcoe_kwqe_conn_offload4 *req4;
  1851. struct fcoe_conn_offload_ramrod_params *fcoe_offload;
  1852. struct cnic_context *ctx;
  1853. struct fcoe_context *fctx;
  1854. struct regpair ctx_addr;
  1855. union l5cm_specific_data l5_data;
  1856. struct fcoe_kcqe kcqe;
  1857. struct kcqe *cqes[1];
  1858. if (num < 4) {
  1859. *work = num;
  1860. return -EINVAL;
  1861. }
  1862. req1 = (struct fcoe_kwqe_conn_offload1 *) wqes[0];
  1863. req2 = (struct fcoe_kwqe_conn_offload2 *) wqes[1];
  1864. req3 = (struct fcoe_kwqe_conn_offload3 *) wqes[2];
  1865. req4 = (struct fcoe_kwqe_conn_offload4 *) wqes[3];
  1866. *work = 4;
  1867. l5_cid = req1->fcoe_conn_id;
  1868. if (l5_cid >= BNX2X_FCOE_NUM_CONNECTIONS)
  1869. goto err_reply;
  1870. l5_cid += BNX2X_FCOE_L5_CID_BASE;
  1871. ctx = &cp->ctx_tbl[l5_cid];
  1872. if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags))
  1873. goto err_reply;
  1874. ret = cnic_alloc_bnx2x_conn_resc(dev, l5_cid);
  1875. if (ret) {
  1876. ret = 0;
  1877. goto err_reply;
  1878. }
  1879. cid = ctx->cid;
  1880. fctx = cnic_get_bnx2x_ctx(dev, cid, 1, &ctx_addr);
  1881. if (fctx) {
  1882. u32 hw_cid = BNX2X_HW_CID(cp, cid);
  1883. u32 val;
  1884. val = CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_XCM_AG,
  1885. FCOE_CONNECTION_TYPE);
  1886. fctx->xstorm_ag_context.cdu_reserved = val;
  1887. val = CDU_RSRVD_VALUE_TYPE_A(hw_cid, CDU_REGION_NUMBER_UCM_AG,
  1888. FCOE_CONNECTION_TYPE);
  1889. fctx->ustorm_ag_context.cdu_usage = val;
  1890. }
  1891. if (sizeof(*fcoe_offload) > CNIC_KWQ16_DATA_SIZE) {
  1892. netdev_err(dev->netdev, "fcoe_offload size too big\n");
  1893. goto err_reply;
  1894. }
  1895. fcoe_offload = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1896. if (!fcoe_offload)
  1897. goto err_reply;
  1898. memset(fcoe_offload, 0, sizeof(*fcoe_offload));
  1899. memcpy(&fcoe_offload->offload_kwqe1, req1, sizeof(*req1));
  1900. memcpy(&fcoe_offload->offload_kwqe2, req2, sizeof(*req2));
  1901. memcpy(&fcoe_offload->offload_kwqe3, req3, sizeof(*req3));
  1902. memcpy(&fcoe_offload->offload_kwqe4, req4, sizeof(*req4));
  1903. cid = BNX2X_HW_CID(cp, cid);
  1904. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_OFFLOAD_CONN, cid,
  1905. FCOE_CONNECTION_TYPE, &l5_data);
  1906. if (!ret)
  1907. set_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags);
  1908. return ret;
  1909. err_reply:
  1910. if (cid != -1)
  1911. cnic_free_bnx2x_conn_resc(dev, l5_cid);
  1912. memset(&kcqe, 0, sizeof(kcqe));
  1913. kcqe.op_code = FCOE_KCQE_OPCODE_OFFLOAD_CONN;
  1914. kcqe.fcoe_conn_id = req1->fcoe_conn_id;
  1915. kcqe.completion_status = FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE;
  1916. cqes[0] = (struct kcqe *) &kcqe;
  1917. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_FCOE, cqes, 1);
  1918. return ret;
  1919. }
  1920. static int cnic_bnx2x_fcoe_enable(struct cnic_dev *dev, struct kwqe *kwqe)
  1921. {
  1922. struct fcoe_kwqe_conn_enable_disable *req;
  1923. struct fcoe_conn_enable_disable_ramrod_params *fcoe_enable;
  1924. union l5cm_specific_data l5_data;
  1925. int ret;
  1926. u32 cid, l5_cid;
  1927. struct cnic_local *cp = dev->cnic_priv;
  1928. req = (struct fcoe_kwqe_conn_enable_disable *) kwqe;
  1929. cid = req->context_id;
  1930. l5_cid = req->conn_id + BNX2X_FCOE_L5_CID_BASE;
  1931. if (sizeof(*fcoe_enable) > CNIC_KWQ16_DATA_SIZE) {
  1932. netdev_err(dev->netdev, "fcoe_enable size too big\n");
  1933. return -ENOMEM;
  1934. }
  1935. fcoe_enable = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1936. if (!fcoe_enable)
  1937. return -ENOMEM;
  1938. memset(fcoe_enable, 0, sizeof(*fcoe_enable));
  1939. memcpy(&fcoe_enable->enable_disable_kwqe, req, sizeof(*req));
  1940. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_ENABLE_CONN, cid,
  1941. FCOE_CONNECTION_TYPE, &l5_data);
  1942. return ret;
  1943. }
  1944. static int cnic_bnx2x_fcoe_disable(struct cnic_dev *dev, struct kwqe *kwqe)
  1945. {
  1946. struct fcoe_kwqe_conn_enable_disable *req;
  1947. struct fcoe_conn_enable_disable_ramrod_params *fcoe_disable;
  1948. union l5cm_specific_data l5_data;
  1949. int ret;
  1950. u32 cid, l5_cid;
  1951. struct cnic_local *cp = dev->cnic_priv;
  1952. req = (struct fcoe_kwqe_conn_enable_disable *) kwqe;
  1953. cid = req->context_id;
  1954. l5_cid = req->conn_id;
  1955. if (l5_cid >= BNX2X_FCOE_NUM_CONNECTIONS)
  1956. return -EINVAL;
  1957. l5_cid += BNX2X_FCOE_L5_CID_BASE;
  1958. if (sizeof(*fcoe_disable) > CNIC_KWQ16_DATA_SIZE) {
  1959. netdev_err(dev->netdev, "fcoe_disable size too big\n");
  1960. return -ENOMEM;
  1961. }
  1962. fcoe_disable = cnic_get_kwqe_16_data(cp, l5_cid, &l5_data);
  1963. if (!fcoe_disable)
  1964. return -ENOMEM;
  1965. memset(fcoe_disable, 0, sizeof(*fcoe_disable));
  1966. memcpy(&fcoe_disable->enable_disable_kwqe, req, sizeof(*req));
  1967. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_DISABLE_CONN, cid,
  1968. FCOE_CONNECTION_TYPE, &l5_data);
  1969. return ret;
  1970. }
  1971. static int cnic_bnx2x_fcoe_destroy(struct cnic_dev *dev, struct kwqe *kwqe)
  1972. {
  1973. struct fcoe_kwqe_conn_destroy *req;
  1974. union l5cm_specific_data l5_data;
  1975. int ret;
  1976. u32 cid, l5_cid;
  1977. struct cnic_local *cp = dev->cnic_priv;
  1978. struct cnic_context *ctx;
  1979. struct fcoe_kcqe kcqe;
  1980. struct kcqe *cqes[1];
  1981. req = (struct fcoe_kwqe_conn_destroy *) kwqe;
  1982. cid = req->context_id;
  1983. l5_cid = req->conn_id;
  1984. if (l5_cid >= BNX2X_FCOE_NUM_CONNECTIONS)
  1985. return -EINVAL;
  1986. l5_cid += BNX2X_FCOE_L5_CID_BASE;
  1987. ctx = &cp->ctx_tbl[l5_cid];
  1988. init_waitqueue_head(&ctx->waitq);
  1989. ctx->wait_cond = 0;
  1990. memset(&l5_data, 0, sizeof(l5_data));
  1991. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_TERMINATE_CONN, cid,
  1992. FCOE_CONNECTION_TYPE, &l5_data);
  1993. if (ret == 0) {
  1994. wait_event(ctx->waitq, ctx->wait_cond);
  1995. set_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags);
  1996. queue_delayed_work(cnic_wq, &cp->delete_task,
  1997. msecs_to_jiffies(2000));
  1998. }
  1999. memset(&kcqe, 0, sizeof(kcqe));
  2000. kcqe.op_code = FCOE_KCQE_OPCODE_DESTROY_CONN;
  2001. kcqe.fcoe_conn_id = req->conn_id;
  2002. kcqe.fcoe_conn_context_id = cid;
  2003. cqes[0] = (struct kcqe *) &kcqe;
  2004. cnic_reply_bnx2x_kcqes(dev, CNIC_ULP_FCOE, cqes, 1);
  2005. return ret;
  2006. }
  2007. static int cnic_bnx2x_fcoe_fw_destroy(struct cnic_dev *dev, struct kwqe *kwqe)
  2008. {
  2009. struct fcoe_kwqe_destroy *req;
  2010. union l5cm_specific_data l5_data;
  2011. struct cnic_local *cp = dev->cnic_priv;
  2012. int ret;
  2013. u32 cid;
  2014. req = (struct fcoe_kwqe_destroy *) kwqe;
  2015. cid = BNX2X_HW_CID(cp, cp->fcoe_init_cid);
  2016. memset(&l5_data, 0, sizeof(l5_data));
  2017. ret = cnic_submit_kwqe_16(dev, FCOE_RAMROD_CMD_ID_DESTROY, cid,
  2018. FCOE_CONNECTION_TYPE, &l5_data);
  2019. return ret;
  2020. }
  2021. static int cnic_submit_bnx2x_iscsi_kwqes(struct cnic_dev *dev,
  2022. struct kwqe *wqes[], u32 num_wqes)
  2023. {
  2024. int i, work, ret;
  2025. u32 opcode;
  2026. struct kwqe *kwqe;
  2027. if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
  2028. return -EAGAIN; /* bnx2 is down */
  2029. for (i = 0; i < num_wqes; ) {
  2030. kwqe = wqes[i];
  2031. opcode = KWQE_OPCODE(kwqe->kwqe_op_flag);
  2032. work = 1;
  2033. switch (opcode) {
  2034. case ISCSI_KWQE_OPCODE_INIT1:
  2035. ret = cnic_bnx2x_iscsi_init1(dev, kwqe);
  2036. break;
  2037. case ISCSI_KWQE_OPCODE_INIT2:
  2038. ret = cnic_bnx2x_iscsi_init2(dev, kwqe);
  2039. break;
  2040. case ISCSI_KWQE_OPCODE_OFFLOAD_CONN1:
  2041. ret = cnic_bnx2x_iscsi_ofld1(dev, &wqes[i],
  2042. num_wqes - i, &work);
  2043. break;
  2044. case ISCSI_KWQE_OPCODE_UPDATE_CONN:
  2045. ret = cnic_bnx2x_iscsi_update(dev, kwqe);
  2046. break;
  2047. case ISCSI_KWQE_OPCODE_DESTROY_CONN:
  2048. ret = cnic_bnx2x_iscsi_destroy(dev, kwqe);
  2049. break;
  2050. case L4_KWQE_OPCODE_VALUE_CONNECT1:
  2051. ret = cnic_bnx2x_connect(dev, &wqes[i], num_wqes - i,
  2052. &work);
  2053. break;
  2054. case L4_KWQE_OPCODE_VALUE_CLOSE:
  2055. ret = cnic_bnx2x_close(dev, kwqe);
  2056. break;
  2057. case L4_KWQE_OPCODE_VALUE_RESET:
  2058. ret = cnic_bnx2x_reset(dev, kwqe);
  2059. break;
  2060. case L4_KWQE_OPCODE_VALUE_OFFLOAD_PG:
  2061. ret = cnic_bnx2x_offload_pg(dev, kwqe);
  2062. break;
  2063. case L4_KWQE_OPCODE_VALUE_UPDATE_PG:
  2064. ret = cnic_bnx2x_update_pg(dev, kwqe);
  2065. break;
  2066. case L4_KWQE_OPCODE_VALUE_UPLOAD_PG:
  2067. ret = 0;
  2068. break;
  2069. default:
  2070. ret = 0;
  2071. netdev_err(dev->netdev, "Unknown type of KWQE(0x%x)\n",
  2072. opcode);
  2073. break;
  2074. }
  2075. if (ret < 0)
  2076. netdev_err(dev->netdev, "KWQE(0x%x) failed\n",
  2077. opcode);
  2078. i += work;
  2079. }
  2080. return 0;
  2081. }
  2082. static int cnic_submit_bnx2x_fcoe_kwqes(struct cnic_dev *dev,
  2083. struct kwqe *wqes[], u32 num_wqes)
  2084. {
  2085. struct cnic_local *cp = dev->cnic_priv;
  2086. int i, work, ret;
  2087. u32 opcode;
  2088. struct kwqe *kwqe;
  2089. if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
  2090. return -EAGAIN; /* bnx2 is down */
  2091. if (BNX2X_CHIP_NUM(cp->chip_id) == BNX2X_CHIP_NUM_57710)
  2092. return -EINVAL;
  2093. for (i = 0; i < num_wqes; ) {
  2094. kwqe = wqes[i];
  2095. opcode = KWQE_OPCODE(kwqe->kwqe_op_flag);
  2096. work = 1;
  2097. switch (opcode) {
  2098. case FCOE_KWQE_OPCODE_INIT1:
  2099. ret = cnic_bnx2x_fcoe_init1(dev, &wqes[i],
  2100. num_wqes - i, &work);
  2101. break;
  2102. case FCOE_KWQE_OPCODE_OFFLOAD_CONN1:
  2103. ret = cnic_bnx2x_fcoe_ofld1(dev, &wqes[i],
  2104. num_wqes - i, &work);
  2105. break;
  2106. case FCOE_KWQE_OPCODE_ENABLE_CONN:
  2107. ret = cnic_bnx2x_fcoe_enable(dev, kwqe);
  2108. break;
  2109. case FCOE_KWQE_OPCODE_DISABLE_CONN:
  2110. ret = cnic_bnx2x_fcoe_disable(dev, kwqe);
  2111. break;
  2112. case FCOE_KWQE_OPCODE_DESTROY_CONN:
  2113. ret = cnic_bnx2x_fcoe_destroy(dev, kwqe);
  2114. break;
  2115. case FCOE_KWQE_OPCODE_DESTROY:
  2116. ret = cnic_bnx2x_fcoe_fw_destroy(dev, kwqe);
  2117. break;
  2118. case FCOE_KWQE_OPCODE_STAT:
  2119. ret = cnic_bnx2x_fcoe_stat(dev, kwqe);
  2120. break;
  2121. default:
  2122. ret = 0;
  2123. netdev_err(dev->netdev, "Unknown type of KWQE(0x%x)\n",
  2124. opcode);
  2125. break;
  2126. }
  2127. if (ret < 0)
  2128. netdev_err(dev->netdev, "KWQE(0x%x) failed\n",
  2129. opcode);
  2130. i += work;
  2131. }
  2132. return 0;
  2133. }
  2134. static int cnic_submit_bnx2x_kwqes(struct cnic_dev *dev, struct kwqe *wqes[],
  2135. u32 num_wqes)
  2136. {
  2137. int ret = -EINVAL;
  2138. u32 layer_code;
  2139. if (!test_bit(CNIC_F_CNIC_UP, &dev->flags))
  2140. return -EAGAIN; /* bnx2x is down */
  2141. if (!num_wqes)
  2142. return 0;
  2143. layer_code = wqes[0]->kwqe_op_flag & KWQE_LAYER_MASK;
  2144. switch (layer_code) {
  2145. case KWQE_FLAGS_LAYER_MASK_L5_ISCSI:
  2146. case KWQE_FLAGS_LAYER_MASK_L4:
  2147. case KWQE_FLAGS_LAYER_MASK_L2:
  2148. ret = cnic_submit_bnx2x_iscsi_kwqes(dev, wqes, num_wqes);
  2149. break;
  2150. case KWQE_FLAGS_LAYER_MASK_L5_FCOE:
  2151. ret = cnic_submit_bnx2x_fcoe_kwqes(dev, wqes, num_wqes);
  2152. break;
  2153. }
  2154. return ret;
  2155. }
  2156. static inline u32 cnic_get_kcqe_layer_mask(u32 opflag)
  2157. {
  2158. if (unlikely(KCQE_OPCODE(opflag) == FCOE_RAMROD_CMD_ID_TERMINATE_CONN))
  2159. return KCQE_FLAGS_LAYER_MASK_L4;
  2160. return opflag & KCQE_FLAGS_LAYER_MASK;
  2161. }
  2162. static void service_kcqes(struct cnic_dev *dev, int num_cqes)
  2163. {
  2164. struct cnic_local *cp = dev->cnic_priv;
  2165. int i, j, comp = 0;
  2166. i = 0;
  2167. j = 1;
  2168. while (num_cqes) {
  2169. struct cnic_ulp_ops *ulp_ops;
  2170. int ulp_type;
  2171. u32 kcqe_op_flag = cp->completed_kcq[i]->kcqe_op_flag;
  2172. u32 kcqe_layer = cnic_get_kcqe_layer_mask(kcqe_op_flag);
  2173. if (unlikely(kcqe_op_flag & KCQE_RAMROD_COMPLETION))
  2174. comp++;
  2175. while (j < num_cqes) {
  2176. u32 next_op = cp->completed_kcq[i + j]->kcqe_op_flag;
  2177. if (cnic_get_kcqe_layer_mask(next_op) != kcqe_layer)
  2178. break;
  2179. if (unlikely(next_op & KCQE_RAMROD_COMPLETION))
  2180. comp++;
  2181. j++;
  2182. }
  2183. if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_RDMA)
  2184. ulp_type = CNIC_ULP_RDMA;
  2185. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_ISCSI)
  2186. ulp_type = CNIC_ULP_ISCSI;
  2187. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L5_FCOE)
  2188. ulp_type = CNIC_ULP_FCOE;
  2189. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L4)
  2190. ulp_type = CNIC_ULP_L4;
  2191. else if (kcqe_layer == KCQE_FLAGS_LAYER_MASK_L2)
  2192. goto end;
  2193. else {
  2194. netdev_err(dev->netdev, "Unknown type of KCQE(0x%x)\n",
  2195. kcqe_op_flag);
  2196. goto end;
  2197. }
  2198. rcu_read_lock();
  2199. ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
  2200. if (likely(ulp_ops)) {
  2201. ulp_ops->indicate_kcqes(cp->ulp_handle[ulp_type],
  2202. cp->completed_kcq + i, j);
  2203. }
  2204. rcu_read_unlock();
  2205. end:
  2206. num_cqes -= j;
  2207. i += j;
  2208. j = 1;
  2209. }
  2210. if (unlikely(comp))
  2211. cnic_spq_completion(dev, DRV_CTL_RET_L5_SPQ_CREDIT_CMD, comp);
  2212. }
  2213. static u16 cnic_bnx2_next_idx(u16 idx)
  2214. {
  2215. return idx + 1;
  2216. }
  2217. static u16 cnic_bnx2_hw_idx(u16 idx)
  2218. {
  2219. return idx;
  2220. }
  2221. static u16 cnic_bnx2x_next_idx(u16 idx)
  2222. {
  2223. idx++;
  2224. if ((idx & MAX_KCQE_CNT) == MAX_KCQE_CNT)
  2225. idx++;
  2226. return idx;
  2227. }
  2228. static u16 cnic_bnx2x_hw_idx(u16 idx)
  2229. {
  2230. if ((idx & MAX_KCQE_CNT) == MAX_KCQE_CNT)
  2231. idx++;
  2232. return idx;
  2233. }
  2234. static int cnic_get_kcqes(struct cnic_dev *dev, struct kcq_info *info)
  2235. {
  2236. struct cnic_local *cp = dev->cnic_priv;
  2237. u16 i, ri, hw_prod, last;
  2238. struct kcqe *kcqe;
  2239. int kcqe_cnt = 0, last_cnt = 0;
  2240. i = ri = last = info->sw_prod_idx;
  2241. ri &= MAX_KCQ_IDX;
  2242. hw_prod = *info->hw_prod_idx_ptr;
  2243. hw_prod = cp->hw_idx(hw_prod);
  2244. while ((i != hw_prod) && (kcqe_cnt < MAX_COMPLETED_KCQE)) {
  2245. kcqe = &info->kcq[KCQ_PG(ri)][KCQ_IDX(ri)];
  2246. cp->completed_kcq[kcqe_cnt++] = kcqe;
  2247. i = cp->next_idx(i);
  2248. ri = i & MAX_KCQ_IDX;
  2249. if (likely(!(kcqe->kcqe_op_flag & KCQE_FLAGS_NEXT))) {
  2250. last_cnt = kcqe_cnt;
  2251. last = i;
  2252. }
  2253. }
  2254. info->sw_prod_idx = last;
  2255. return last_cnt;
  2256. }
  2257. static int cnic_l2_completion(struct cnic_local *cp)
  2258. {
  2259. u16 hw_cons, sw_cons;
  2260. struct cnic_uio_dev *udev = cp->udev;
  2261. union eth_rx_cqe *cqe, *cqe_ring = (union eth_rx_cqe *)
  2262. (udev->l2_ring + (2 * BCM_PAGE_SIZE));
  2263. u32 cmd;
  2264. int comp = 0;
  2265. if (!test_bit(CNIC_F_BNX2X_CLASS, &cp->dev->flags))
  2266. return 0;
  2267. hw_cons = *cp->rx_cons_ptr;
  2268. if ((hw_cons & BNX2X_MAX_RCQ_DESC_CNT) == BNX2X_MAX_RCQ_DESC_CNT)
  2269. hw_cons++;
  2270. sw_cons = cp->rx_cons;
  2271. while (sw_cons != hw_cons) {
  2272. u8 cqe_fp_flags;
  2273. cqe = &cqe_ring[sw_cons & BNX2X_MAX_RCQ_DESC_CNT];
  2274. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  2275. if (cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE) {
  2276. cmd = le32_to_cpu(cqe->ramrod_cqe.conn_and_cmd_data);
  2277. cmd >>= COMMON_RAMROD_ETH_RX_CQE_CMD_ID_SHIFT;
  2278. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP ||
  2279. cmd == RAMROD_CMD_ID_ETH_HALT)
  2280. comp++;
  2281. }
  2282. sw_cons = BNX2X_NEXT_RCQE(sw_cons);
  2283. }
  2284. return comp;
  2285. }
  2286. static void cnic_chk_pkt_rings(struct cnic_local *cp)
  2287. {
  2288. u16 rx_cons, tx_cons;
  2289. int comp = 0;
  2290. if (!test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags))
  2291. return;
  2292. rx_cons = *cp->rx_cons_ptr;
  2293. tx_cons = *cp->tx_cons_ptr;
  2294. if (cp->tx_cons != tx_cons || cp->rx_cons != rx_cons) {
  2295. if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags))
  2296. comp = cnic_l2_completion(cp);
  2297. cp->tx_cons = tx_cons;
  2298. cp->rx_cons = rx_cons;
  2299. if (cp->udev)
  2300. uio_event_notify(&cp->udev->cnic_uinfo);
  2301. }
  2302. if (comp)
  2303. clear_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags);
  2304. }
  2305. static u32 cnic_service_bnx2_queues(struct cnic_dev *dev)
  2306. {
  2307. struct cnic_local *cp = dev->cnic_priv;
  2308. u32 status_idx = (u16) *cp->kcq1.status_idx_ptr;
  2309. int kcqe_cnt;
  2310. cp->kwq_con_idx = *cp->kwq_con_idx_ptr;
  2311. while ((kcqe_cnt = cnic_get_kcqes(dev, &cp->kcq1))) {
  2312. service_kcqes(dev, kcqe_cnt);
  2313. /* Tell compiler that status_blk fields can change. */
  2314. barrier();
  2315. if (status_idx != *cp->kcq1.status_idx_ptr) {
  2316. status_idx = (u16) *cp->kcq1.status_idx_ptr;
  2317. cp->kwq_con_idx = *cp->kwq_con_idx_ptr;
  2318. } else
  2319. break;
  2320. }
  2321. CNIC_WR16(dev, cp->kcq1.io_addr, cp->kcq1.sw_prod_idx);
  2322. cnic_chk_pkt_rings(cp);
  2323. return status_idx;
  2324. }
  2325. static int cnic_service_bnx2(void *data, void *status_blk)
  2326. {
  2327. struct cnic_dev *dev = data;
  2328. if (unlikely(!test_bit(CNIC_F_CNIC_UP, &dev->flags))) {
  2329. struct status_block *sblk = status_blk;
  2330. return sblk->status_idx;
  2331. }
  2332. return cnic_service_bnx2_queues(dev);
  2333. }
  2334. static void cnic_service_bnx2_msix(unsigned long data)
  2335. {
  2336. struct cnic_dev *dev = (struct cnic_dev *) data;
  2337. struct cnic_local *cp = dev->cnic_priv;
  2338. cp->last_status_idx = cnic_service_bnx2_queues(dev);
  2339. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  2340. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx);
  2341. }
  2342. static void cnic_doirq(struct cnic_dev *dev)
  2343. {
  2344. struct cnic_local *cp = dev->cnic_priv;
  2345. if (likely(test_bit(CNIC_F_CNIC_UP, &dev->flags))) {
  2346. u16 prod = cp->kcq1.sw_prod_idx & MAX_KCQ_IDX;
  2347. prefetch(cp->status_blk.gen);
  2348. prefetch(&cp->kcq1.kcq[KCQ_PG(prod)][KCQ_IDX(prod)]);
  2349. tasklet_schedule(&cp->cnic_irq_task);
  2350. }
  2351. }
  2352. static irqreturn_t cnic_irq(int irq, void *dev_instance)
  2353. {
  2354. struct cnic_dev *dev = dev_instance;
  2355. struct cnic_local *cp = dev->cnic_priv;
  2356. if (cp->ack_int)
  2357. cp->ack_int(dev);
  2358. cnic_doirq(dev);
  2359. return IRQ_HANDLED;
  2360. }
  2361. static inline void cnic_ack_bnx2x_int(struct cnic_dev *dev, u8 id, u8 storm,
  2362. u16 index, u8 op, u8 update)
  2363. {
  2364. struct cnic_local *cp = dev->cnic_priv;
  2365. u32 hc_addr = (HC_REG_COMMAND_REG + CNIC_PORT(cp) * 32 +
  2366. COMMAND_REG_INT_ACK);
  2367. struct igu_ack_register igu_ack;
  2368. igu_ack.status_block_index = index;
  2369. igu_ack.sb_id_and_flags =
  2370. ((id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
  2371. (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
  2372. (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
  2373. (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
  2374. CNIC_WR(dev, hc_addr, (*(u32 *)&igu_ack));
  2375. }
  2376. static void cnic_ack_igu_sb(struct cnic_dev *dev, u8 igu_sb_id, u8 segment,
  2377. u16 index, u8 op, u8 update)
  2378. {
  2379. struct igu_regular cmd_data;
  2380. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id) * 8;
  2381. cmd_data.sb_id_and_flags =
  2382. (index << IGU_REGULAR_SB_INDEX_SHIFT) |
  2383. (segment << IGU_REGULAR_SEGMENT_ACCESS_SHIFT) |
  2384. (update << IGU_REGULAR_BUPDATE_SHIFT) |
  2385. (op << IGU_REGULAR_ENABLE_INT_SHIFT);
  2386. CNIC_WR(dev, igu_addr, cmd_data.sb_id_and_flags);
  2387. }
  2388. static void cnic_ack_bnx2x_msix(struct cnic_dev *dev)
  2389. {
  2390. struct cnic_local *cp = dev->cnic_priv;
  2391. cnic_ack_bnx2x_int(dev, cp->bnx2x_igu_sb_id, CSTORM_ID, 0,
  2392. IGU_INT_DISABLE, 0);
  2393. }
  2394. static void cnic_ack_bnx2x_e2_msix(struct cnic_dev *dev)
  2395. {
  2396. struct cnic_local *cp = dev->cnic_priv;
  2397. cnic_ack_igu_sb(dev, cp->bnx2x_igu_sb_id, IGU_SEG_ACCESS_DEF, 0,
  2398. IGU_INT_DISABLE, 0);
  2399. }
  2400. static u32 cnic_service_bnx2x_kcq(struct cnic_dev *dev, struct kcq_info *info)
  2401. {
  2402. u32 last_status = *info->status_idx_ptr;
  2403. int kcqe_cnt;
  2404. while ((kcqe_cnt = cnic_get_kcqes(dev, info))) {
  2405. service_kcqes(dev, kcqe_cnt);
  2406. /* Tell compiler that sblk fields can change. */
  2407. barrier();
  2408. if (last_status == *info->status_idx_ptr)
  2409. break;
  2410. last_status = *info->status_idx_ptr;
  2411. }
  2412. return last_status;
  2413. }
  2414. static void cnic_service_bnx2x_bh(unsigned long data)
  2415. {
  2416. struct cnic_dev *dev = (struct cnic_dev *) data;
  2417. struct cnic_local *cp = dev->cnic_priv;
  2418. u32 status_idx;
  2419. if (unlikely(!test_bit(CNIC_F_CNIC_UP, &dev->flags)))
  2420. return;
  2421. status_idx = cnic_service_bnx2x_kcq(dev, &cp->kcq1);
  2422. CNIC_WR16(dev, cp->kcq1.io_addr, cp->kcq1.sw_prod_idx + MAX_KCQ_IDX);
  2423. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  2424. status_idx = cnic_service_bnx2x_kcq(dev, &cp->kcq2);
  2425. CNIC_WR16(dev, cp->kcq2.io_addr, cp->kcq2.sw_prod_idx +
  2426. MAX_KCQ_IDX);
  2427. cnic_ack_igu_sb(dev, cp->bnx2x_igu_sb_id, IGU_SEG_ACCESS_DEF,
  2428. status_idx, IGU_INT_ENABLE, 1);
  2429. } else {
  2430. cnic_ack_bnx2x_int(dev, cp->bnx2x_igu_sb_id, USTORM_ID,
  2431. status_idx, IGU_INT_ENABLE, 1);
  2432. }
  2433. }
  2434. static int cnic_service_bnx2x(void *data, void *status_blk)
  2435. {
  2436. struct cnic_dev *dev = data;
  2437. struct cnic_local *cp = dev->cnic_priv;
  2438. if (!(cp->ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX))
  2439. cnic_doirq(dev);
  2440. cnic_chk_pkt_rings(cp);
  2441. return 0;
  2442. }
  2443. static void cnic_ulp_stop(struct cnic_dev *dev)
  2444. {
  2445. struct cnic_local *cp = dev->cnic_priv;
  2446. int if_type;
  2447. cnic_send_nlmsg(cp, ISCSI_KEVENT_IF_DOWN, NULL);
  2448. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  2449. struct cnic_ulp_ops *ulp_ops;
  2450. mutex_lock(&cnic_lock);
  2451. ulp_ops = cp->ulp_ops[if_type];
  2452. if (!ulp_ops) {
  2453. mutex_unlock(&cnic_lock);
  2454. continue;
  2455. }
  2456. set_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
  2457. mutex_unlock(&cnic_lock);
  2458. if (test_and_clear_bit(ULP_F_START, &cp->ulp_flags[if_type]))
  2459. ulp_ops->cnic_stop(cp->ulp_handle[if_type]);
  2460. clear_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
  2461. }
  2462. }
  2463. static void cnic_ulp_start(struct cnic_dev *dev)
  2464. {
  2465. struct cnic_local *cp = dev->cnic_priv;
  2466. int if_type;
  2467. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  2468. struct cnic_ulp_ops *ulp_ops;
  2469. mutex_lock(&cnic_lock);
  2470. ulp_ops = cp->ulp_ops[if_type];
  2471. if (!ulp_ops || !ulp_ops->cnic_start) {
  2472. mutex_unlock(&cnic_lock);
  2473. continue;
  2474. }
  2475. set_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
  2476. mutex_unlock(&cnic_lock);
  2477. if (!test_and_set_bit(ULP_F_START, &cp->ulp_flags[if_type]))
  2478. ulp_ops->cnic_start(cp->ulp_handle[if_type]);
  2479. clear_bit(ULP_F_CALL_PENDING, &cp->ulp_flags[if_type]);
  2480. }
  2481. }
  2482. static int cnic_ctl(void *data, struct cnic_ctl_info *info)
  2483. {
  2484. struct cnic_dev *dev = data;
  2485. switch (info->cmd) {
  2486. case CNIC_CTL_STOP_CMD:
  2487. cnic_hold(dev);
  2488. cnic_ulp_stop(dev);
  2489. cnic_stop_hw(dev);
  2490. cnic_put(dev);
  2491. break;
  2492. case CNIC_CTL_START_CMD:
  2493. cnic_hold(dev);
  2494. if (!cnic_start_hw(dev))
  2495. cnic_ulp_start(dev);
  2496. cnic_put(dev);
  2497. break;
  2498. case CNIC_CTL_COMPLETION_CMD: {
  2499. u32 cid = BNX2X_SW_CID(info->data.comp.cid);
  2500. u32 l5_cid;
  2501. struct cnic_local *cp = dev->cnic_priv;
  2502. if (cnic_get_l5_cid(cp, cid, &l5_cid) == 0) {
  2503. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  2504. ctx->wait_cond = 1;
  2505. wake_up(&ctx->waitq);
  2506. }
  2507. break;
  2508. }
  2509. default:
  2510. return -EINVAL;
  2511. }
  2512. return 0;
  2513. }
  2514. static void cnic_ulp_init(struct cnic_dev *dev)
  2515. {
  2516. int i;
  2517. struct cnic_local *cp = dev->cnic_priv;
  2518. for (i = 0; i < MAX_CNIC_ULP_TYPE_EXT; i++) {
  2519. struct cnic_ulp_ops *ulp_ops;
  2520. mutex_lock(&cnic_lock);
  2521. ulp_ops = cnic_ulp_tbl[i];
  2522. if (!ulp_ops || !ulp_ops->cnic_init) {
  2523. mutex_unlock(&cnic_lock);
  2524. continue;
  2525. }
  2526. ulp_get(ulp_ops);
  2527. mutex_unlock(&cnic_lock);
  2528. if (!test_and_set_bit(ULP_F_INIT, &cp->ulp_flags[i]))
  2529. ulp_ops->cnic_init(dev);
  2530. ulp_put(ulp_ops);
  2531. }
  2532. }
  2533. static void cnic_ulp_exit(struct cnic_dev *dev)
  2534. {
  2535. int i;
  2536. struct cnic_local *cp = dev->cnic_priv;
  2537. for (i = 0; i < MAX_CNIC_ULP_TYPE_EXT; i++) {
  2538. struct cnic_ulp_ops *ulp_ops;
  2539. mutex_lock(&cnic_lock);
  2540. ulp_ops = cnic_ulp_tbl[i];
  2541. if (!ulp_ops || !ulp_ops->cnic_exit) {
  2542. mutex_unlock(&cnic_lock);
  2543. continue;
  2544. }
  2545. ulp_get(ulp_ops);
  2546. mutex_unlock(&cnic_lock);
  2547. if (test_and_clear_bit(ULP_F_INIT, &cp->ulp_flags[i]))
  2548. ulp_ops->cnic_exit(dev);
  2549. ulp_put(ulp_ops);
  2550. }
  2551. }
  2552. static int cnic_cm_offload_pg(struct cnic_sock *csk)
  2553. {
  2554. struct cnic_dev *dev = csk->dev;
  2555. struct l4_kwq_offload_pg *l4kwqe;
  2556. struct kwqe *wqes[1];
  2557. l4kwqe = (struct l4_kwq_offload_pg *) &csk->kwqe1;
  2558. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2559. wqes[0] = (struct kwqe *) l4kwqe;
  2560. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_OFFLOAD_PG;
  2561. l4kwqe->flags =
  2562. L4_LAYER_CODE << L4_KWQ_OFFLOAD_PG_LAYER_CODE_SHIFT;
  2563. l4kwqe->l2hdr_nbytes = ETH_HLEN;
  2564. l4kwqe->da0 = csk->ha[0];
  2565. l4kwqe->da1 = csk->ha[1];
  2566. l4kwqe->da2 = csk->ha[2];
  2567. l4kwqe->da3 = csk->ha[3];
  2568. l4kwqe->da4 = csk->ha[4];
  2569. l4kwqe->da5 = csk->ha[5];
  2570. l4kwqe->sa0 = dev->mac_addr[0];
  2571. l4kwqe->sa1 = dev->mac_addr[1];
  2572. l4kwqe->sa2 = dev->mac_addr[2];
  2573. l4kwqe->sa3 = dev->mac_addr[3];
  2574. l4kwqe->sa4 = dev->mac_addr[4];
  2575. l4kwqe->sa5 = dev->mac_addr[5];
  2576. l4kwqe->etype = ETH_P_IP;
  2577. l4kwqe->ipid_start = DEF_IPID_START;
  2578. l4kwqe->host_opaque = csk->l5_cid;
  2579. if (csk->vlan_id) {
  2580. l4kwqe->pg_flags |= L4_KWQ_OFFLOAD_PG_VLAN_TAGGING;
  2581. l4kwqe->vlan_tag = csk->vlan_id;
  2582. l4kwqe->l2hdr_nbytes += 4;
  2583. }
  2584. return dev->submit_kwqes(dev, wqes, 1);
  2585. }
  2586. static int cnic_cm_update_pg(struct cnic_sock *csk)
  2587. {
  2588. struct cnic_dev *dev = csk->dev;
  2589. struct l4_kwq_update_pg *l4kwqe;
  2590. struct kwqe *wqes[1];
  2591. l4kwqe = (struct l4_kwq_update_pg *) &csk->kwqe1;
  2592. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2593. wqes[0] = (struct kwqe *) l4kwqe;
  2594. l4kwqe->opcode = L4_KWQE_OPCODE_VALUE_UPDATE_PG;
  2595. l4kwqe->flags =
  2596. L4_LAYER_CODE << L4_KWQ_UPDATE_PG_LAYER_CODE_SHIFT;
  2597. l4kwqe->pg_cid = csk->pg_cid;
  2598. l4kwqe->da0 = csk->ha[0];
  2599. l4kwqe->da1 = csk->ha[1];
  2600. l4kwqe->da2 = csk->ha[2];
  2601. l4kwqe->da3 = csk->ha[3];
  2602. l4kwqe->da4 = csk->ha[4];
  2603. l4kwqe->da5 = csk->ha[5];
  2604. l4kwqe->pg_host_opaque = csk->l5_cid;
  2605. l4kwqe->pg_valids = L4_KWQ_UPDATE_PG_VALIDS_DA;
  2606. return dev->submit_kwqes(dev, wqes, 1);
  2607. }
  2608. static int cnic_cm_upload_pg(struct cnic_sock *csk)
  2609. {
  2610. struct cnic_dev *dev = csk->dev;
  2611. struct l4_kwq_upload *l4kwqe;
  2612. struct kwqe *wqes[1];
  2613. l4kwqe = (struct l4_kwq_upload *) &csk->kwqe1;
  2614. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2615. wqes[0] = (struct kwqe *) l4kwqe;
  2616. l4kwqe->opcode = L4_KWQE_OPCODE_VALUE_UPLOAD_PG;
  2617. l4kwqe->flags =
  2618. L4_LAYER_CODE << L4_KWQ_UPLOAD_LAYER_CODE_SHIFT;
  2619. l4kwqe->cid = csk->pg_cid;
  2620. return dev->submit_kwqes(dev, wqes, 1);
  2621. }
  2622. static int cnic_cm_conn_req(struct cnic_sock *csk)
  2623. {
  2624. struct cnic_dev *dev = csk->dev;
  2625. struct l4_kwq_connect_req1 *l4kwqe1;
  2626. struct l4_kwq_connect_req2 *l4kwqe2;
  2627. struct l4_kwq_connect_req3 *l4kwqe3;
  2628. struct kwqe *wqes[3];
  2629. u8 tcp_flags = 0;
  2630. int num_wqes = 2;
  2631. l4kwqe1 = (struct l4_kwq_connect_req1 *) &csk->kwqe1;
  2632. l4kwqe2 = (struct l4_kwq_connect_req2 *) &csk->kwqe2;
  2633. l4kwqe3 = (struct l4_kwq_connect_req3 *) &csk->kwqe3;
  2634. memset(l4kwqe1, 0, sizeof(*l4kwqe1));
  2635. memset(l4kwqe2, 0, sizeof(*l4kwqe2));
  2636. memset(l4kwqe3, 0, sizeof(*l4kwqe3));
  2637. l4kwqe3->op_code = L4_KWQE_OPCODE_VALUE_CONNECT3;
  2638. l4kwqe3->flags =
  2639. L4_LAYER_CODE << L4_KWQ_CONNECT_REQ3_LAYER_CODE_SHIFT;
  2640. l4kwqe3->ka_timeout = csk->ka_timeout;
  2641. l4kwqe3->ka_interval = csk->ka_interval;
  2642. l4kwqe3->ka_max_probe_count = csk->ka_max_probe_count;
  2643. l4kwqe3->tos = csk->tos;
  2644. l4kwqe3->ttl = csk->ttl;
  2645. l4kwqe3->snd_seq_scale = csk->snd_seq_scale;
  2646. l4kwqe3->pmtu = csk->mtu;
  2647. l4kwqe3->rcv_buf = csk->rcv_buf;
  2648. l4kwqe3->snd_buf = csk->snd_buf;
  2649. l4kwqe3->seed = csk->seed;
  2650. wqes[0] = (struct kwqe *) l4kwqe1;
  2651. if (test_bit(SK_F_IPV6, &csk->flags)) {
  2652. wqes[1] = (struct kwqe *) l4kwqe2;
  2653. wqes[2] = (struct kwqe *) l4kwqe3;
  2654. num_wqes = 3;
  2655. l4kwqe1->conn_flags = L4_KWQ_CONNECT_REQ1_IP_V6;
  2656. l4kwqe2->op_code = L4_KWQE_OPCODE_VALUE_CONNECT2;
  2657. l4kwqe2->flags =
  2658. L4_KWQ_CONNECT_REQ2_LINKED_WITH_NEXT |
  2659. L4_LAYER_CODE << L4_KWQ_CONNECT_REQ2_LAYER_CODE_SHIFT;
  2660. l4kwqe2->src_ip_v6_2 = be32_to_cpu(csk->src_ip[1]);
  2661. l4kwqe2->src_ip_v6_3 = be32_to_cpu(csk->src_ip[2]);
  2662. l4kwqe2->src_ip_v6_4 = be32_to_cpu(csk->src_ip[3]);
  2663. l4kwqe2->dst_ip_v6_2 = be32_to_cpu(csk->dst_ip[1]);
  2664. l4kwqe2->dst_ip_v6_3 = be32_to_cpu(csk->dst_ip[2]);
  2665. l4kwqe2->dst_ip_v6_4 = be32_to_cpu(csk->dst_ip[3]);
  2666. l4kwqe3->mss = l4kwqe3->pmtu - sizeof(struct ipv6hdr) -
  2667. sizeof(struct tcphdr);
  2668. } else {
  2669. wqes[1] = (struct kwqe *) l4kwqe3;
  2670. l4kwqe3->mss = l4kwqe3->pmtu - sizeof(struct iphdr) -
  2671. sizeof(struct tcphdr);
  2672. }
  2673. l4kwqe1->op_code = L4_KWQE_OPCODE_VALUE_CONNECT1;
  2674. l4kwqe1->flags =
  2675. (L4_LAYER_CODE << L4_KWQ_CONNECT_REQ1_LAYER_CODE_SHIFT) |
  2676. L4_KWQ_CONNECT_REQ3_LINKED_WITH_NEXT;
  2677. l4kwqe1->cid = csk->cid;
  2678. l4kwqe1->pg_cid = csk->pg_cid;
  2679. l4kwqe1->src_ip = be32_to_cpu(csk->src_ip[0]);
  2680. l4kwqe1->dst_ip = be32_to_cpu(csk->dst_ip[0]);
  2681. l4kwqe1->src_port = be16_to_cpu(csk->src_port);
  2682. l4kwqe1->dst_port = be16_to_cpu(csk->dst_port);
  2683. if (csk->tcp_flags & SK_TCP_NO_DELAY_ACK)
  2684. tcp_flags |= L4_KWQ_CONNECT_REQ1_NO_DELAY_ACK;
  2685. if (csk->tcp_flags & SK_TCP_KEEP_ALIVE)
  2686. tcp_flags |= L4_KWQ_CONNECT_REQ1_KEEP_ALIVE;
  2687. if (csk->tcp_flags & SK_TCP_NAGLE)
  2688. tcp_flags |= L4_KWQ_CONNECT_REQ1_NAGLE_ENABLE;
  2689. if (csk->tcp_flags & SK_TCP_TIMESTAMP)
  2690. tcp_flags |= L4_KWQ_CONNECT_REQ1_TIME_STAMP;
  2691. if (csk->tcp_flags & SK_TCP_SACK)
  2692. tcp_flags |= L4_KWQ_CONNECT_REQ1_SACK;
  2693. if (csk->tcp_flags & SK_TCP_SEG_SCALING)
  2694. tcp_flags |= L4_KWQ_CONNECT_REQ1_SEG_SCALING;
  2695. l4kwqe1->tcp_flags = tcp_flags;
  2696. return dev->submit_kwqes(dev, wqes, num_wqes);
  2697. }
  2698. static int cnic_cm_close_req(struct cnic_sock *csk)
  2699. {
  2700. struct cnic_dev *dev = csk->dev;
  2701. struct l4_kwq_close_req *l4kwqe;
  2702. struct kwqe *wqes[1];
  2703. l4kwqe = (struct l4_kwq_close_req *) &csk->kwqe2;
  2704. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2705. wqes[0] = (struct kwqe *) l4kwqe;
  2706. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_CLOSE;
  2707. l4kwqe->flags = L4_LAYER_CODE << L4_KWQ_CLOSE_REQ_LAYER_CODE_SHIFT;
  2708. l4kwqe->cid = csk->cid;
  2709. return dev->submit_kwqes(dev, wqes, 1);
  2710. }
  2711. static int cnic_cm_abort_req(struct cnic_sock *csk)
  2712. {
  2713. struct cnic_dev *dev = csk->dev;
  2714. struct l4_kwq_reset_req *l4kwqe;
  2715. struct kwqe *wqes[1];
  2716. l4kwqe = (struct l4_kwq_reset_req *) &csk->kwqe2;
  2717. memset(l4kwqe, 0, sizeof(*l4kwqe));
  2718. wqes[0] = (struct kwqe *) l4kwqe;
  2719. l4kwqe->op_code = L4_KWQE_OPCODE_VALUE_RESET;
  2720. l4kwqe->flags = L4_LAYER_CODE << L4_KWQ_RESET_REQ_LAYER_CODE_SHIFT;
  2721. l4kwqe->cid = csk->cid;
  2722. return dev->submit_kwqes(dev, wqes, 1);
  2723. }
  2724. static int cnic_cm_create(struct cnic_dev *dev, int ulp_type, u32 cid,
  2725. u32 l5_cid, struct cnic_sock **csk, void *context)
  2726. {
  2727. struct cnic_local *cp = dev->cnic_priv;
  2728. struct cnic_sock *csk1;
  2729. if (l5_cid >= MAX_CM_SK_TBL_SZ)
  2730. return -EINVAL;
  2731. if (cp->ctx_tbl) {
  2732. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  2733. if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags))
  2734. return -EAGAIN;
  2735. }
  2736. csk1 = &cp->csk_tbl[l5_cid];
  2737. if (atomic_read(&csk1->ref_count))
  2738. return -EAGAIN;
  2739. if (test_and_set_bit(SK_F_INUSE, &csk1->flags))
  2740. return -EBUSY;
  2741. csk1->dev = dev;
  2742. csk1->cid = cid;
  2743. csk1->l5_cid = l5_cid;
  2744. csk1->ulp_type = ulp_type;
  2745. csk1->context = context;
  2746. csk1->ka_timeout = DEF_KA_TIMEOUT;
  2747. csk1->ka_interval = DEF_KA_INTERVAL;
  2748. csk1->ka_max_probe_count = DEF_KA_MAX_PROBE_COUNT;
  2749. csk1->tos = DEF_TOS;
  2750. csk1->ttl = DEF_TTL;
  2751. csk1->snd_seq_scale = DEF_SND_SEQ_SCALE;
  2752. csk1->rcv_buf = DEF_RCV_BUF;
  2753. csk1->snd_buf = DEF_SND_BUF;
  2754. csk1->seed = DEF_SEED;
  2755. *csk = csk1;
  2756. return 0;
  2757. }
  2758. static void cnic_cm_cleanup(struct cnic_sock *csk)
  2759. {
  2760. if (csk->src_port) {
  2761. struct cnic_dev *dev = csk->dev;
  2762. struct cnic_local *cp = dev->cnic_priv;
  2763. cnic_free_id(&cp->csk_port_tbl, be16_to_cpu(csk->src_port));
  2764. csk->src_port = 0;
  2765. }
  2766. }
  2767. static void cnic_close_conn(struct cnic_sock *csk)
  2768. {
  2769. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags)) {
  2770. cnic_cm_upload_pg(csk);
  2771. clear_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags);
  2772. }
  2773. cnic_cm_cleanup(csk);
  2774. }
  2775. static int cnic_cm_destroy(struct cnic_sock *csk)
  2776. {
  2777. if (!cnic_in_use(csk))
  2778. return -EINVAL;
  2779. csk_hold(csk);
  2780. clear_bit(SK_F_INUSE, &csk->flags);
  2781. smp_mb__after_clear_bit();
  2782. while (atomic_read(&csk->ref_count) != 1)
  2783. msleep(1);
  2784. cnic_cm_cleanup(csk);
  2785. csk->flags = 0;
  2786. csk_put(csk);
  2787. return 0;
  2788. }
  2789. static inline u16 cnic_get_vlan(struct net_device *dev,
  2790. struct net_device **vlan_dev)
  2791. {
  2792. if (dev->priv_flags & IFF_802_1Q_VLAN) {
  2793. *vlan_dev = vlan_dev_real_dev(dev);
  2794. return vlan_dev_vlan_id(dev);
  2795. }
  2796. *vlan_dev = dev;
  2797. return 0;
  2798. }
  2799. static int cnic_get_v4_route(struct sockaddr_in *dst_addr,
  2800. struct dst_entry **dst)
  2801. {
  2802. #if defined(CONFIG_INET)
  2803. struct flowi fl;
  2804. int err;
  2805. struct rtable *rt;
  2806. memset(&fl, 0, sizeof(fl));
  2807. fl.nl_u.ip4_u.daddr = dst_addr->sin_addr.s_addr;
  2808. err = ip_route_output_key(&init_net, &rt, &fl);
  2809. if (!err)
  2810. *dst = &rt->dst;
  2811. return err;
  2812. #else
  2813. return -ENETUNREACH;
  2814. #endif
  2815. }
  2816. static int cnic_get_v6_route(struct sockaddr_in6 *dst_addr,
  2817. struct dst_entry **dst)
  2818. {
  2819. #if defined(CONFIG_IPV6) || (defined(CONFIG_IPV6_MODULE) && defined(MODULE))
  2820. struct flowi fl;
  2821. memset(&fl, 0, sizeof(fl));
  2822. ipv6_addr_copy(&fl.fl6_dst, &dst_addr->sin6_addr);
  2823. if (ipv6_addr_type(&fl.fl6_dst) & IPV6_ADDR_LINKLOCAL)
  2824. fl.oif = dst_addr->sin6_scope_id;
  2825. *dst = ip6_route_output(&init_net, NULL, &fl);
  2826. if (*dst)
  2827. return 0;
  2828. #endif
  2829. return -ENETUNREACH;
  2830. }
  2831. static struct cnic_dev *cnic_cm_select_dev(struct sockaddr_in *dst_addr,
  2832. int ulp_type)
  2833. {
  2834. struct cnic_dev *dev = NULL;
  2835. struct dst_entry *dst;
  2836. struct net_device *netdev = NULL;
  2837. int err = -ENETUNREACH;
  2838. if (dst_addr->sin_family == AF_INET)
  2839. err = cnic_get_v4_route(dst_addr, &dst);
  2840. else if (dst_addr->sin_family == AF_INET6) {
  2841. struct sockaddr_in6 *dst_addr6 =
  2842. (struct sockaddr_in6 *) dst_addr;
  2843. err = cnic_get_v6_route(dst_addr6, &dst);
  2844. } else
  2845. return NULL;
  2846. if (err)
  2847. return NULL;
  2848. if (!dst->dev)
  2849. goto done;
  2850. cnic_get_vlan(dst->dev, &netdev);
  2851. dev = cnic_from_netdev(netdev);
  2852. done:
  2853. dst_release(dst);
  2854. if (dev)
  2855. cnic_put(dev);
  2856. return dev;
  2857. }
  2858. static int cnic_resolve_addr(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  2859. {
  2860. struct cnic_dev *dev = csk->dev;
  2861. struct cnic_local *cp = dev->cnic_priv;
  2862. return cnic_send_nlmsg(cp, ISCSI_KEVENT_PATH_REQ, csk);
  2863. }
  2864. static int cnic_get_route(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  2865. {
  2866. struct cnic_dev *dev = csk->dev;
  2867. struct cnic_local *cp = dev->cnic_priv;
  2868. int is_v6, rc = 0;
  2869. struct dst_entry *dst = NULL;
  2870. struct net_device *realdev;
  2871. __be16 local_port;
  2872. u32 port_id;
  2873. if (saddr->local.v6.sin6_family == AF_INET6 &&
  2874. saddr->remote.v6.sin6_family == AF_INET6)
  2875. is_v6 = 1;
  2876. else if (saddr->local.v4.sin_family == AF_INET &&
  2877. saddr->remote.v4.sin_family == AF_INET)
  2878. is_v6 = 0;
  2879. else
  2880. return -EINVAL;
  2881. clear_bit(SK_F_IPV6, &csk->flags);
  2882. if (is_v6) {
  2883. set_bit(SK_F_IPV6, &csk->flags);
  2884. cnic_get_v6_route(&saddr->remote.v6, &dst);
  2885. memcpy(&csk->dst_ip[0], &saddr->remote.v6.sin6_addr,
  2886. sizeof(struct in6_addr));
  2887. csk->dst_port = saddr->remote.v6.sin6_port;
  2888. local_port = saddr->local.v6.sin6_port;
  2889. } else {
  2890. cnic_get_v4_route(&saddr->remote.v4, &dst);
  2891. csk->dst_ip[0] = saddr->remote.v4.sin_addr.s_addr;
  2892. csk->dst_port = saddr->remote.v4.sin_port;
  2893. local_port = saddr->local.v4.sin_port;
  2894. }
  2895. csk->vlan_id = 0;
  2896. csk->mtu = dev->netdev->mtu;
  2897. if (dst && dst->dev) {
  2898. u16 vlan = cnic_get_vlan(dst->dev, &realdev);
  2899. if (realdev == dev->netdev) {
  2900. csk->vlan_id = vlan;
  2901. csk->mtu = dst_mtu(dst);
  2902. }
  2903. }
  2904. port_id = be16_to_cpu(local_port);
  2905. if (port_id >= CNIC_LOCAL_PORT_MIN &&
  2906. port_id < CNIC_LOCAL_PORT_MAX) {
  2907. if (cnic_alloc_id(&cp->csk_port_tbl, port_id))
  2908. port_id = 0;
  2909. } else
  2910. port_id = 0;
  2911. if (!port_id) {
  2912. port_id = cnic_alloc_new_id(&cp->csk_port_tbl);
  2913. if (port_id == -1) {
  2914. rc = -ENOMEM;
  2915. goto err_out;
  2916. }
  2917. local_port = cpu_to_be16(port_id);
  2918. }
  2919. csk->src_port = local_port;
  2920. err_out:
  2921. dst_release(dst);
  2922. return rc;
  2923. }
  2924. static void cnic_init_csk_state(struct cnic_sock *csk)
  2925. {
  2926. csk->state = 0;
  2927. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  2928. clear_bit(SK_F_CLOSING, &csk->flags);
  2929. }
  2930. static int cnic_cm_connect(struct cnic_sock *csk, struct cnic_sockaddr *saddr)
  2931. {
  2932. int err = 0;
  2933. if (!cnic_in_use(csk))
  2934. return -EINVAL;
  2935. if (test_and_set_bit(SK_F_CONNECT_START, &csk->flags))
  2936. return -EINVAL;
  2937. cnic_init_csk_state(csk);
  2938. err = cnic_get_route(csk, saddr);
  2939. if (err)
  2940. goto err_out;
  2941. err = cnic_resolve_addr(csk, saddr);
  2942. if (!err)
  2943. return 0;
  2944. err_out:
  2945. clear_bit(SK_F_CONNECT_START, &csk->flags);
  2946. return err;
  2947. }
  2948. static int cnic_cm_abort(struct cnic_sock *csk)
  2949. {
  2950. struct cnic_local *cp = csk->dev->cnic_priv;
  2951. u32 opcode = L4_KCQE_OPCODE_VALUE_RESET_COMP;
  2952. if (!cnic_in_use(csk))
  2953. return -EINVAL;
  2954. if (cnic_abort_prep(csk))
  2955. return cnic_cm_abort_req(csk);
  2956. /* Getting here means that we haven't started connect, or
  2957. * connect was not successful.
  2958. */
  2959. cp->close_conn(csk, opcode);
  2960. if (csk->state != opcode)
  2961. return -EALREADY;
  2962. return 0;
  2963. }
  2964. static int cnic_cm_close(struct cnic_sock *csk)
  2965. {
  2966. if (!cnic_in_use(csk))
  2967. return -EINVAL;
  2968. if (cnic_close_prep(csk)) {
  2969. csk->state = L4_KCQE_OPCODE_VALUE_CLOSE_COMP;
  2970. return cnic_cm_close_req(csk);
  2971. } else {
  2972. return -EALREADY;
  2973. }
  2974. return 0;
  2975. }
  2976. static void cnic_cm_upcall(struct cnic_local *cp, struct cnic_sock *csk,
  2977. u8 opcode)
  2978. {
  2979. struct cnic_ulp_ops *ulp_ops;
  2980. int ulp_type = csk->ulp_type;
  2981. rcu_read_lock();
  2982. ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
  2983. if (ulp_ops) {
  2984. if (opcode == L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE)
  2985. ulp_ops->cm_connect_complete(csk);
  2986. else if (opcode == L4_KCQE_OPCODE_VALUE_CLOSE_COMP)
  2987. ulp_ops->cm_close_complete(csk);
  2988. else if (opcode == L4_KCQE_OPCODE_VALUE_RESET_RECEIVED)
  2989. ulp_ops->cm_remote_abort(csk);
  2990. else if (opcode == L4_KCQE_OPCODE_VALUE_RESET_COMP)
  2991. ulp_ops->cm_abort_complete(csk);
  2992. else if (opcode == L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED)
  2993. ulp_ops->cm_remote_close(csk);
  2994. }
  2995. rcu_read_unlock();
  2996. }
  2997. static int cnic_cm_set_pg(struct cnic_sock *csk)
  2998. {
  2999. if (cnic_offld_prep(csk)) {
  3000. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags))
  3001. cnic_cm_update_pg(csk);
  3002. else
  3003. cnic_cm_offload_pg(csk);
  3004. }
  3005. return 0;
  3006. }
  3007. static void cnic_cm_process_offld_pg(struct cnic_dev *dev, struct l4_kcq *kcqe)
  3008. {
  3009. struct cnic_local *cp = dev->cnic_priv;
  3010. u32 l5_cid = kcqe->pg_host_opaque;
  3011. u8 opcode = kcqe->op_code;
  3012. struct cnic_sock *csk = &cp->csk_tbl[l5_cid];
  3013. csk_hold(csk);
  3014. if (!cnic_in_use(csk))
  3015. goto done;
  3016. if (opcode == L4_KCQE_OPCODE_VALUE_UPDATE_PG) {
  3017. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  3018. goto done;
  3019. }
  3020. /* Possible PG kcqe status: SUCCESS, OFFLOADED_PG, or CTX_ALLOC_FAIL */
  3021. if (kcqe->status == L4_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAIL) {
  3022. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  3023. cnic_cm_upcall(cp, csk,
  3024. L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE);
  3025. goto done;
  3026. }
  3027. csk->pg_cid = kcqe->pg_cid;
  3028. set_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags);
  3029. cnic_cm_conn_req(csk);
  3030. done:
  3031. csk_put(csk);
  3032. }
  3033. static void cnic_process_fcoe_term_conn(struct cnic_dev *dev, struct kcqe *kcqe)
  3034. {
  3035. struct cnic_local *cp = dev->cnic_priv;
  3036. struct fcoe_kcqe *fc_kcqe = (struct fcoe_kcqe *) kcqe;
  3037. u32 l5_cid = fc_kcqe->fcoe_conn_id + BNX2X_FCOE_L5_CID_BASE;
  3038. struct cnic_context *ctx = &cp->ctx_tbl[l5_cid];
  3039. ctx->timestamp = jiffies;
  3040. ctx->wait_cond = 1;
  3041. wake_up(&ctx->waitq);
  3042. }
  3043. static void cnic_cm_process_kcqe(struct cnic_dev *dev, struct kcqe *kcqe)
  3044. {
  3045. struct cnic_local *cp = dev->cnic_priv;
  3046. struct l4_kcq *l4kcqe = (struct l4_kcq *) kcqe;
  3047. u8 opcode = l4kcqe->op_code;
  3048. u32 l5_cid;
  3049. struct cnic_sock *csk;
  3050. if (opcode == FCOE_RAMROD_CMD_ID_TERMINATE_CONN) {
  3051. cnic_process_fcoe_term_conn(dev, kcqe);
  3052. return;
  3053. }
  3054. if (opcode == L4_KCQE_OPCODE_VALUE_OFFLOAD_PG ||
  3055. opcode == L4_KCQE_OPCODE_VALUE_UPDATE_PG) {
  3056. cnic_cm_process_offld_pg(dev, l4kcqe);
  3057. return;
  3058. }
  3059. l5_cid = l4kcqe->conn_id;
  3060. if (opcode & 0x80)
  3061. l5_cid = l4kcqe->cid;
  3062. if (l5_cid >= MAX_CM_SK_TBL_SZ)
  3063. return;
  3064. csk = &cp->csk_tbl[l5_cid];
  3065. csk_hold(csk);
  3066. if (!cnic_in_use(csk)) {
  3067. csk_put(csk);
  3068. return;
  3069. }
  3070. switch (opcode) {
  3071. case L5CM_RAMROD_CMD_ID_TCP_CONNECT:
  3072. if (l4kcqe->status != 0) {
  3073. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  3074. cnic_cm_upcall(cp, csk,
  3075. L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE);
  3076. }
  3077. break;
  3078. case L4_KCQE_OPCODE_VALUE_CONNECT_COMPLETE:
  3079. if (l4kcqe->status == 0)
  3080. set_bit(SK_F_OFFLD_COMPLETE, &csk->flags);
  3081. smp_mb__before_clear_bit();
  3082. clear_bit(SK_F_OFFLD_SCHED, &csk->flags);
  3083. cnic_cm_upcall(cp, csk, opcode);
  3084. break;
  3085. case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED:
  3086. case L4_KCQE_OPCODE_VALUE_CLOSE_COMP:
  3087. case L4_KCQE_OPCODE_VALUE_RESET_COMP:
  3088. case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE:
  3089. case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD:
  3090. cp->close_conn(csk, opcode);
  3091. break;
  3092. case L4_KCQE_OPCODE_VALUE_CLOSE_RECEIVED:
  3093. cnic_cm_upcall(cp, csk, opcode);
  3094. break;
  3095. }
  3096. csk_put(csk);
  3097. }
  3098. static void cnic_cm_indicate_kcqe(void *data, struct kcqe *kcqe[], u32 num)
  3099. {
  3100. struct cnic_dev *dev = data;
  3101. int i;
  3102. for (i = 0; i < num; i++)
  3103. cnic_cm_process_kcqe(dev, kcqe[i]);
  3104. }
  3105. static struct cnic_ulp_ops cm_ulp_ops = {
  3106. .indicate_kcqes = cnic_cm_indicate_kcqe,
  3107. };
  3108. static void cnic_cm_free_mem(struct cnic_dev *dev)
  3109. {
  3110. struct cnic_local *cp = dev->cnic_priv;
  3111. kfree(cp->csk_tbl);
  3112. cp->csk_tbl = NULL;
  3113. cnic_free_id_tbl(&cp->csk_port_tbl);
  3114. }
  3115. static int cnic_cm_alloc_mem(struct cnic_dev *dev)
  3116. {
  3117. struct cnic_local *cp = dev->cnic_priv;
  3118. cp->csk_tbl = kzalloc(sizeof(struct cnic_sock) * MAX_CM_SK_TBL_SZ,
  3119. GFP_KERNEL);
  3120. if (!cp->csk_tbl)
  3121. return -ENOMEM;
  3122. if (cnic_init_id_tbl(&cp->csk_port_tbl, CNIC_LOCAL_PORT_RANGE,
  3123. CNIC_LOCAL_PORT_MIN)) {
  3124. cnic_cm_free_mem(dev);
  3125. return -ENOMEM;
  3126. }
  3127. return 0;
  3128. }
  3129. static int cnic_ready_to_close(struct cnic_sock *csk, u32 opcode)
  3130. {
  3131. if (test_and_clear_bit(SK_F_OFFLD_COMPLETE, &csk->flags)) {
  3132. /* Unsolicited RESET_COMP or RESET_RECEIVED */
  3133. opcode = L4_KCQE_OPCODE_VALUE_RESET_RECEIVED;
  3134. csk->state = opcode;
  3135. }
  3136. /* 1. If event opcode matches the expected event in csk->state
  3137. * 2. If the expected event is CLOSE_COMP, we accept any event
  3138. * 3. If the expected event is 0, meaning the connection was never
  3139. * never established, we accept the opcode from cm_abort.
  3140. */
  3141. if (opcode == csk->state || csk->state == 0 ||
  3142. csk->state == L4_KCQE_OPCODE_VALUE_CLOSE_COMP) {
  3143. if (!test_and_set_bit(SK_F_CLOSING, &csk->flags)) {
  3144. if (csk->state == 0)
  3145. csk->state = opcode;
  3146. return 1;
  3147. }
  3148. }
  3149. return 0;
  3150. }
  3151. static void cnic_close_bnx2_conn(struct cnic_sock *csk, u32 opcode)
  3152. {
  3153. struct cnic_dev *dev = csk->dev;
  3154. struct cnic_local *cp = dev->cnic_priv;
  3155. if (opcode == L4_KCQE_OPCODE_VALUE_RESET_RECEIVED) {
  3156. cnic_cm_upcall(cp, csk, opcode);
  3157. return;
  3158. }
  3159. clear_bit(SK_F_CONNECT_START, &csk->flags);
  3160. cnic_close_conn(csk);
  3161. csk->state = opcode;
  3162. cnic_cm_upcall(cp, csk, opcode);
  3163. }
  3164. static void cnic_cm_stop_bnx2_hw(struct cnic_dev *dev)
  3165. {
  3166. }
  3167. static int cnic_cm_init_bnx2_hw(struct cnic_dev *dev)
  3168. {
  3169. u32 seed;
  3170. get_random_bytes(&seed, 4);
  3171. cnic_ctx_wr(dev, 45, 0, seed);
  3172. return 0;
  3173. }
  3174. static void cnic_close_bnx2x_conn(struct cnic_sock *csk, u32 opcode)
  3175. {
  3176. struct cnic_dev *dev = csk->dev;
  3177. struct cnic_local *cp = dev->cnic_priv;
  3178. struct cnic_context *ctx = &cp->ctx_tbl[csk->l5_cid];
  3179. union l5cm_specific_data l5_data;
  3180. u32 cmd = 0;
  3181. int close_complete = 0;
  3182. switch (opcode) {
  3183. case L4_KCQE_OPCODE_VALUE_RESET_RECEIVED:
  3184. case L4_KCQE_OPCODE_VALUE_CLOSE_COMP:
  3185. case L4_KCQE_OPCODE_VALUE_RESET_COMP:
  3186. if (cnic_ready_to_close(csk, opcode)) {
  3187. if (test_bit(SK_F_PG_OFFLD_COMPLETE, &csk->flags))
  3188. cmd = L5CM_RAMROD_CMD_ID_SEARCHER_DELETE;
  3189. else
  3190. close_complete = 1;
  3191. }
  3192. break;
  3193. case L5CM_RAMROD_CMD_ID_SEARCHER_DELETE:
  3194. cmd = L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD;
  3195. break;
  3196. case L5CM_RAMROD_CMD_ID_TERMINATE_OFFLOAD:
  3197. close_complete = 1;
  3198. break;
  3199. }
  3200. if (cmd) {
  3201. memset(&l5_data, 0, sizeof(l5_data));
  3202. cnic_submit_kwqe_16(dev, cmd, csk->cid, ISCSI_CONNECTION_TYPE,
  3203. &l5_data);
  3204. } else if (close_complete) {
  3205. ctx->timestamp = jiffies;
  3206. cnic_close_conn(csk);
  3207. cnic_cm_upcall(cp, csk, csk->state);
  3208. }
  3209. }
  3210. static void cnic_cm_stop_bnx2x_hw(struct cnic_dev *dev)
  3211. {
  3212. struct cnic_local *cp = dev->cnic_priv;
  3213. int i;
  3214. if (!cp->ctx_tbl)
  3215. return;
  3216. if (!netif_running(dev->netdev))
  3217. return;
  3218. for (i = 0; i < cp->max_cid_space; i++) {
  3219. struct cnic_context *ctx = &cp->ctx_tbl[i];
  3220. while (test_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags))
  3221. msleep(10);
  3222. if (test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags))
  3223. netdev_warn(dev->netdev, "CID %x not deleted\n",
  3224. ctx->cid);
  3225. }
  3226. cancel_delayed_work(&cp->delete_task);
  3227. flush_workqueue(cnic_wq);
  3228. if (atomic_read(&cp->iscsi_conn) != 0)
  3229. netdev_warn(dev->netdev, "%d iSCSI connections not destroyed\n",
  3230. atomic_read(&cp->iscsi_conn));
  3231. }
  3232. static int cnic_cm_init_bnx2x_hw(struct cnic_dev *dev)
  3233. {
  3234. struct cnic_local *cp = dev->cnic_priv;
  3235. u32 pfid = cp->pfid;
  3236. u32 port = CNIC_PORT(cp);
  3237. cnic_init_bnx2x_mac(dev);
  3238. cnic_bnx2x_set_tcp_timestamp(dev, 1);
  3239. CNIC_WR16(dev, BAR_XSTRORM_INTMEM +
  3240. XSTORM_ISCSI_LOCAL_VLAN_OFFSET(pfid), 0);
  3241. CNIC_WR(dev, BAR_XSTRORM_INTMEM +
  3242. XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_ENABLED_OFFSET(port), 1);
  3243. CNIC_WR(dev, BAR_XSTRORM_INTMEM +
  3244. XSTORM_TCP_GLOBAL_DEL_ACK_COUNTER_MAX_COUNT_OFFSET(port),
  3245. DEF_MAX_DA_COUNT);
  3246. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  3247. XSTORM_ISCSI_TCP_VARS_TTL_OFFSET(pfid), DEF_TTL);
  3248. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  3249. XSTORM_ISCSI_TCP_VARS_TOS_OFFSET(pfid), DEF_TOS);
  3250. CNIC_WR8(dev, BAR_XSTRORM_INTMEM +
  3251. XSTORM_ISCSI_TCP_VARS_ADV_WND_SCL_OFFSET(pfid), 2);
  3252. CNIC_WR(dev, BAR_XSTRORM_INTMEM +
  3253. XSTORM_TCP_TX_SWS_TIMER_VAL_OFFSET(pfid), DEF_SWS_TIMER);
  3254. CNIC_WR(dev, BAR_TSTRORM_INTMEM + TSTORM_TCP_MAX_CWND_OFFSET(pfid),
  3255. DEF_MAX_CWND);
  3256. return 0;
  3257. }
  3258. static void cnic_delete_task(struct work_struct *work)
  3259. {
  3260. struct cnic_local *cp;
  3261. struct cnic_dev *dev;
  3262. u32 i;
  3263. int need_resched = 0;
  3264. cp = container_of(work, struct cnic_local, delete_task.work);
  3265. dev = cp->dev;
  3266. for (i = 0; i < cp->max_cid_space; i++) {
  3267. struct cnic_context *ctx = &cp->ctx_tbl[i];
  3268. if (!test_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags) ||
  3269. !test_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags))
  3270. continue;
  3271. if (!time_after(jiffies, ctx->timestamp + (2 * HZ))) {
  3272. need_resched = 1;
  3273. continue;
  3274. }
  3275. if (!test_and_clear_bit(CTX_FL_DELETE_WAIT, &ctx->ctx_flags))
  3276. continue;
  3277. cnic_bnx2x_destroy_ramrod(dev, i);
  3278. cnic_free_bnx2x_conn_resc(dev, i);
  3279. if (ctx->ulp_proto_id == CNIC_ULP_ISCSI)
  3280. atomic_dec(&cp->iscsi_conn);
  3281. clear_bit(CTX_FL_OFFLD_START, &ctx->ctx_flags);
  3282. }
  3283. if (need_resched)
  3284. queue_delayed_work(cnic_wq, &cp->delete_task,
  3285. msecs_to_jiffies(10));
  3286. }
  3287. static int cnic_cm_open(struct cnic_dev *dev)
  3288. {
  3289. struct cnic_local *cp = dev->cnic_priv;
  3290. int err;
  3291. err = cnic_cm_alloc_mem(dev);
  3292. if (err)
  3293. return err;
  3294. err = cp->start_cm(dev);
  3295. if (err)
  3296. goto err_out;
  3297. INIT_DELAYED_WORK(&cp->delete_task, cnic_delete_task);
  3298. dev->cm_create = cnic_cm_create;
  3299. dev->cm_destroy = cnic_cm_destroy;
  3300. dev->cm_connect = cnic_cm_connect;
  3301. dev->cm_abort = cnic_cm_abort;
  3302. dev->cm_close = cnic_cm_close;
  3303. dev->cm_select_dev = cnic_cm_select_dev;
  3304. cp->ulp_handle[CNIC_ULP_L4] = dev;
  3305. rcu_assign_pointer(cp->ulp_ops[CNIC_ULP_L4], &cm_ulp_ops);
  3306. return 0;
  3307. err_out:
  3308. cnic_cm_free_mem(dev);
  3309. return err;
  3310. }
  3311. static int cnic_cm_shutdown(struct cnic_dev *dev)
  3312. {
  3313. struct cnic_local *cp = dev->cnic_priv;
  3314. int i;
  3315. cp->stop_cm(dev);
  3316. if (!cp->csk_tbl)
  3317. return 0;
  3318. for (i = 0; i < MAX_CM_SK_TBL_SZ; i++) {
  3319. struct cnic_sock *csk = &cp->csk_tbl[i];
  3320. clear_bit(SK_F_INUSE, &csk->flags);
  3321. cnic_cm_cleanup(csk);
  3322. }
  3323. cnic_cm_free_mem(dev);
  3324. return 0;
  3325. }
  3326. static void cnic_init_context(struct cnic_dev *dev, u32 cid)
  3327. {
  3328. u32 cid_addr;
  3329. int i;
  3330. cid_addr = GET_CID_ADDR(cid);
  3331. for (i = 0; i < CTX_SIZE; i += 4)
  3332. cnic_ctx_wr(dev, cid_addr, i, 0);
  3333. }
  3334. static int cnic_setup_5709_context(struct cnic_dev *dev, int valid)
  3335. {
  3336. struct cnic_local *cp = dev->cnic_priv;
  3337. int ret = 0, i;
  3338. u32 valid_bit = valid ? BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID : 0;
  3339. if (CHIP_NUM(cp) != CHIP_NUM_5709)
  3340. return 0;
  3341. for (i = 0; i < cp->ctx_blks; i++) {
  3342. int j;
  3343. u32 idx = cp->ctx_arr[i].cid / cp->cids_per_blk;
  3344. u32 val;
  3345. memset(cp->ctx_arr[i].ctx, 0, BCM_PAGE_SIZE);
  3346. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA0,
  3347. (cp->ctx_arr[i].mapping & 0xffffffff) | valid_bit);
  3348. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_DATA1,
  3349. (u64) cp->ctx_arr[i].mapping >> 32);
  3350. CNIC_WR(dev, BNX2_CTX_HOST_PAGE_TBL_CTRL, idx |
  3351. BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
  3352. for (j = 0; j < 10; j++) {
  3353. val = CNIC_RD(dev, BNX2_CTX_HOST_PAGE_TBL_CTRL);
  3354. if (!(val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ))
  3355. break;
  3356. udelay(5);
  3357. }
  3358. if (val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) {
  3359. ret = -EBUSY;
  3360. break;
  3361. }
  3362. }
  3363. return ret;
  3364. }
  3365. static void cnic_free_irq(struct cnic_dev *dev)
  3366. {
  3367. struct cnic_local *cp = dev->cnic_priv;
  3368. struct cnic_eth_dev *ethdev = cp->ethdev;
  3369. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3370. cp->disable_int_sync(dev);
  3371. tasklet_kill(&cp->cnic_irq_task);
  3372. free_irq(ethdev->irq_arr[0].vector, dev);
  3373. }
  3374. }
  3375. static int cnic_request_irq(struct cnic_dev *dev)
  3376. {
  3377. struct cnic_local *cp = dev->cnic_priv;
  3378. struct cnic_eth_dev *ethdev = cp->ethdev;
  3379. int err;
  3380. err = request_irq(ethdev->irq_arr[0].vector, cnic_irq, 0, "cnic", dev);
  3381. if (err)
  3382. tasklet_disable(&cp->cnic_irq_task);
  3383. return err;
  3384. }
  3385. static int cnic_init_bnx2_irq(struct cnic_dev *dev)
  3386. {
  3387. struct cnic_local *cp = dev->cnic_priv;
  3388. struct cnic_eth_dev *ethdev = cp->ethdev;
  3389. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3390. int err, i = 0;
  3391. int sblk_num = cp->status_blk_num;
  3392. u32 base = ((sblk_num - 1) * BNX2_HC_SB_CONFIG_SIZE) +
  3393. BNX2_HC_SB_CONFIG_1;
  3394. CNIC_WR(dev, base, BNX2_HC_SB_CONFIG_1_ONE_SHOT);
  3395. CNIC_WR(dev, base + BNX2_HC_COMP_PROD_TRIP_OFF, (2 << 16) | 8);
  3396. CNIC_WR(dev, base + BNX2_HC_COM_TICKS_OFF, (64 << 16) | 220);
  3397. CNIC_WR(dev, base + BNX2_HC_CMD_TICKS_OFF, (64 << 16) | 220);
  3398. cp->last_status_idx = cp->status_blk.bnx2->status_idx;
  3399. tasklet_init(&cp->cnic_irq_task, cnic_service_bnx2_msix,
  3400. (unsigned long) dev);
  3401. err = cnic_request_irq(dev);
  3402. if (err)
  3403. return err;
  3404. while (cp->status_blk.bnx2->status_completion_producer_index &&
  3405. i < 10) {
  3406. CNIC_WR(dev, BNX2_HC_COALESCE_NOW,
  3407. 1 << (11 + sblk_num));
  3408. udelay(10);
  3409. i++;
  3410. barrier();
  3411. }
  3412. if (cp->status_blk.bnx2->status_completion_producer_index) {
  3413. cnic_free_irq(dev);
  3414. goto failed;
  3415. }
  3416. } else {
  3417. struct status_block *sblk = cp->status_blk.gen;
  3418. u32 hc_cmd = CNIC_RD(dev, BNX2_HC_COMMAND);
  3419. int i = 0;
  3420. while (sblk->status_completion_producer_index && i < 10) {
  3421. CNIC_WR(dev, BNX2_HC_COMMAND,
  3422. hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3423. udelay(10);
  3424. i++;
  3425. barrier();
  3426. }
  3427. if (sblk->status_completion_producer_index)
  3428. goto failed;
  3429. }
  3430. return 0;
  3431. failed:
  3432. netdev_err(dev->netdev, "KCQ index not resetting to 0\n");
  3433. return -EBUSY;
  3434. }
  3435. static void cnic_enable_bnx2_int(struct cnic_dev *dev)
  3436. {
  3437. struct cnic_local *cp = dev->cnic_priv;
  3438. struct cnic_eth_dev *ethdev = cp->ethdev;
  3439. if (!(ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX))
  3440. return;
  3441. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  3442. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | cp->last_status_idx);
  3443. }
  3444. static void cnic_disable_bnx2_int_sync(struct cnic_dev *dev)
  3445. {
  3446. struct cnic_local *cp = dev->cnic_priv;
  3447. struct cnic_eth_dev *ethdev = cp->ethdev;
  3448. if (!(ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX))
  3449. return;
  3450. CNIC_WR(dev, BNX2_PCICFG_INT_ACK_CMD, cp->int_num |
  3451. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  3452. CNIC_RD(dev, BNX2_PCICFG_INT_ACK_CMD);
  3453. synchronize_irq(ethdev->irq_arr[0].vector);
  3454. }
  3455. static void cnic_init_bnx2_tx_ring(struct cnic_dev *dev)
  3456. {
  3457. struct cnic_local *cp = dev->cnic_priv;
  3458. struct cnic_eth_dev *ethdev = cp->ethdev;
  3459. struct cnic_uio_dev *udev = cp->udev;
  3460. u32 cid_addr, tx_cid, sb_id;
  3461. u32 val, offset0, offset1, offset2, offset3;
  3462. int i;
  3463. struct tx_bd *txbd;
  3464. dma_addr_t buf_map, ring_map = udev->l2_ring_map;
  3465. struct status_block *s_blk = cp->status_blk.gen;
  3466. sb_id = cp->status_blk_num;
  3467. tx_cid = 20;
  3468. cp->tx_cons_ptr = &s_blk->status_tx_quick_consumer_index2;
  3469. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3470. struct status_block_msix *sblk = cp->status_blk.bnx2;
  3471. tx_cid = TX_TSS_CID + sb_id - 1;
  3472. CNIC_WR(dev, BNX2_TSCH_TSS_CFG, (sb_id << 24) |
  3473. (TX_TSS_CID << 7));
  3474. cp->tx_cons_ptr = &sblk->status_tx_quick_consumer_index;
  3475. }
  3476. cp->tx_cons = *cp->tx_cons_ptr;
  3477. cid_addr = GET_CID_ADDR(tx_cid);
  3478. if (CHIP_NUM(cp) == CHIP_NUM_5709) {
  3479. u32 cid_addr2 = GET_CID_ADDR(tx_cid + 4) + 0x40;
  3480. for (i = 0; i < PHY_CTX_SIZE; i += 4)
  3481. cnic_ctx_wr(dev, cid_addr2, i, 0);
  3482. offset0 = BNX2_L2CTX_TYPE_XI;
  3483. offset1 = BNX2_L2CTX_CMD_TYPE_XI;
  3484. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI_XI;
  3485. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO_XI;
  3486. } else {
  3487. cnic_init_context(dev, tx_cid);
  3488. cnic_init_context(dev, tx_cid + 1);
  3489. offset0 = BNX2_L2CTX_TYPE;
  3490. offset1 = BNX2_L2CTX_CMD_TYPE;
  3491. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI;
  3492. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO;
  3493. }
  3494. val = BNX2_L2CTX_TYPE_TYPE_L2 | BNX2_L2CTX_TYPE_SIZE_L2;
  3495. cnic_ctx_wr(dev, cid_addr, offset0, val);
  3496. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
  3497. cnic_ctx_wr(dev, cid_addr, offset1, val);
  3498. txbd = (struct tx_bd *) udev->l2_ring;
  3499. buf_map = udev->l2_buf_map;
  3500. for (i = 0; i < MAX_TX_DESC_CNT; i++, txbd++) {
  3501. txbd->tx_bd_haddr_hi = (u64) buf_map >> 32;
  3502. txbd->tx_bd_haddr_lo = (u64) buf_map & 0xffffffff;
  3503. }
  3504. val = (u64) ring_map >> 32;
  3505. cnic_ctx_wr(dev, cid_addr, offset2, val);
  3506. txbd->tx_bd_haddr_hi = val;
  3507. val = (u64) ring_map & 0xffffffff;
  3508. cnic_ctx_wr(dev, cid_addr, offset3, val);
  3509. txbd->tx_bd_haddr_lo = val;
  3510. }
  3511. static void cnic_init_bnx2_rx_ring(struct cnic_dev *dev)
  3512. {
  3513. struct cnic_local *cp = dev->cnic_priv;
  3514. struct cnic_eth_dev *ethdev = cp->ethdev;
  3515. struct cnic_uio_dev *udev = cp->udev;
  3516. u32 cid_addr, sb_id, val, coal_reg, coal_val;
  3517. int i;
  3518. struct rx_bd *rxbd;
  3519. struct status_block *s_blk = cp->status_blk.gen;
  3520. dma_addr_t ring_map = udev->l2_ring_map;
  3521. sb_id = cp->status_blk_num;
  3522. cnic_init_context(dev, 2);
  3523. cp->rx_cons_ptr = &s_blk->status_rx_quick_consumer_index2;
  3524. coal_reg = BNX2_HC_COMMAND;
  3525. coal_val = CNIC_RD(dev, coal_reg);
  3526. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3527. struct status_block_msix *sblk = cp->status_blk.bnx2;
  3528. cp->rx_cons_ptr = &sblk->status_rx_quick_consumer_index;
  3529. coal_reg = BNX2_HC_COALESCE_NOW;
  3530. coal_val = 1 << (11 + sb_id);
  3531. }
  3532. i = 0;
  3533. while (!(*cp->rx_cons_ptr != 0) && i < 10) {
  3534. CNIC_WR(dev, coal_reg, coal_val);
  3535. udelay(10);
  3536. i++;
  3537. barrier();
  3538. }
  3539. cp->rx_cons = *cp->rx_cons_ptr;
  3540. cid_addr = GET_CID_ADDR(2);
  3541. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE |
  3542. BNX2_L2CTX_CTX_TYPE_SIZE_L2 | (0x02 << 8);
  3543. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_CTX_TYPE, val);
  3544. if (sb_id == 0)
  3545. val = 2 << BNX2_L2CTX_L2_STATUSB_NUM_SHIFT;
  3546. else
  3547. val = BNX2_L2CTX_L2_STATUSB_NUM(sb_id);
  3548. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_HOST_BDIDX, val);
  3549. rxbd = (struct rx_bd *) (udev->l2_ring + BCM_PAGE_SIZE);
  3550. for (i = 0; i < MAX_RX_DESC_CNT; i++, rxbd++) {
  3551. dma_addr_t buf_map;
  3552. int n = (i % cp->l2_rx_ring_size) + 1;
  3553. buf_map = udev->l2_buf_map + (n * cp->l2_single_buf_size);
  3554. rxbd->rx_bd_len = cp->l2_single_buf_size;
  3555. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  3556. rxbd->rx_bd_haddr_hi = (u64) buf_map >> 32;
  3557. rxbd->rx_bd_haddr_lo = (u64) buf_map & 0xffffffff;
  3558. }
  3559. val = (u64) (ring_map + BCM_PAGE_SIZE) >> 32;
  3560. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_HI, val);
  3561. rxbd->rx_bd_haddr_hi = val;
  3562. val = (u64) (ring_map + BCM_PAGE_SIZE) & 0xffffffff;
  3563. cnic_ctx_wr(dev, cid_addr, BNX2_L2CTX_NX_BDHADDR_LO, val);
  3564. rxbd->rx_bd_haddr_lo = val;
  3565. val = cnic_reg_rd_ind(dev, BNX2_RXP_SCRATCH_RXP_FLOOD);
  3566. cnic_reg_wr_ind(dev, BNX2_RXP_SCRATCH_RXP_FLOOD, val | (1 << 2));
  3567. }
  3568. static void cnic_shutdown_bnx2_rx_ring(struct cnic_dev *dev)
  3569. {
  3570. struct kwqe *wqes[1], l2kwqe;
  3571. memset(&l2kwqe, 0, sizeof(l2kwqe));
  3572. wqes[0] = &l2kwqe;
  3573. l2kwqe.kwqe_op_flag = (L2_LAYER_CODE << KWQE_LAYER_SHIFT) |
  3574. (L2_KWQE_OPCODE_VALUE_FLUSH <<
  3575. KWQE_OPCODE_SHIFT) | 2;
  3576. dev->submit_kwqes(dev, wqes, 1);
  3577. }
  3578. static void cnic_set_bnx2_mac(struct cnic_dev *dev)
  3579. {
  3580. struct cnic_local *cp = dev->cnic_priv;
  3581. u32 val;
  3582. val = cp->func << 2;
  3583. cp->shmem_base = cnic_reg_rd_ind(dev, BNX2_SHM_HDR_ADDR_0 + val);
  3584. val = cnic_reg_rd_ind(dev, cp->shmem_base +
  3585. BNX2_PORT_HW_CFG_ISCSI_MAC_UPPER);
  3586. dev->mac_addr[0] = (u8) (val >> 8);
  3587. dev->mac_addr[1] = (u8) val;
  3588. CNIC_WR(dev, BNX2_EMAC_MAC_MATCH4, val);
  3589. val = cnic_reg_rd_ind(dev, cp->shmem_base +
  3590. BNX2_PORT_HW_CFG_ISCSI_MAC_LOWER);
  3591. dev->mac_addr[2] = (u8) (val >> 24);
  3592. dev->mac_addr[3] = (u8) (val >> 16);
  3593. dev->mac_addr[4] = (u8) (val >> 8);
  3594. dev->mac_addr[5] = (u8) val;
  3595. CNIC_WR(dev, BNX2_EMAC_MAC_MATCH5, val);
  3596. val = 4 | BNX2_RPM_SORT_USER2_BC_EN;
  3597. if (CHIP_NUM(cp) != CHIP_NUM_5709)
  3598. val |= BNX2_RPM_SORT_USER2_PROM_VLAN;
  3599. CNIC_WR(dev, BNX2_RPM_SORT_USER2, 0x0);
  3600. CNIC_WR(dev, BNX2_RPM_SORT_USER2, val);
  3601. CNIC_WR(dev, BNX2_RPM_SORT_USER2, val | BNX2_RPM_SORT_USER2_ENA);
  3602. }
  3603. static int cnic_start_bnx2_hw(struct cnic_dev *dev)
  3604. {
  3605. struct cnic_local *cp = dev->cnic_priv;
  3606. struct cnic_eth_dev *ethdev = cp->ethdev;
  3607. struct status_block *sblk = cp->status_blk.gen;
  3608. u32 val, kcq_cid_addr, kwq_cid_addr;
  3609. int err;
  3610. cnic_set_bnx2_mac(dev);
  3611. val = CNIC_RD(dev, BNX2_MQ_CONFIG);
  3612. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  3613. if (BCM_PAGE_BITS > 12)
  3614. val |= (12 - 8) << 4;
  3615. else
  3616. val |= (BCM_PAGE_BITS - 8) << 4;
  3617. CNIC_WR(dev, BNX2_MQ_CONFIG, val);
  3618. CNIC_WR(dev, BNX2_HC_COMP_PROD_TRIP, (2 << 16) | 8);
  3619. CNIC_WR(dev, BNX2_HC_COM_TICKS, (64 << 16) | 220);
  3620. CNIC_WR(dev, BNX2_HC_CMD_TICKS, (64 << 16) | 220);
  3621. err = cnic_setup_5709_context(dev, 1);
  3622. if (err)
  3623. return err;
  3624. cnic_init_context(dev, KWQ_CID);
  3625. cnic_init_context(dev, KCQ_CID);
  3626. kwq_cid_addr = GET_CID_ADDR(KWQ_CID);
  3627. cp->kwq_io_addr = MB_GET_CID_ADDR(KWQ_CID) + L5_KRNLQ_HOST_QIDX;
  3628. cp->max_kwq_idx = MAX_KWQ_IDX;
  3629. cp->kwq_prod_idx = 0;
  3630. cp->kwq_con_idx = 0;
  3631. set_bit(CNIC_LCL_FL_KWQ_INIT, &cp->cnic_local_flags);
  3632. if (CHIP_NUM(cp) == CHIP_NUM_5706 || CHIP_NUM(cp) == CHIP_NUM_5708)
  3633. cp->kwq_con_idx_ptr = &sblk->status_rx_quick_consumer_index15;
  3634. else
  3635. cp->kwq_con_idx_ptr = &sblk->status_cmd_consumer_index;
  3636. /* Initialize the kernel work queue context. */
  3637. val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
  3638. (BCM_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
  3639. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_TYPE, val);
  3640. val = (BCM_PAGE_SIZE / sizeof(struct kwqe) - 1) << 16;
  3641. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
  3642. val = ((BCM_PAGE_SIZE / sizeof(struct kwqe)) << 16) | KWQ_PAGE_CNT;
  3643. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
  3644. val = (u32) ((u64) cp->kwq_info.pgtbl_map >> 32);
  3645. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_HADDR_HI, val);
  3646. val = (u32) cp->kwq_info.pgtbl_map;
  3647. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_PGTBL_HADDR_LO, val);
  3648. kcq_cid_addr = GET_CID_ADDR(KCQ_CID);
  3649. cp->kcq1.io_addr = MB_GET_CID_ADDR(KCQ_CID) + L5_KRNLQ_HOST_QIDX;
  3650. cp->kcq1.sw_prod_idx = 0;
  3651. cp->kcq1.hw_prod_idx_ptr =
  3652. (u16 *) &sblk->status_completion_producer_index;
  3653. cp->kcq1.status_idx_ptr = (u16 *) &sblk->status_idx;
  3654. /* Initialize the kernel complete queue context. */
  3655. val = KRNLQ_TYPE_TYPE_KRNLQ | KRNLQ_SIZE_TYPE_SIZE |
  3656. (BCM_PAGE_BITS - 8) | KRNLQ_FLAGS_QE_SELF_SEQ;
  3657. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_TYPE, val);
  3658. val = (BCM_PAGE_SIZE / sizeof(struct kcqe) - 1) << 16;
  3659. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_QE_SELF_SEQ_MAX, val);
  3660. val = ((BCM_PAGE_SIZE / sizeof(struct kcqe)) << 16) | KCQ_PAGE_CNT;
  3661. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_NPAGES, val);
  3662. val = (u32) ((u64) cp->kcq1.dma.pgtbl_map >> 32);
  3663. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_HADDR_HI, val);
  3664. val = (u32) cp->kcq1.dma.pgtbl_map;
  3665. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_PGTBL_HADDR_LO, val);
  3666. cp->int_num = 0;
  3667. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX) {
  3668. struct status_block_msix *msblk = cp->status_blk.bnx2;
  3669. u32 sb_id = cp->status_blk_num;
  3670. u32 sb = BNX2_L2CTX_L5_STATUSB_NUM(sb_id);
  3671. cp->kcq1.hw_prod_idx_ptr =
  3672. (u16 *) &msblk->status_completion_producer_index;
  3673. cp->kcq1.status_idx_ptr = (u16 *) &msblk->status_idx;
  3674. cp->kwq_con_idx_ptr = (u16 *) &msblk->status_cmd_consumer_index;
  3675. cp->int_num = sb_id << BNX2_PCICFG_INT_ACK_CMD_INT_NUM_SHIFT;
  3676. cnic_ctx_wr(dev, kwq_cid_addr, L5_KRNLQ_HOST_QIDX, sb);
  3677. cnic_ctx_wr(dev, kcq_cid_addr, L5_KRNLQ_HOST_QIDX, sb);
  3678. }
  3679. /* Enable Commnad Scheduler notification when we write to the
  3680. * host producer index of the kernel contexts. */
  3681. CNIC_WR(dev, BNX2_MQ_KNL_CMD_MASK1, 2);
  3682. /* Enable Command Scheduler notification when we write to either
  3683. * the Send Queue or Receive Queue producer indexes of the kernel
  3684. * bypass contexts. */
  3685. CNIC_WR(dev, BNX2_MQ_KNL_BYP_CMD_MASK1, 7);
  3686. CNIC_WR(dev, BNX2_MQ_KNL_BYP_WRITE_MASK1, 7);
  3687. /* Notify COM when the driver post an application buffer. */
  3688. CNIC_WR(dev, BNX2_MQ_KNL_RX_V2P_MASK2, 0x2000);
  3689. /* Set the CP and COM doorbells. These two processors polls the
  3690. * doorbell for a non zero value before running. This must be done
  3691. * after setting up the kernel queue contexts. */
  3692. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 1);
  3693. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 1);
  3694. cnic_init_bnx2_tx_ring(dev);
  3695. cnic_init_bnx2_rx_ring(dev);
  3696. err = cnic_init_bnx2_irq(dev);
  3697. if (err) {
  3698. netdev_err(dev->netdev, "cnic_init_irq failed\n");
  3699. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 0);
  3700. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 0);
  3701. return err;
  3702. }
  3703. return 0;
  3704. }
  3705. static void cnic_setup_bnx2x_context(struct cnic_dev *dev)
  3706. {
  3707. struct cnic_local *cp = dev->cnic_priv;
  3708. struct cnic_eth_dev *ethdev = cp->ethdev;
  3709. u32 start_offset = ethdev->ctx_tbl_offset;
  3710. int i;
  3711. for (i = 0; i < cp->ctx_blks; i++) {
  3712. struct cnic_ctx *ctx = &cp->ctx_arr[i];
  3713. dma_addr_t map = ctx->mapping;
  3714. if (cp->ctx_align) {
  3715. unsigned long mask = cp->ctx_align - 1;
  3716. map = (map + mask) & ~mask;
  3717. }
  3718. cnic_ctx_tbl_wr(dev, start_offset + i, map);
  3719. }
  3720. }
  3721. static int cnic_init_bnx2x_irq(struct cnic_dev *dev)
  3722. {
  3723. struct cnic_local *cp = dev->cnic_priv;
  3724. struct cnic_eth_dev *ethdev = cp->ethdev;
  3725. int err = 0;
  3726. tasklet_init(&cp->cnic_irq_task, cnic_service_bnx2x_bh,
  3727. (unsigned long) dev);
  3728. if (ethdev->drv_state & CNIC_DRV_STATE_USING_MSIX)
  3729. err = cnic_request_irq(dev);
  3730. return err;
  3731. }
  3732. static inline void cnic_storm_memset_hc_disable(struct cnic_dev *dev,
  3733. u16 sb_id, u8 sb_index,
  3734. u8 disable)
  3735. {
  3736. u32 addr = BAR_CSTRORM_INTMEM +
  3737. CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id) +
  3738. offsetof(struct hc_status_block_data_e1x, index_data) +
  3739. sizeof(struct hc_index_data)*sb_index +
  3740. offsetof(struct hc_index_data, flags);
  3741. u16 flags = CNIC_RD16(dev, addr);
  3742. /* clear and set */
  3743. flags &= ~HC_INDEX_DATA_HC_ENABLED;
  3744. flags |= (((~disable) << HC_INDEX_DATA_HC_ENABLED_SHIFT) &
  3745. HC_INDEX_DATA_HC_ENABLED);
  3746. CNIC_WR16(dev, addr, flags);
  3747. }
  3748. static void cnic_enable_bnx2x_int(struct cnic_dev *dev)
  3749. {
  3750. struct cnic_local *cp = dev->cnic_priv;
  3751. u8 sb_id = cp->status_blk_num;
  3752. CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
  3753. CSTORM_STATUS_BLOCK_DATA_OFFSET(sb_id) +
  3754. offsetof(struct hc_status_block_data_e1x, index_data) +
  3755. sizeof(struct hc_index_data)*HC_INDEX_ISCSI_EQ_CONS +
  3756. offsetof(struct hc_index_data, timeout), 64 / 12);
  3757. cnic_storm_memset_hc_disable(dev, sb_id, HC_INDEX_ISCSI_EQ_CONS, 0);
  3758. }
  3759. static void cnic_disable_bnx2x_int_sync(struct cnic_dev *dev)
  3760. {
  3761. }
  3762. static void cnic_init_bnx2x_tx_ring(struct cnic_dev *dev,
  3763. struct client_init_ramrod_data *data)
  3764. {
  3765. struct cnic_local *cp = dev->cnic_priv;
  3766. struct cnic_uio_dev *udev = cp->udev;
  3767. union eth_tx_bd_types *txbd = (union eth_tx_bd_types *) udev->l2_ring;
  3768. dma_addr_t buf_map, ring_map = udev->l2_ring_map;
  3769. struct host_sp_status_block *sb = cp->bnx2x_def_status_blk;
  3770. int port = CNIC_PORT(cp);
  3771. int i;
  3772. u32 cli = cp->ethdev->iscsi_l2_client_id;
  3773. u32 val;
  3774. memset(txbd, 0, BCM_PAGE_SIZE);
  3775. buf_map = udev->l2_buf_map;
  3776. for (i = 0; i < MAX_TX_DESC_CNT; i += 3, txbd += 3) {
  3777. struct eth_tx_start_bd *start_bd = &txbd->start_bd;
  3778. struct eth_tx_bd *reg_bd = &((txbd + 2)->reg_bd);
  3779. start_bd->addr_hi = cpu_to_le32((u64) buf_map >> 32);
  3780. start_bd->addr_lo = cpu_to_le32(buf_map & 0xffffffff);
  3781. reg_bd->addr_hi = start_bd->addr_hi;
  3782. reg_bd->addr_lo = start_bd->addr_lo + 0x10;
  3783. start_bd->nbytes = cpu_to_le16(0x10);
  3784. start_bd->nbd = cpu_to_le16(3);
  3785. start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  3786. start_bd->general_data = (UNICAST_ADDRESS <<
  3787. ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT);
  3788. start_bd->general_data |= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
  3789. }
  3790. val = (u64) ring_map >> 32;
  3791. txbd->next_bd.addr_hi = cpu_to_le32(val);
  3792. data->tx.tx_bd_page_base.hi = cpu_to_le32(val);
  3793. val = (u64) ring_map & 0xffffffff;
  3794. txbd->next_bd.addr_lo = cpu_to_le32(val);
  3795. data->tx.tx_bd_page_base.lo = cpu_to_le32(val);
  3796. /* Other ramrod params */
  3797. data->tx.tx_sb_index_number = HC_SP_INDEX_ETH_ISCSI_CQ_CONS;
  3798. data->tx.tx_status_block_id = BNX2X_DEF_SB_ID;
  3799. /* reset xstorm per client statistics */
  3800. if (cli < MAX_STAT_COUNTER_ID) {
  3801. val = BAR_XSTRORM_INTMEM +
  3802. XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli);
  3803. for (i = 0; i < sizeof(struct xstorm_per_client_stats) / 4; i++)
  3804. CNIC_WR(dev, val + i * 4, 0);
  3805. }
  3806. cp->tx_cons_ptr =
  3807. &sb->sp_sb.index_values[HC_SP_INDEX_ETH_ISCSI_CQ_CONS];
  3808. }
  3809. static void cnic_init_bnx2x_rx_ring(struct cnic_dev *dev,
  3810. struct client_init_ramrod_data *data)
  3811. {
  3812. struct cnic_local *cp = dev->cnic_priv;
  3813. struct cnic_uio_dev *udev = cp->udev;
  3814. struct eth_rx_bd *rxbd = (struct eth_rx_bd *) (udev->l2_ring +
  3815. BCM_PAGE_SIZE);
  3816. struct eth_rx_cqe_next_page *rxcqe = (struct eth_rx_cqe_next_page *)
  3817. (udev->l2_ring + (2 * BCM_PAGE_SIZE));
  3818. struct host_sp_status_block *sb = cp->bnx2x_def_status_blk;
  3819. int i;
  3820. int port = CNIC_PORT(cp);
  3821. u32 cli = cp->ethdev->iscsi_l2_client_id;
  3822. int cl_qzone_id = BNX2X_CL_QZONE_ID(cp, cli);
  3823. u32 val;
  3824. dma_addr_t ring_map = udev->l2_ring_map;
  3825. /* General data */
  3826. data->general.client_id = cli;
  3827. data->general.statistics_en_flg = 1;
  3828. data->general.statistics_counter_id = cli;
  3829. data->general.activate_flg = 1;
  3830. data->general.sp_client_id = cli;
  3831. for (i = 0; i < BNX2X_MAX_RX_DESC_CNT; i++, rxbd++) {
  3832. dma_addr_t buf_map;
  3833. int n = (i % cp->l2_rx_ring_size) + 1;
  3834. buf_map = udev->l2_buf_map + (n * cp->l2_single_buf_size);
  3835. rxbd->addr_hi = cpu_to_le32((u64) buf_map >> 32);
  3836. rxbd->addr_lo = cpu_to_le32(buf_map & 0xffffffff);
  3837. }
  3838. val = (u64) (ring_map + BCM_PAGE_SIZE) >> 32;
  3839. rxbd->addr_hi = cpu_to_le32(val);
  3840. data->rx.bd_page_base.hi = cpu_to_le32(val);
  3841. val = (u64) (ring_map + BCM_PAGE_SIZE) & 0xffffffff;
  3842. rxbd->addr_lo = cpu_to_le32(val);
  3843. data->rx.bd_page_base.lo = cpu_to_le32(val);
  3844. rxcqe += BNX2X_MAX_RCQ_DESC_CNT;
  3845. val = (u64) (ring_map + (2 * BCM_PAGE_SIZE)) >> 32;
  3846. rxcqe->addr_hi = cpu_to_le32(val);
  3847. data->rx.cqe_page_base.hi = cpu_to_le32(val);
  3848. val = (u64) (ring_map + (2 * BCM_PAGE_SIZE)) & 0xffffffff;
  3849. rxcqe->addr_lo = cpu_to_le32(val);
  3850. data->rx.cqe_page_base.lo = cpu_to_le32(val);
  3851. /* Other ramrod params */
  3852. data->rx.client_qzone_id = cl_qzone_id;
  3853. data->rx.rx_sb_index_number = HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS;
  3854. data->rx.status_block_id = BNX2X_DEF_SB_ID;
  3855. data->rx.cache_line_alignment_log_size = L1_CACHE_SHIFT;
  3856. data->rx.bd_buff_size = cpu_to_le16(cp->l2_single_buf_size);
  3857. data->rx.mtu = cpu_to_le16(cp->l2_single_buf_size - 14);
  3858. data->rx.outer_vlan_removal_enable_flg = 1;
  3859. /* reset tstorm and ustorm per client statistics */
  3860. if (cli < MAX_STAT_COUNTER_ID) {
  3861. val = BAR_TSTRORM_INTMEM +
  3862. TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli);
  3863. for (i = 0; i < sizeof(struct tstorm_per_client_stats) / 4; i++)
  3864. CNIC_WR(dev, val + i * 4, 0);
  3865. val = BAR_USTRORM_INTMEM +
  3866. USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cli);
  3867. for (i = 0; i < sizeof(struct ustorm_per_client_stats) / 4; i++)
  3868. CNIC_WR(dev, val + i * 4, 0);
  3869. }
  3870. cp->rx_cons_ptr =
  3871. &sb->sp_sb.index_values[HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS];
  3872. cp->rx_cons = *cp->rx_cons_ptr;
  3873. }
  3874. static int cnic_read_bnx2x_iscsi_mac(struct cnic_dev *dev, u32 upper_addr,
  3875. u32 lower_addr)
  3876. {
  3877. u32 val;
  3878. u8 mac[6];
  3879. val = CNIC_RD(dev, upper_addr);
  3880. mac[0] = (u8) (val >> 8);
  3881. mac[1] = (u8) val;
  3882. val = CNIC_RD(dev, lower_addr);
  3883. mac[2] = (u8) (val >> 24);
  3884. mac[3] = (u8) (val >> 16);
  3885. mac[4] = (u8) (val >> 8);
  3886. mac[5] = (u8) val;
  3887. if (is_valid_ether_addr(mac)) {
  3888. memcpy(dev->mac_addr, mac, 6);
  3889. return 0;
  3890. } else {
  3891. return -EINVAL;
  3892. }
  3893. }
  3894. static void cnic_get_bnx2x_iscsi_info(struct cnic_dev *dev)
  3895. {
  3896. struct cnic_local *cp = dev->cnic_priv;
  3897. u32 base, base2, addr, addr1, val;
  3898. int port = CNIC_PORT(cp);
  3899. dev->max_iscsi_conn = 0;
  3900. base = CNIC_RD(dev, MISC_REG_SHARED_MEM_ADDR);
  3901. if (base == 0)
  3902. return;
  3903. base2 = CNIC_RD(dev, (CNIC_PATH(cp) ? MISC_REG_GENERIC_CR_1 :
  3904. MISC_REG_GENERIC_CR_0));
  3905. addr = BNX2X_SHMEM_ADDR(base,
  3906. dev_info.port_hw_config[port].iscsi_mac_upper);
  3907. addr1 = BNX2X_SHMEM_ADDR(base,
  3908. dev_info.port_hw_config[port].iscsi_mac_lower);
  3909. cnic_read_bnx2x_iscsi_mac(dev, addr, addr1);
  3910. addr = BNX2X_SHMEM_ADDR(base, validity_map[port]);
  3911. val = CNIC_RD(dev, addr);
  3912. if (!(val & SHR_MEM_VALIDITY_LIC_NO_KEY_IN_EFFECT)) {
  3913. u16 val16;
  3914. addr = BNX2X_SHMEM_ADDR(base,
  3915. drv_lic_key[port].max_iscsi_init_conn);
  3916. val16 = CNIC_RD16(dev, addr);
  3917. if (val16)
  3918. val16 ^= 0x1e1e;
  3919. dev->max_iscsi_conn = val16;
  3920. }
  3921. if (BNX2X_CHIP_IS_E2(cp->chip_id))
  3922. dev->max_fcoe_conn = BNX2X_FCOE_NUM_CONNECTIONS;
  3923. if (BNX2X_CHIP_IS_E1H(cp->chip_id) || BNX2X_CHIP_IS_E2(cp->chip_id)) {
  3924. int func = CNIC_FUNC(cp);
  3925. u32 mf_cfg_addr;
  3926. if (BNX2X_SHMEM2_HAS(base2, mf_cfg_addr))
  3927. mf_cfg_addr = CNIC_RD(dev, BNX2X_SHMEM2_ADDR(base2,
  3928. mf_cfg_addr));
  3929. else
  3930. mf_cfg_addr = base + BNX2X_SHMEM_MF_BLK_OFFSET;
  3931. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  3932. /* Must determine if the MF is SD vs SI mode */
  3933. addr = BNX2X_SHMEM_ADDR(base,
  3934. dev_info.shared_feature_config.config);
  3935. val = CNIC_RD(dev, addr);
  3936. if ((val & SHARED_FEAT_CFG_FORCE_SF_MODE_MASK) ==
  3937. SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT) {
  3938. int rc;
  3939. /* MULTI_FUNCTION_SI mode */
  3940. addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
  3941. func_ext_config[func].func_cfg);
  3942. val = CNIC_RD(dev, addr);
  3943. if (!(val & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD))
  3944. dev->max_iscsi_conn = 0;
  3945. if (!(val & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  3946. dev->max_fcoe_conn = 0;
  3947. addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
  3948. func_ext_config[func].
  3949. iscsi_mac_addr_upper);
  3950. addr1 = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
  3951. func_ext_config[func].
  3952. iscsi_mac_addr_lower);
  3953. rc = cnic_read_bnx2x_iscsi_mac(dev, addr,
  3954. addr1);
  3955. if (rc && func > 1)
  3956. dev->max_iscsi_conn = 0;
  3957. return;
  3958. }
  3959. }
  3960. addr = BNX2X_MF_CFG_ADDR(mf_cfg_addr,
  3961. func_mf_config[func].e1hov_tag);
  3962. val = CNIC_RD(dev, addr);
  3963. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  3964. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  3965. dev->max_fcoe_conn = 0;
  3966. dev->max_iscsi_conn = 0;
  3967. }
  3968. }
  3969. if (!is_valid_ether_addr(dev->mac_addr))
  3970. dev->max_iscsi_conn = 0;
  3971. }
  3972. static void cnic_init_bnx2x_kcq(struct cnic_dev *dev)
  3973. {
  3974. struct cnic_local *cp = dev->cnic_priv;
  3975. u32 pfid = cp->pfid;
  3976. cp->kcq1.io_addr = BAR_CSTRORM_INTMEM +
  3977. CSTORM_ISCSI_EQ_PROD_OFFSET(pfid, 0);
  3978. cp->kcq1.sw_prod_idx = 0;
  3979. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  3980. struct host_hc_status_block_e2 *sb = cp->status_blk.gen;
  3981. cp->kcq1.hw_prod_idx_ptr =
  3982. &sb->sb.index_values[HC_INDEX_ISCSI_EQ_CONS];
  3983. cp->kcq1.status_idx_ptr =
  3984. &sb->sb.running_index[SM_RX_ID];
  3985. } else {
  3986. struct host_hc_status_block_e1x *sb = cp->status_blk.gen;
  3987. cp->kcq1.hw_prod_idx_ptr =
  3988. &sb->sb.index_values[HC_INDEX_ISCSI_EQ_CONS];
  3989. cp->kcq1.status_idx_ptr =
  3990. &sb->sb.running_index[SM_RX_ID];
  3991. }
  3992. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  3993. struct host_hc_status_block_e2 *sb = cp->status_blk.gen;
  3994. cp->kcq2.io_addr = BAR_USTRORM_INTMEM +
  3995. USTORM_FCOE_EQ_PROD_OFFSET(pfid);
  3996. cp->kcq2.sw_prod_idx = 0;
  3997. cp->kcq2.hw_prod_idx_ptr =
  3998. &sb->sb.index_values[HC_INDEX_FCOE_EQ_CONS];
  3999. cp->kcq2.status_idx_ptr =
  4000. &sb->sb.running_index[SM_RX_ID];
  4001. }
  4002. }
  4003. static int cnic_start_bnx2x_hw(struct cnic_dev *dev)
  4004. {
  4005. struct cnic_local *cp = dev->cnic_priv;
  4006. struct cnic_eth_dev *ethdev = cp->ethdev;
  4007. int func = CNIC_FUNC(cp), ret, i;
  4008. u32 pfid;
  4009. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  4010. u32 val = CNIC_RD(dev, MISC_REG_PORT4MODE_EN_OVWR);
  4011. if (!(val & 1))
  4012. val = CNIC_RD(dev, MISC_REG_PORT4MODE_EN);
  4013. else
  4014. val = (val >> 1) & 1;
  4015. if (val)
  4016. cp->pfid = func >> 1;
  4017. else
  4018. cp->pfid = func & 0x6;
  4019. } else {
  4020. cp->pfid = func;
  4021. }
  4022. pfid = cp->pfid;
  4023. ret = cnic_init_id_tbl(&cp->cid_tbl, MAX_ISCSI_TBL_SZ,
  4024. cp->iscsi_start_cid);
  4025. if (ret)
  4026. return -ENOMEM;
  4027. if (BNX2X_CHIP_IS_E2(cp->chip_id)) {
  4028. ret = cnic_init_id_tbl(&cp->fcoe_cid_tbl,
  4029. BNX2X_FCOE_NUM_CONNECTIONS,
  4030. cp->fcoe_start_cid);
  4031. if (ret)
  4032. return -ENOMEM;
  4033. }
  4034. cp->bnx2x_igu_sb_id = ethdev->irq_arr[0].status_blk_num2;
  4035. cnic_init_bnx2x_kcq(dev);
  4036. cnic_get_bnx2x_iscsi_info(dev);
  4037. /* Only 1 EQ */
  4038. CNIC_WR16(dev, cp->kcq1.io_addr, MAX_KCQ_IDX);
  4039. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4040. CSTORM_ISCSI_EQ_CONS_OFFSET(pfid, 0), 0);
  4041. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4042. CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid, 0),
  4043. cp->kcq1.dma.pg_map_arr[1] & 0xffffffff);
  4044. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4045. CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_OFFSET(pfid, 0) + 4,
  4046. (u64) cp->kcq1.dma.pg_map_arr[1] >> 32);
  4047. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4048. CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid, 0),
  4049. cp->kcq1.dma.pg_map_arr[0] & 0xffffffff);
  4050. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4051. CSTORM_ISCSI_EQ_NEXT_EQE_ADDR_OFFSET(pfid, 0) + 4,
  4052. (u64) cp->kcq1.dma.pg_map_arr[0] >> 32);
  4053. CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
  4054. CSTORM_ISCSI_EQ_NEXT_PAGE_ADDR_VALID_OFFSET(pfid, 0), 1);
  4055. CNIC_WR16(dev, BAR_CSTRORM_INTMEM +
  4056. CSTORM_ISCSI_EQ_SB_NUM_OFFSET(pfid, 0), cp->status_blk_num);
  4057. CNIC_WR8(dev, BAR_CSTRORM_INTMEM +
  4058. CSTORM_ISCSI_EQ_SB_INDEX_OFFSET(pfid, 0),
  4059. HC_INDEX_ISCSI_EQ_CONS);
  4060. for (i = 0; i < cp->conn_buf_info.num_pages; i++) {
  4061. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  4062. TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(pfid, i),
  4063. cp->conn_buf_info.pgtbl[2 * i]);
  4064. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  4065. TSTORM_ISCSI_CONN_BUF_PBL_OFFSET(pfid, i) + 4,
  4066. cp->conn_buf_info.pgtbl[(2 * i) + 1]);
  4067. }
  4068. CNIC_WR(dev, BAR_USTRORM_INTMEM +
  4069. USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid),
  4070. cp->gbl_buf_info.pg_map_arr[0] & 0xffffffff);
  4071. CNIC_WR(dev, BAR_USTRORM_INTMEM +
  4072. USTORM_ISCSI_GLOBAL_BUF_PHYS_ADDR_OFFSET(pfid) + 4,
  4073. (u64) cp->gbl_buf_info.pg_map_arr[0] >> 32);
  4074. CNIC_WR(dev, BAR_TSTRORM_INTMEM +
  4075. TSTORM_ISCSI_TCP_LOCAL_ADV_WND_OFFSET(pfid), DEF_RCV_BUF);
  4076. cnic_setup_bnx2x_context(dev);
  4077. ret = cnic_init_bnx2x_irq(dev);
  4078. if (ret)
  4079. return ret;
  4080. return 0;
  4081. }
  4082. static void cnic_init_rings(struct cnic_dev *dev)
  4083. {
  4084. struct cnic_local *cp = dev->cnic_priv;
  4085. struct cnic_uio_dev *udev = cp->udev;
  4086. if (test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags))
  4087. return;
  4088. if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
  4089. cnic_init_bnx2_tx_ring(dev);
  4090. cnic_init_bnx2_rx_ring(dev);
  4091. set_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags);
  4092. } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
  4093. u32 cli = cp->ethdev->iscsi_l2_client_id;
  4094. u32 cid = cp->ethdev->iscsi_l2_cid;
  4095. u32 cl_qzone_id;
  4096. struct client_init_ramrod_data *data;
  4097. union l5cm_specific_data l5_data;
  4098. struct ustorm_eth_rx_producers rx_prods = {0};
  4099. u32 off, i;
  4100. rx_prods.bd_prod = 0;
  4101. rx_prods.cqe_prod = BNX2X_MAX_RCQ_DESC_CNT;
  4102. barrier();
  4103. cl_qzone_id = BNX2X_CL_QZONE_ID(cp, cli);
  4104. off = BAR_USTRORM_INTMEM +
  4105. (BNX2X_CHIP_IS_E2(cp->chip_id) ?
  4106. USTORM_RX_PRODS_E2_OFFSET(cl_qzone_id) :
  4107. USTORM_RX_PRODS_E1X_OFFSET(CNIC_PORT(cp), cli));
  4108. for (i = 0; i < sizeof(struct ustorm_eth_rx_producers) / 4; i++)
  4109. CNIC_WR(dev, off + i * 4, ((u32 *) &rx_prods)[i]);
  4110. set_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags);
  4111. data = udev->l2_buf;
  4112. memset(data, 0, sizeof(*data));
  4113. cnic_init_bnx2x_tx_ring(dev, data);
  4114. cnic_init_bnx2x_rx_ring(dev, data);
  4115. l5_data.phy_address.lo = udev->l2_buf_map & 0xffffffff;
  4116. l5_data.phy_address.hi = (u64) udev->l2_buf_map >> 32;
  4117. set_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags);
  4118. cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_ETH_CLIENT_SETUP,
  4119. cid, ETH_CONNECTION_TYPE, &l5_data);
  4120. i = 0;
  4121. while (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags) &&
  4122. ++i < 10)
  4123. msleep(1);
  4124. if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags))
  4125. netdev_err(dev->netdev,
  4126. "iSCSI CLIENT_SETUP did not complete\n");
  4127. cnic_spq_completion(dev, DRV_CTL_RET_L2_SPQ_CREDIT_CMD, 1);
  4128. cnic_ring_ctl(dev, cid, cli, 1);
  4129. }
  4130. }
  4131. static void cnic_shutdown_rings(struct cnic_dev *dev)
  4132. {
  4133. struct cnic_local *cp = dev->cnic_priv;
  4134. if (!test_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags))
  4135. return;
  4136. if (test_bit(CNIC_F_BNX2_CLASS, &dev->flags)) {
  4137. cnic_shutdown_bnx2_rx_ring(dev);
  4138. } else if (test_bit(CNIC_F_BNX2X_CLASS, &dev->flags)) {
  4139. struct cnic_local *cp = dev->cnic_priv;
  4140. u32 cli = cp->ethdev->iscsi_l2_client_id;
  4141. u32 cid = cp->ethdev->iscsi_l2_cid;
  4142. union l5cm_specific_data l5_data;
  4143. int i;
  4144. cnic_ring_ctl(dev, cid, cli, 0);
  4145. set_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags);
  4146. l5_data.phy_address.lo = cli;
  4147. l5_data.phy_address.hi = 0;
  4148. cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_ETH_HALT,
  4149. cid, ETH_CONNECTION_TYPE, &l5_data);
  4150. i = 0;
  4151. while (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags) &&
  4152. ++i < 10)
  4153. msleep(1);
  4154. if (test_bit(CNIC_LCL_FL_L2_WAIT, &cp->cnic_local_flags))
  4155. netdev_err(dev->netdev,
  4156. "iSCSI CLIENT_HALT did not complete\n");
  4157. cnic_spq_completion(dev, DRV_CTL_RET_L2_SPQ_CREDIT_CMD, 1);
  4158. memset(&l5_data, 0, sizeof(l5_data));
  4159. cnic_submit_kwqe_16(dev, RAMROD_CMD_ID_COMMON_CFC_DEL,
  4160. cid, NONE_CONNECTION_TYPE, &l5_data);
  4161. msleep(10);
  4162. }
  4163. clear_bit(CNIC_LCL_FL_RINGS_INITED, &cp->cnic_local_flags);
  4164. }
  4165. static int cnic_register_netdev(struct cnic_dev *dev)
  4166. {
  4167. struct cnic_local *cp = dev->cnic_priv;
  4168. struct cnic_eth_dev *ethdev = cp->ethdev;
  4169. int err;
  4170. if (!ethdev)
  4171. return -ENODEV;
  4172. if (ethdev->drv_state & CNIC_DRV_STATE_REGD)
  4173. return 0;
  4174. err = ethdev->drv_register_cnic(dev->netdev, cp->cnic_ops, dev);
  4175. if (err)
  4176. netdev_err(dev->netdev, "register_cnic failed\n");
  4177. return err;
  4178. }
  4179. static void cnic_unregister_netdev(struct cnic_dev *dev)
  4180. {
  4181. struct cnic_local *cp = dev->cnic_priv;
  4182. struct cnic_eth_dev *ethdev = cp->ethdev;
  4183. if (!ethdev)
  4184. return;
  4185. ethdev->drv_unregister_cnic(dev->netdev);
  4186. }
  4187. static int cnic_start_hw(struct cnic_dev *dev)
  4188. {
  4189. struct cnic_local *cp = dev->cnic_priv;
  4190. struct cnic_eth_dev *ethdev = cp->ethdev;
  4191. int err;
  4192. if (test_bit(CNIC_F_CNIC_UP, &dev->flags))
  4193. return -EALREADY;
  4194. dev->regview = ethdev->io_base;
  4195. pci_dev_get(dev->pcidev);
  4196. cp->func = PCI_FUNC(dev->pcidev->devfn);
  4197. cp->status_blk.gen = ethdev->irq_arr[0].status_blk;
  4198. cp->status_blk_num = ethdev->irq_arr[0].status_blk_num;
  4199. err = cp->alloc_resc(dev);
  4200. if (err) {
  4201. netdev_err(dev->netdev, "allocate resource failure\n");
  4202. goto err1;
  4203. }
  4204. err = cp->start_hw(dev);
  4205. if (err)
  4206. goto err1;
  4207. err = cnic_cm_open(dev);
  4208. if (err)
  4209. goto err1;
  4210. set_bit(CNIC_F_CNIC_UP, &dev->flags);
  4211. cp->enable_int(dev);
  4212. return 0;
  4213. err1:
  4214. cp->free_resc(dev);
  4215. pci_dev_put(dev->pcidev);
  4216. return err;
  4217. }
  4218. static void cnic_stop_bnx2_hw(struct cnic_dev *dev)
  4219. {
  4220. cnic_disable_bnx2_int_sync(dev);
  4221. cnic_reg_wr_ind(dev, BNX2_CP_SCRATCH + 0x20, 0);
  4222. cnic_reg_wr_ind(dev, BNX2_COM_SCRATCH + 0x20, 0);
  4223. cnic_init_context(dev, KWQ_CID);
  4224. cnic_init_context(dev, KCQ_CID);
  4225. cnic_setup_5709_context(dev, 0);
  4226. cnic_free_irq(dev);
  4227. cnic_free_resc(dev);
  4228. }
  4229. static void cnic_stop_bnx2x_hw(struct cnic_dev *dev)
  4230. {
  4231. struct cnic_local *cp = dev->cnic_priv;
  4232. cnic_free_irq(dev);
  4233. *cp->kcq1.hw_prod_idx_ptr = 0;
  4234. CNIC_WR(dev, BAR_CSTRORM_INTMEM +
  4235. CSTORM_ISCSI_EQ_CONS_OFFSET(cp->pfid, 0), 0);
  4236. CNIC_WR16(dev, cp->kcq1.io_addr, 0);
  4237. cnic_free_resc(dev);
  4238. }
  4239. static void cnic_stop_hw(struct cnic_dev *dev)
  4240. {
  4241. if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) {
  4242. struct cnic_local *cp = dev->cnic_priv;
  4243. int i = 0;
  4244. /* Need to wait for the ring shutdown event to complete
  4245. * before clearing the CNIC_UP flag.
  4246. */
  4247. while (cp->udev->uio_dev != -1 && i < 15) {
  4248. msleep(100);
  4249. i++;
  4250. }
  4251. cnic_shutdown_rings(dev);
  4252. clear_bit(CNIC_F_CNIC_UP, &dev->flags);
  4253. rcu_assign_pointer(cp->ulp_ops[CNIC_ULP_L4], NULL);
  4254. synchronize_rcu();
  4255. cnic_cm_shutdown(dev);
  4256. cp->stop_hw(dev);
  4257. pci_dev_put(dev->pcidev);
  4258. }
  4259. }
  4260. static void cnic_free_dev(struct cnic_dev *dev)
  4261. {
  4262. int i = 0;
  4263. while ((atomic_read(&dev->ref_count) != 0) && i < 10) {
  4264. msleep(100);
  4265. i++;
  4266. }
  4267. if (atomic_read(&dev->ref_count) != 0)
  4268. netdev_err(dev->netdev, "Failed waiting for ref count to go to zero\n");
  4269. netdev_info(dev->netdev, "Removed CNIC device\n");
  4270. dev_put(dev->netdev);
  4271. kfree(dev);
  4272. }
  4273. static struct cnic_dev *cnic_alloc_dev(struct net_device *dev,
  4274. struct pci_dev *pdev)
  4275. {
  4276. struct cnic_dev *cdev;
  4277. struct cnic_local *cp;
  4278. int alloc_size;
  4279. alloc_size = sizeof(struct cnic_dev) + sizeof(struct cnic_local);
  4280. cdev = kzalloc(alloc_size , GFP_KERNEL);
  4281. if (cdev == NULL) {
  4282. netdev_err(dev, "allocate dev struct failure\n");
  4283. return NULL;
  4284. }
  4285. cdev->netdev = dev;
  4286. cdev->cnic_priv = (char *)cdev + sizeof(struct cnic_dev);
  4287. cdev->register_device = cnic_register_device;
  4288. cdev->unregister_device = cnic_unregister_device;
  4289. cdev->iscsi_nl_msg_recv = cnic_iscsi_nl_msg_recv;
  4290. cp = cdev->cnic_priv;
  4291. cp->dev = cdev;
  4292. cp->l2_single_buf_size = 0x400;
  4293. cp->l2_rx_ring_size = 3;
  4294. spin_lock_init(&cp->cnic_ulp_lock);
  4295. netdev_info(dev, "Added CNIC device\n");
  4296. return cdev;
  4297. }
  4298. static struct cnic_dev *init_bnx2_cnic(struct net_device *dev)
  4299. {
  4300. struct pci_dev *pdev;
  4301. struct cnic_dev *cdev;
  4302. struct cnic_local *cp;
  4303. struct cnic_eth_dev *ethdev = NULL;
  4304. struct cnic_eth_dev *(*probe)(struct net_device *) = NULL;
  4305. probe = symbol_get(bnx2_cnic_probe);
  4306. if (probe) {
  4307. ethdev = (*probe)(dev);
  4308. symbol_put(bnx2_cnic_probe);
  4309. }
  4310. if (!ethdev)
  4311. return NULL;
  4312. pdev = ethdev->pdev;
  4313. if (!pdev)
  4314. return NULL;
  4315. dev_hold(dev);
  4316. pci_dev_get(pdev);
  4317. if (pdev->device == PCI_DEVICE_ID_NX2_5709 ||
  4318. pdev->device == PCI_DEVICE_ID_NX2_5709S) {
  4319. u8 rev;
  4320. pci_read_config_byte(pdev, PCI_REVISION_ID, &rev);
  4321. if (rev < 0x10) {
  4322. pci_dev_put(pdev);
  4323. goto cnic_err;
  4324. }
  4325. }
  4326. pci_dev_put(pdev);
  4327. cdev = cnic_alloc_dev(dev, pdev);
  4328. if (cdev == NULL)
  4329. goto cnic_err;
  4330. set_bit(CNIC_F_BNX2_CLASS, &cdev->flags);
  4331. cdev->submit_kwqes = cnic_submit_bnx2_kwqes;
  4332. cp = cdev->cnic_priv;
  4333. cp->ethdev = ethdev;
  4334. cdev->pcidev = pdev;
  4335. cp->chip_id = ethdev->chip_id;
  4336. cp->cnic_ops = &cnic_bnx2_ops;
  4337. cp->start_hw = cnic_start_bnx2_hw;
  4338. cp->stop_hw = cnic_stop_bnx2_hw;
  4339. cp->setup_pgtbl = cnic_setup_page_tbl;
  4340. cp->alloc_resc = cnic_alloc_bnx2_resc;
  4341. cp->free_resc = cnic_free_resc;
  4342. cp->start_cm = cnic_cm_init_bnx2_hw;
  4343. cp->stop_cm = cnic_cm_stop_bnx2_hw;
  4344. cp->enable_int = cnic_enable_bnx2_int;
  4345. cp->disable_int_sync = cnic_disable_bnx2_int_sync;
  4346. cp->close_conn = cnic_close_bnx2_conn;
  4347. cp->next_idx = cnic_bnx2_next_idx;
  4348. cp->hw_idx = cnic_bnx2_hw_idx;
  4349. return cdev;
  4350. cnic_err:
  4351. dev_put(dev);
  4352. return NULL;
  4353. }
  4354. static struct cnic_dev *init_bnx2x_cnic(struct net_device *dev)
  4355. {
  4356. struct pci_dev *pdev;
  4357. struct cnic_dev *cdev;
  4358. struct cnic_local *cp;
  4359. struct cnic_eth_dev *ethdev = NULL;
  4360. struct cnic_eth_dev *(*probe)(struct net_device *) = NULL;
  4361. probe = symbol_get(bnx2x_cnic_probe);
  4362. if (probe) {
  4363. ethdev = (*probe)(dev);
  4364. symbol_put(bnx2x_cnic_probe);
  4365. }
  4366. if (!ethdev)
  4367. return NULL;
  4368. pdev = ethdev->pdev;
  4369. if (!pdev)
  4370. return NULL;
  4371. dev_hold(dev);
  4372. cdev = cnic_alloc_dev(dev, pdev);
  4373. if (cdev == NULL) {
  4374. dev_put(dev);
  4375. return NULL;
  4376. }
  4377. set_bit(CNIC_F_BNX2X_CLASS, &cdev->flags);
  4378. cdev->submit_kwqes = cnic_submit_bnx2x_kwqes;
  4379. cp = cdev->cnic_priv;
  4380. cp->ethdev = ethdev;
  4381. cdev->pcidev = pdev;
  4382. cp->chip_id = ethdev->chip_id;
  4383. cp->cnic_ops = &cnic_bnx2x_ops;
  4384. cp->start_hw = cnic_start_bnx2x_hw;
  4385. cp->stop_hw = cnic_stop_bnx2x_hw;
  4386. cp->setup_pgtbl = cnic_setup_page_tbl_le;
  4387. cp->alloc_resc = cnic_alloc_bnx2x_resc;
  4388. cp->free_resc = cnic_free_resc;
  4389. cp->start_cm = cnic_cm_init_bnx2x_hw;
  4390. cp->stop_cm = cnic_cm_stop_bnx2x_hw;
  4391. cp->enable_int = cnic_enable_bnx2x_int;
  4392. cp->disable_int_sync = cnic_disable_bnx2x_int_sync;
  4393. if (BNX2X_CHIP_IS_E2(cp->chip_id))
  4394. cp->ack_int = cnic_ack_bnx2x_e2_msix;
  4395. else
  4396. cp->ack_int = cnic_ack_bnx2x_msix;
  4397. cp->close_conn = cnic_close_bnx2x_conn;
  4398. cp->next_idx = cnic_bnx2x_next_idx;
  4399. cp->hw_idx = cnic_bnx2x_hw_idx;
  4400. return cdev;
  4401. }
  4402. static struct cnic_dev *is_cnic_dev(struct net_device *dev)
  4403. {
  4404. struct ethtool_drvinfo drvinfo;
  4405. struct cnic_dev *cdev = NULL;
  4406. if (dev->ethtool_ops && dev->ethtool_ops->get_drvinfo) {
  4407. memset(&drvinfo, 0, sizeof(drvinfo));
  4408. dev->ethtool_ops->get_drvinfo(dev, &drvinfo);
  4409. if (!strcmp(drvinfo.driver, "bnx2"))
  4410. cdev = init_bnx2_cnic(dev);
  4411. if (!strcmp(drvinfo.driver, "bnx2x"))
  4412. cdev = init_bnx2x_cnic(dev);
  4413. if (cdev) {
  4414. write_lock(&cnic_dev_lock);
  4415. list_add(&cdev->list, &cnic_dev_list);
  4416. write_unlock(&cnic_dev_lock);
  4417. }
  4418. }
  4419. return cdev;
  4420. }
  4421. /**
  4422. * netdev event handler
  4423. */
  4424. static int cnic_netdev_event(struct notifier_block *this, unsigned long event,
  4425. void *ptr)
  4426. {
  4427. struct net_device *netdev = ptr;
  4428. struct cnic_dev *dev;
  4429. int if_type;
  4430. int new_dev = 0;
  4431. dev = cnic_from_netdev(netdev);
  4432. if (!dev && (event == NETDEV_REGISTER || event == NETDEV_UP)) {
  4433. /* Check for the hot-plug device */
  4434. dev = is_cnic_dev(netdev);
  4435. if (dev) {
  4436. new_dev = 1;
  4437. cnic_hold(dev);
  4438. }
  4439. }
  4440. if (dev) {
  4441. struct cnic_local *cp = dev->cnic_priv;
  4442. if (new_dev)
  4443. cnic_ulp_init(dev);
  4444. else if (event == NETDEV_UNREGISTER)
  4445. cnic_ulp_exit(dev);
  4446. if (event == NETDEV_UP) {
  4447. if (cnic_register_netdev(dev) != 0) {
  4448. cnic_put(dev);
  4449. goto done;
  4450. }
  4451. if (!cnic_start_hw(dev))
  4452. cnic_ulp_start(dev);
  4453. }
  4454. rcu_read_lock();
  4455. for (if_type = 0; if_type < MAX_CNIC_ULP_TYPE; if_type++) {
  4456. struct cnic_ulp_ops *ulp_ops;
  4457. void *ctx;
  4458. ulp_ops = rcu_dereference(cp->ulp_ops[if_type]);
  4459. if (!ulp_ops || !ulp_ops->indicate_netevent)
  4460. continue;
  4461. ctx = cp->ulp_handle[if_type];
  4462. ulp_ops->indicate_netevent(ctx, event);
  4463. }
  4464. rcu_read_unlock();
  4465. if (event == NETDEV_GOING_DOWN) {
  4466. cnic_ulp_stop(dev);
  4467. cnic_stop_hw(dev);
  4468. cnic_unregister_netdev(dev);
  4469. } else if (event == NETDEV_UNREGISTER) {
  4470. write_lock(&cnic_dev_lock);
  4471. list_del_init(&dev->list);
  4472. write_unlock(&cnic_dev_lock);
  4473. cnic_put(dev);
  4474. cnic_free_dev(dev);
  4475. goto done;
  4476. }
  4477. cnic_put(dev);
  4478. }
  4479. done:
  4480. return NOTIFY_DONE;
  4481. }
  4482. static struct notifier_block cnic_netdev_notifier = {
  4483. .notifier_call = cnic_netdev_event
  4484. };
  4485. static void cnic_release(void)
  4486. {
  4487. struct cnic_dev *dev;
  4488. struct cnic_uio_dev *udev;
  4489. while (!list_empty(&cnic_dev_list)) {
  4490. dev = list_entry(cnic_dev_list.next, struct cnic_dev, list);
  4491. if (test_bit(CNIC_F_CNIC_UP, &dev->flags)) {
  4492. cnic_ulp_stop(dev);
  4493. cnic_stop_hw(dev);
  4494. }
  4495. cnic_ulp_exit(dev);
  4496. cnic_unregister_netdev(dev);
  4497. list_del_init(&dev->list);
  4498. cnic_free_dev(dev);
  4499. }
  4500. while (!list_empty(&cnic_udev_list)) {
  4501. udev = list_entry(cnic_udev_list.next, struct cnic_uio_dev,
  4502. list);
  4503. cnic_free_uio(udev);
  4504. }
  4505. }
  4506. static int __init cnic_init(void)
  4507. {
  4508. int rc = 0;
  4509. pr_info("%s", version);
  4510. rc = register_netdevice_notifier(&cnic_netdev_notifier);
  4511. if (rc) {
  4512. cnic_release();
  4513. return rc;
  4514. }
  4515. cnic_wq = create_singlethread_workqueue("cnic_wq");
  4516. if (!cnic_wq) {
  4517. cnic_release();
  4518. unregister_netdevice_notifier(&cnic_netdev_notifier);
  4519. return -ENOMEM;
  4520. }
  4521. return 0;
  4522. }
  4523. static void __exit cnic_exit(void)
  4524. {
  4525. unregister_netdevice_notifier(&cnic_netdev_notifier);
  4526. cnic_release();
  4527. destroy_workqueue(cnic_wq);
  4528. }
  4529. module_init(cnic_init);
  4530. module_exit(cnic_exit);