fdls_disc.c 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2008 Cisco Systems, Inc. All rights reserved.
  4. * Copyright 2007 Nuova Systems, Inc. All rights reserved.
  5. */
  6. #include <linux/workqueue.h>
  7. #include "fnic.h"
  8. #include "fdls_fc.h"
  9. #include "fnic_fdls.h"
  10. #include <scsi/fc/fc_fcp.h>
  11. #include <scsi/scsi_transport_fc.h>
  12. #include <linux/utsname.h>
  13. #define FC_FC4_TYPE_SCSI 0x08
  14. #define PORT_SPEED_BIT_8 8
  15. #define PORT_SPEED_BIT_9 9
  16. #define PORT_SPEED_BIT_14 14
  17. #define PORT_SPEED_BIT_15 15
  18. /* FNIC FDMI Register HBA Macros */
  19. #define FNIC_FDMI_NUM_PORTS 1
  20. #define FNIC_FDMI_NUM_HBA_ATTRS 9
  21. #define FNIC_FDMI_TYPE_NODE_NAME 0X1
  22. #define FNIC_FDMI_TYPE_MANUFACTURER 0X2
  23. #define FNIC_FDMI_MANUFACTURER "Cisco Systems"
  24. #define FNIC_FDMI_TYPE_SERIAL_NUMBER 0X3
  25. #define FNIC_FDMI_TYPE_MODEL 0X4
  26. #define FNIC_FDMI_TYPE_MODEL_DES 0X5
  27. #define FNIC_FDMI_MODEL_DESCRIPTION "Cisco Virtual Interface Card"
  28. #define FNIC_FDMI_TYPE_HARDWARE_VERSION 0X6
  29. #define FNIC_FDMI_TYPE_DRIVER_VERSION 0X7
  30. #define FNIC_FDMI_TYPE_ROM_VERSION 0X8
  31. #define FNIC_FDMI_TYPE_FIRMWARE_VERSION 0X9
  32. #define FNIC_FDMI_NN_LEN 8
  33. #define FNIC_FDMI_MANU_LEN 20
  34. #define FNIC_FDMI_SERIAL_LEN 16
  35. #define FNIC_FDMI_MODEL_LEN 12
  36. #define FNIC_FDMI_MODEL_DES_LEN 56
  37. #define FNIC_FDMI_HW_VER_LEN 16
  38. #define FNIC_FDMI_DR_VER_LEN 28
  39. #define FNIC_FDMI_ROM_VER_LEN 8
  40. #define FNIC_FDMI_FW_VER_LEN 16
  41. /* FNIC FDMI Register PA Macros */
  42. #define FNIC_FDMI_TYPE_FC4_TYPES 0X1
  43. #define FNIC_FDMI_TYPE_SUPPORTED_SPEEDS 0X2
  44. #define FNIC_FDMI_TYPE_CURRENT_SPEED 0X3
  45. #define FNIC_FDMI_TYPE_MAX_FRAME_SIZE 0X4
  46. #define FNIC_FDMI_TYPE_OS_NAME 0X5
  47. #define FNIC_FDMI_TYPE_HOST_NAME 0X6
  48. #define FNIC_FDMI_NUM_PORT_ATTRS 6
  49. #define FNIC_FDMI_FC4_LEN 32
  50. #define FNIC_FDMI_SUPP_SPEED_LEN 4
  51. #define FNIC_FDMI_CUR_SPEED_LEN 4
  52. #define FNIC_FDMI_MFS_LEN 4
  53. #define FNIC_FDMI_MFS 0x800
  54. #define FNIC_FDMI_OS_NAME_LEN 16
  55. #define FNIC_FDMI_HN_LEN 24
  56. #define FDLS_FDMI_PLOGI_PENDING 0x1
  57. #define FDLS_FDMI_REG_HBA_PENDING 0x2
  58. #define FDLS_FDMI_RPA_PENDING 0x4
  59. #define FDLS_FDMI_ABORT_PENDING 0x8
  60. #define FDLS_FDMI_MAX_RETRY 3
  61. #define RETRIES_EXHAUSTED(iport) \
  62. (iport->fabric.retry_counter == FABRIC_LOGO_MAX_RETRY)
  63. #define FNIC_TPORT_MAX_NEXUS_RESTART (8)
  64. #define SCHEDULE_OXID_FREE_RETRY_TIME (300)
  65. /* Private Functions */
  66. static void fdls_fdmi_register_hba(struct fnic_iport_s *iport);
  67. static void fdls_fdmi_register_pa(struct fnic_iport_s *iport);
  68. static void fdls_send_rpn_id(struct fnic_iport_s *iport);
  69. static void fdls_process_flogi_rsp(struct fnic_iport_s *iport,
  70. struct fc_frame_header *fchdr,
  71. void *rx_frame);
  72. static void fnic_fdls_start_plogi(struct fnic_iport_s *iport);
  73. static void fnic_fdls_start_flogi(struct fnic_iport_s *iport);
  74. static struct fnic_tport_s *fdls_create_tport(struct fnic_iport_s *iport,
  75. uint32_t fcid,
  76. uint64_t wwpn);
  77. static void fdls_target_restart_nexus(struct fnic_tport_s *tport);
  78. static void fdls_start_tport_timer(struct fnic_iport_s *iport,
  79. struct fnic_tport_s *tport, int timeout);
  80. static void fdls_tport_timer_callback(struct timer_list *t);
  81. static void fdls_send_fdmi_plogi(struct fnic_iport_s *iport);
  82. static void fdls_start_fabric_timer(struct fnic_iport_s *iport,
  83. int timeout);
  84. static void fdls_init_plogi_frame(uint8_t *frame, struct fnic_iport_s *iport);
  85. static void fdls_init_els_acc_frame(uint8_t *frame, struct fnic_iport_s *iport);
  86. static void fdls_init_els_rjt_frame(uint8_t *frame, struct fnic_iport_s *iport);
  87. static void fdls_init_logo_frame(uint8_t *frame, struct fnic_iport_s *iport);
  88. static void fdls_init_fabric_abts_frame(uint8_t *frame,
  89. struct fnic_iport_s *iport);
  90. uint8_t *fdls_alloc_frame(struct fnic_iport_s *iport)
  91. {
  92. struct fnic *fnic = iport->fnic;
  93. uint8_t *frame = NULL;
  94. frame = mempool_alloc(fnic->frame_pool, GFP_ATOMIC);
  95. if (frame == NULL) {
  96. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  97. "Failed to allocate frame");
  98. return NULL;
  99. }
  100. memset(frame, 0, FNIC_FCOE_FRAME_MAXSZ);
  101. return frame;
  102. }
  103. /**
  104. * fdls_alloc_oxid - Allocate an oxid from the bitmap based oxid pool
  105. * @iport: Handle to iport instance
  106. * @oxid_frame_type: Type of frame to allocate
  107. * @active_oxid: the oxid which is in use
  108. *
  109. * Called with fnic lock held
  110. */
  111. uint16_t fdls_alloc_oxid(struct fnic_iport_s *iport, int oxid_frame_type,
  112. uint16_t *active_oxid)
  113. {
  114. struct fnic *fnic = iport->fnic;
  115. struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool;
  116. int idx;
  117. uint16_t oxid;
  118. lockdep_assert_held(&fnic->fnic_lock);
  119. /*
  120. * Allocate next available oxid from bitmap
  121. */
  122. idx = find_next_zero_bit(oxid_pool->bitmap, FNIC_OXID_POOL_SZ, oxid_pool->next_idx);
  123. if (idx == FNIC_OXID_POOL_SZ) {
  124. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  125. "Alloc oxid: all oxid slots are busy iport state:%d\n",
  126. iport->state);
  127. return FNIC_UNASSIGNED_OXID;
  128. }
  129. WARN_ON(test_and_set_bit(idx, oxid_pool->bitmap));
  130. oxid_pool->next_idx = (idx + 1) % FNIC_OXID_POOL_SZ; /* cycle through the bitmap */
  131. oxid = FNIC_OXID_ENCODE(idx, oxid_frame_type);
  132. *active_oxid = oxid;
  133. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  134. "alloc oxid: 0x%x, iport state: %d\n",
  135. oxid, iport->state);
  136. return oxid;
  137. }
  138. /**
  139. * fdls_free_oxid_idx - Free the oxid using the idx
  140. * @iport: Handle to iport instance
  141. * @oxid_idx: The index to free
  142. *
  143. * Free the oxid immediately and make it available for new requests
  144. * Called with fnic lock held
  145. */
  146. static void fdls_free_oxid_idx(struct fnic_iport_s *iport, uint16_t oxid_idx)
  147. {
  148. struct fnic *fnic = iport->fnic;
  149. struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool;
  150. lockdep_assert_held(&fnic->fnic_lock);
  151. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  152. "free oxid idx: 0x%x\n", oxid_idx);
  153. WARN_ON(!test_and_clear_bit(oxid_idx, oxid_pool->bitmap));
  154. }
  155. /**
  156. * fdls_reclaim_oxid_handler - Callback handler for delayed_oxid_work
  157. * @work: Handle to work_struct
  158. *
  159. * Scheduled when an oxid is to be freed later
  160. * After freeing expired oxid(s), the handler schedules
  161. * another callback with the remaining time
  162. * of next unexpired entry in the reclaim list.
  163. */
  164. void fdls_reclaim_oxid_handler(struct work_struct *work)
  165. {
  166. struct fnic_oxid_pool_s *oxid_pool = container_of(work,
  167. struct fnic_oxid_pool_s, oxid_reclaim_work.work);
  168. struct fnic_iport_s *iport = container_of(oxid_pool,
  169. struct fnic_iport_s, oxid_pool);
  170. struct fnic *fnic = iport->fnic;
  171. struct reclaim_entry_s *reclaim_entry, *next;
  172. unsigned long delay_j, cur_jiffies;
  173. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  174. "Reclaim oxid callback\n");
  175. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  176. /* Though the work was scheduled for one entry,
  177. * walk through and free the expired entries which might have been scheduled
  178. * at around the same time as the first entry
  179. */
  180. list_for_each_entry_safe(reclaim_entry, next,
  181. &(oxid_pool->oxid_reclaim_list), links) {
  182. /* The list is always maintained in the order of expiry time */
  183. cur_jiffies = jiffies;
  184. if (time_before(cur_jiffies, reclaim_entry->expires))
  185. break;
  186. list_del(&reclaim_entry->links);
  187. fdls_free_oxid_idx(iport, reclaim_entry->oxid_idx);
  188. kfree(reclaim_entry);
  189. }
  190. /* schedule to free up the next entry */
  191. if (!list_empty(&oxid_pool->oxid_reclaim_list)) {
  192. reclaim_entry = list_first_entry(&oxid_pool->oxid_reclaim_list,
  193. struct reclaim_entry_s, links);
  194. delay_j = reclaim_entry->expires - cur_jiffies;
  195. schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j);
  196. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  197. "Scheduling next callback at:%ld jiffies\n", delay_j);
  198. }
  199. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  200. }
  201. /**
  202. * fdls_free_oxid - Helper function to free the oxid
  203. * @iport: Handle to iport instance
  204. * @oxid: oxid to free
  205. * @active_oxid: the oxid which is in use
  206. *
  207. * Called with fnic lock held
  208. */
  209. void fdls_free_oxid(struct fnic_iport_s *iport,
  210. uint16_t oxid, uint16_t *active_oxid)
  211. {
  212. fdls_free_oxid_idx(iport, FNIC_OXID_IDX(oxid));
  213. *active_oxid = FNIC_UNASSIGNED_OXID;
  214. }
  215. /**
  216. * fdls_schedule_oxid_free - Schedule oxid to be freed later
  217. * @iport: Handle to iport instance
  218. * @active_oxid: the oxid which is in use
  219. *
  220. * Gets called in a rare case scenario when both a command
  221. * (fdls or target discovery) timed out and the following ABTS
  222. * timed out as well, without a link change.
  223. *
  224. * Called with fnic lock held
  225. */
  226. void fdls_schedule_oxid_free(struct fnic_iport_s *iport, uint16_t *active_oxid)
  227. {
  228. struct fnic *fnic = iport->fnic;
  229. struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool;
  230. struct reclaim_entry_s *reclaim_entry;
  231. unsigned long delay_j = msecs_to_jiffies(OXID_RECLAIM_TOV(iport));
  232. int oxid_idx = FNIC_OXID_IDX(*active_oxid);
  233. lockdep_assert_held(&fnic->fnic_lock);
  234. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  235. "Schedule oxid free. oxid: 0x%x\n", *active_oxid);
  236. *active_oxid = FNIC_UNASSIGNED_OXID;
  237. reclaim_entry = (struct reclaim_entry_s *)
  238. kzalloc_obj(struct reclaim_entry_s, GFP_ATOMIC);
  239. if (!reclaim_entry) {
  240. FNIC_FCS_DBG(KERN_WARNING, fnic->host, fnic->fnic_num,
  241. "Failed to allocate memory for reclaim struct for oxid idx: %d\n",
  242. oxid_idx);
  243. /* Retry the scheduling */
  244. WARN_ON(test_and_set_bit(oxid_idx, oxid_pool->pending_schedule_free));
  245. schedule_delayed_work(&oxid_pool->schedule_oxid_free_retry, 0);
  246. return;
  247. }
  248. reclaim_entry->oxid_idx = oxid_idx;
  249. reclaim_entry->expires = round_jiffies(jiffies + delay_j);
  250. list_add_tail(&reclaim_entry->links, &oxid_pool->oxid_reclaim_list);
  251. schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j);
  252. }
  253. /**
  254. * fdls_schedule_oxid_free_retry_work - Thread to schedule the
  255. * oxid to be freed later
  256. *
  257. * @work: Handle to the work struct
  258. */
  259. void fdls_schedule_oxid_free_retry_work(struct work_struct *work)
  260. {
  261. struct fnic_oxid_pool_s *oxid_pool = container_of(work,
  262. struct fnic_oxid_pool_s, schedule_oxid_free_retry.work);
  263. struct fnic_iport_s *iport = container_of(oxid_pool,
  264. struct fnic_iport_s, oxid_pool);
  265. struct fnic *fnic = iport->fnic;
  266. struct reclaim_entry_s *reclaim_entry;
  267. unsigned long delay_j = msecs_to_jiffies(OXID_RECLAIM_TOV(iport));
  268. unsigned long flags;
  269. int idx;
  270. for_each_set_bit(idx, oxid_pool->pending_schedule_free, FNIC_OXID_POOL_SZ) {
  271. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  272. "Schedule oxid free. oxid idx: %d\n", idx);
  273. reclaim_entry = kzalloc_obj(*reclaim_entry);
  274. if (!reclaim_entry) {
  275. schedule_delayed_work(&oxid_pool->schedule_oxid_free_retry,
  276. msecs_to_jiffies(SCHEDULE_OXID_FREE_RETRY_TIME));
  277. return;
  278. }
  279. clear_bit(idx, oxid_pool->pending_schedule_free);
  280. reclaim_entry->oxid_idx = idx;
  281. reclaim_entry->expires = round_jiffies(jiffies + delay_j);
  282. spin_lock_irqsave(&fnic->fnic_lock, flags);
  283. list_add_tail(&reclaim_entry->links, &oxid_pool->oxid_reclaim_list);
  284. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  285. schedule_delayed_work(&oxid_pool->oxid_reclaim_work, delay_j);
  286. }
  287. }
  288. static bool fdls_is_oxid_fabric_req(uint16_t oxid)
  289. {
  290. int oxid_frame_type = FNIC_FRAME_TYPE(oxid);
  291. switch (oxid_frame_type) {
  292. case FNIC_FRAME_TYPE_FABRIC_FLOGI:
  293. case FNIC_FRAME_TYPE_FABRIC_PLOGI:
  294. case FNIC_FRAME_TYPE_FABRIC_RPN:
  295. case FNIC_FRAME_TYPE_FABRIC_RFT:
  296. case FNIC_FRAME_TYPE_FABRIC_RFF:
  297. case FNIC_FRAME_TYPE_FABRIC_GPN_FT:
  298. case FNIC_FRAME_TYPE_FABRIC_LOGO:
  299. break;
  300. default:
  301. return false;
  302. }
  303. return true;
  304. }
  305. static bool fdls_is_oxid_fdmi_req(uint16_t oxid)
  306. {
  307. int oxid_frame_type = FNIC_FRAME_TYPE(oxid);
  308. switch (oxid_frame_type) {
  309. case FNIC_FRAME_TYPE_FDMI_PLOGI:
  310. case FNIC_FRAME_TYPE_FDMI_RHBA:
  311. case FNIC_FRAME_TYPE_FDMI_RPA:
  312. break;
  313. default:
  314. return false;
  315. }
  316. return true;
  317. }
  318. static bool fdls_is_oxid_tgt_req(uint16_t oxid)
  319. {
  320. int oxid_frame_type = FNIC_FRAME_TYPE(oxid);
  321. switch (oxid_frame_type) {
  322. case FNIC_FRAME_TYPE_TGT_PLOGI:
  323. case FNIC_FRAME_TYPE_TGT_PRLI:
  324. case FNIC_FRAME_TYPE_TGT_ADISC:
  325. case FNIC_FRAME_TYPE_TGT_LOGO:
  326. break;
  327. default:
  328. return false;
  329. }
  330. return true;
  331. }
  332. static void fdls_reset_oxid_pool(struct fnic_iport_s *iport)
  333. {
  334. struct fnic_oxid_pool_s *oxid_pool = &iport->oxid_pool;
  335. oxid_pool->next_idx = 0;
  336. }
  337. void fnic_del_fabric_timer_sync(struct fnic *fnic)
  338. {
  339. fnic->iport.fabric.del_timer_inprogress = 1;
  340. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  341. timer_delete_sync(&fnic->iport.fabric.retry_timer);
  342. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  343. fnic->iport.fabric.del_timer_inprogress = 0;
  344. }
  345. void fnic_del_tport_timer_sync(struct fnic *fnic,
  346. struct fnic_tport_s *tport)
  347. {
  348. tport->del_timer_inprogress = 1;
  349. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  350. timer_delete_sync(&tport->retry_timer);
  351. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  352. tport->del_timer_inprogress = 0;
  353. }
  354. static void
  355. fdls_start_fabric_timer(struct fnic_iport_s *iport, int timeout)
  356. {
  357. u64 fabric_tov;
  358. struct fnic *fnic = iport->fnic;
  359. if (iport->fabric.timer_pending) {
  360. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  361. "iport fcid: 0x%x: Canceling fabric disc timer\n",
  362. iport->fcid);
  363. fnic_del_fabric_timer_sync(fnic);
  364. iport->fabric.timer_pending = 0;
  365. }
  366. if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED))
  367. iport->fabric.retry_counter++;
  368. fabric_tov = jiffies + msecs_to_jiffies(timeout);
  369. mod_timer(&iport->fabric.retry_timer, round_jiffies(fabric_tov));
  370. iport->fabric.timer_pending = 1;
  371. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  372. "fabric timer is %d ", timeout);
  373. }
  374. static void
  375. fdls_start_tport_timer(struct fnic_iport_s *iport,
  376. struct fnic_tport_s *tport, int timeout)
  377. {
  378. u64 fabric_tov;
  379. struct fnic *fnic = iport->fnic;
  380. if (tport->timer_pending) {
  381. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  382. "tport fcid 0x%x: Canceling disc timer\n",
  383. tport->fcid);
  384. fnic_del_tport_timer_sync(fnic, tport);
  385. tport->timer_pending = 0;
  386. }
  387. if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED))
  388. tport->retry_counter++;
  389. fabric_tov = jiffies + msecs_to_jiffies(timeout);
  390. mod_timer(&tport->retry_timer, round_jiffies(fabric_tov));
  391. tport->timer_pending = 1;
  392. }
  393. void fdls_init_plogi_frame(uint8_t *frame,
  394. struct fnic_iport_s *iport)
  395. {
  396. struct fc_std_flogi *pplogi;
  397. uint8_t s_id[3];
  398. pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  399. *pplogi = (struct fc_std_flogi) {
  400. .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_d_id = {0xFF, 0xFF, 0xFC},
  401. .fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  402. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
  403. .els = {
  404. .fl_cmd = ELS_PLOGI,
  405. .fl_csp = {.sp_hi_ver = FNIC_FC_PH_VER_HI,
  406. .sp_lo_ver = FNIC_FC_PH_VER_LO,
  407. .sp_bb_cred = cpu_to_be16(FNIC_FC_B2B_CREDIT),
  408. .sp_features = cpu_to_be16(FC_SP_FT_CIRO),
  409. .sp_bb_data = cpu_to_be16(FNIC_FC_B2B_RDF_SZ),
  410. .sp_tot_seq = cpu_to_be16(FNIC_FC_CONCUR_SEQS),
  411. .sp_rel_off = cpu_to_be16(FNIC_FC_RO_INFO),
  412. .sp_e_d_tov = cpu_to_be32(FC_DEF_E_D_TOV)},
  413. .fl_cssp[2].cp_class = cpu_to_be16(FC_CPC_VALID | FC_CPC_SEQ),
  414. .fl_cssp[2].cp_rdfs = cpu_to_be16(0x800),
  415. .fl_cssp[2].cp_con_seq = cpu_to_be16(0xFF),
  416. .fl_cssp[2].cp_open_seq = 1}
  417. };
  418. FNIC_STD_SET_NPORT_NAME(&pplogi->els.fl_wwpn, iport->wwpn);
  419. FNIC_STD_SET_NODE_NAME(&pplogi->els.fl_wwnn, iport->wwnn);
  420. FNIC_LOGI_SET_RDF_SIZE(pplogi->els, iport->max_payload_size);
  421. hton24(s_id, iport->fcid);
  422. FNIC_STD_SET_S_ID(pplogi->fchdr, s_id);
  423. }
  424. static void fdls_init_els_acc_frame(uint8_t *frame,
  425. struct fnic_iport_s *iport)
  426. {
  427. struct fc_std_els_acc_rsp *pels_acc;
  428. uint8_t s_id[3];
  429. pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  430. *pels_acc = (struct fc_std_els_acc_rsp) {
  431. .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REP,
  432. .fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REP_FCTL, 0, 0}},
  433. .acc.la_cmd = ELS_LS_ACC,
  434. };
  435. hton24(s_id, iport->fcid);
  436. FNIC_STD_SET_S_ID(pels_acc->fchdr, s_id);
  437. FNIC_STD_SET_RX_ID(pels_acc->fchdr, FNIC_UNASSIGNED_RXID);
  438. }
  439. static void fdls_init_els_rjt_frame(uint8_t *frame,
  440. struct fnic_iport_s *iport)
  441. {
  442. struct fc_std_els_rjt_rsp *pels_rjt;
  443. pels_rjt = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  444. *pels_rjt = (struct fc_std_els_rjt_rsp) {
  445. .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REP, .fh_type = FC_TYPE_ELS,
  446. .fh_f_ctl = {FNIC_ELS_REP_FCTL, 0, 0}},
  447. .rej.er_cmd = ELS_LS_RJT,
  448. };
  449. FNIC_STD_SET_RX_ID(pels_rjt->fchdr, FNIC_UNASSIGNED_RXID);
  450. }
  451. static void fdls_init_logo_frame(uint8_t *frame,
  452. struct fnic_iport_s *iport)
  453. {
  454. struct fc_std_logo *plogo;
  455. uint8_t s_id[3];
  456. plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  457. *plogo = (struct fc_std_logo) {
  458. .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_type = FC_TYPE_ELS,
  459. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0}},
  460. .els.fl_cmd = ELS_LOGO,
  461. };
  462. hton24(s_id, iport->fcid);
  463. FNIC_STD_SET_S_ID(plogo->fchdr, s_id);
  464. memcpy(plogo->els.fl_n_port_id, s_id, 3);
  465. FNIC_STD_SET_NPORT_NAME(&plogo->els.fl_n_port_wwn,
  466. iport->wwpn);
  467. }
  468. static void fdls_init_fabric_abts_frame(uint8_t *frame,
  469. struct fnic_iport_s *iport)
  470. {
  471. struct fc_frame_header *pfabric_abts;
  472. pfabric_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  473. *pfabric_abts = (struct fc_frame_header) {
  474. .fh_r_ctl = FC_RCTL_BA_ABTS, /* ABTS */
  475. .fh_s_id = {0x00, 0x00, 0x00},
  476. .fh_cs_ctl = 0x00, .fh_type = FC_TYPE_BLS,
  477. .fh_f_ctl = {FNIC_REQ_ABTS_FCTL, 0, 0}, .fh_seq_id = 0x00,
  478. .fh_df_ctl = 0x00, .fh_seq_cnt = 0x0000,
  479. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID),
  480. .fh_parm_offset = 0x00000000, /* bit:0 = 0 Abort a exchange */
  481. };
  482. }
  483. static void
  484. fdls_send_rscn_resp(struct fnic_iport_s *iport,
  485. struct fc_frame_header *rscn_fchdr)
  486. {
  487. uint8_t *frame;
  488. struct fc_std_els_acc_rsp *pels_acc;
  489. struct fnic *fnic = iport->fnic;
  490. uint16_t oxid;
  491. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  492. sizeof(struct fc_std_els_acc_rsp);
  493. frame = fdls_alloc_frame(iport);
  494. if (frame == NULL) {
  495. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  496. "Failed to allocate frame to send RSCN response");
  497. return;
  498. }
  499. pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  500. fdls_init_els_acc_frame(frame, iport);
  501. FNIC_STD_SET_D_ID(pels_acc->fchdr, rscn_fchdr->fh_s_id);
  502. oxid = FNIC_STD_GET_OX_ID(rscn_fchdr);
  503. FNIC_STD_SET_OX_ID(pels_acc->fchdr, oxid);
  504. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  505. "0x%x: FDLS send RSCN response with oxid: 0x%x",
  506. iport->fcid, oxid);
  507. fnic_send_fcoe_frame(iport, frame, frame_size);
  508. }
  509. static void
  510. fdls_send_logo_resp(struct fnic_iport_s *iport,
  511. struct fc_frame_header *req_fchdr)
  512. {
  513. uint8_t *frame;
  514. struct fc_std_els_acc_rsp *plogo_resp;
  515. struct fnic *fnic = iport->fnic;
  516. uint16_t oxid;
  517. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  518. sizeof(struct fc_std_els_acc_rsp);
  519. frame = fdls_alloc_frame(iport);
  520. if (frame == NULL) {
  521. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  522. "Failed to allocate frame to send LOGO response");
  523. return;
  524. }
  525. plogo_resp = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  526. fdls_init_els_acc_frame(frame, iport);
  527. FNIC_STD_SET_D_ID(plogo_resp->fchdr, req_fchdr->fh_s_id);
  528. oxid = FNIC_STD_GET_OX_ID(req_fchdr);
  529. FNIC_STD_SET_OX_ID(plogo_resp->fchdr, oxid);
  530. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  531. "0x%x: FDLS send LOGO response with oxid: 0x%x",
  532. iport->fcid, oxid);
  533. fnic_send_fcoe_frame(iport, frame, frame_size);
  534. }
  535. void
  536. fdls_send_tport_abts(struct fnic_iport_s *iport,
  537. struct fnic_tport_s *tport)
  538. {
  539. uint8_t *frame;
  540. uint8_t s_id[3];
  541. uint8_t d_id[3];
  542. struct fnic *fnic = iport->fnic;
  543. struct fc_frame_header *ptport_abts;
  544. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  545. sizeof(struct fc_frame_header);
  546. frame = fdls_alloc_frame(iport);
  547. if (frame == NULL) {
  548. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  549. "Failed to allocate frame to send tport ABTS");
  550. return;
  551. }
  552. ptport_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  553. *ptport_abts = (struct fc_frame_header) {
  554. .fh_r_ctl = FC_RCTL_BA_ABTS, /* ABTS */
  555. .fh_cs_ctl = 0x00, .fh_type = FC_TYPE_BLS,
  556. .fh_f_ctl = {FNIC_REQ_ABTS_FCTL, 0, 0}, .fh_seq_id = 0x00,
  557. .fh_df_ctl = 0x00, .fh_seq_cnt = 0x0000,
  558. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID),
  559. .fh_parm_offset = 0x00000000, /* bit:0 = 0 Abort a exchange */
  560. };
  561. hton24(s_id, iport->fcid);
  562. hton24(d_id, tport->fcid);
  563. FNIC_STD_SET_S_ID(*ptport_abts, s_id);
  564. FNIC_STD_SET_D_ID(*ptport_abts, d_id);
  565. tport->flags |= FNIC_FDLS_TGT_ABORT_ISSUED;
  566. FNIC_STD_SET_OX_ID(*ptport_abts, tport->active_oxid);
  567. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  568. "0x%x: FDLS send tport abts: tport->state: %d ",
  569. iport->fcid, tport->state);
  570. fnic_send_fcoe_frame(iport, frame, frame_size);
  571. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  572. fdls_start_tport_timer(iport, tport, 2 * iport->e_d_tov);
  573. }
  574. static void fdls_send_fabric_abts(struct fnic_iport_s *iport)
  575. {
  576. uint8_t *frame;
  577. uint8_t s_id[3];
  578. uint8_t d_id[3];
  579. struct fnic *fnic = iport->fnic;
  580. struct fc_frame_header *pfabric_abts;
  581. uint16_t oxid;
  582. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  583. sizeof(struct fc_frame_header);
  584. frame = fdls_alloc_frame(iport);
  585. if (frame == NULL) {
  586. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  587. "Failed to allocate frame to send fabric ABTS");
  588. return;
  589. }
  590. pfabric_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  591. fdls_init_fabric_abts_frame(frame, iport);
  592. hton24(s_id, iport->fcid);
  593. switch (iport->fabric.state) {
  594. case FDLS_STATE_FABRIC_LOGO:
  595. hton24(d_id, FC_FID_FLOGI);
  596. FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
  597. break;
  598. case FDLS_STATE_FABRIC_FLOGI:
  599. hton24(d_id, FC_FID_FLOGI);
  600. FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
  601. break;
  602. case FDLS_STATE_FABRIC_PLOGI:
  603. FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
  604. hton24(d_id, FC_FID_DIR_SERV);
  605. FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
  606. break;
  607. case FDLS_STATE_RPN_ID:
  608. FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
  609. hton24(d_id, FC_FID_DIR_SERV);
  610. FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
  611. break;
  612. case FDLS_STATE_SCR:
  613. FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
  614. hton24(d_id, FC_FID_FCTRL);
  615. FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
  616. break;
  617. case FDLS_STATE_REGISTER_FC4_TYPES:
  618. FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
  619. hton24(d_id, FC_FID_DIR_SERV);
  620. FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
  621. break;
  622. case FDLS_STATE_REGISTER_FC4_FEATURES:
  623. FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
  624. hton24(d_id, FC_FID_DIR_SERV);
  625. FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
  626. break;
  627. case FDLS_STATE_GPN_FT:
  628. FNIC_STD_SET_S_ID(*pfabric_abts, s_id);
  629. hton24(d_id, FC_FID_DIR_SERV);
  630. FNIC_STD_SET_D_ID(*pfabric_abts, d_id);
  631. break;
  632. default:
  633. return;
  634. }
  635. oxid = iport->active_oxid_fabric_req;
  636. FNIC_STD_SET_OX_ID(*pfabric_abts, oxid);
  637. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  638. "0x%x: FDLS send fabric abts. iport->fabric.state: %d oxid: 0x%x",
  639. iport->fcid, iport->fabric.state, oxid);
  640. iport->fabric.flags |= FNIC_FDLS_FABRIC_ABORT_ISSUED;
  641. fnic_send_fcoe_frame(iport, frame, frame_size);
  642. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  643. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  644. iport->fabric.timer_pending = 1;
  645. }
  646. static uint8_t *fdls_alloc_init_fdmi_abts_frame(struct fnic_iport_s *iport,
  647. uint16_t oxid)
  648. {
  649. struct fc_frame_header *pfdmi_abts;
  650. uint8_t d_id[3];
  651. uint8_t *frame;
  652. struct fnic *fnic = iport->fnic;
  653. frame = fdls_alloc_frame(iport);
  654. if (frame == NULL) {
  655. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  656. "Failed to allocate frame to send FDMI ABTS");
  657. return NULL;
  658. }
  659. pfdmi_abts = (struct fc_frame_header *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  660. fdls_init_fabric_abts_frame(frame, iport);
  661. hton24(d_id, FC_FID_MGMT_SERV);
  662. FNIC_STD_SET_D_ID(*pfdmi_abts, d_id);
  663. FNIC_STD_SET_OX_ID(*pfdmi_abts, oxid);
  664. return frame;
  665. }
  666. static void fdls_send_fdmi_abts(struct fnic_iport_s *iport)
  667. {
  668. uint8_t *frame;
  669. struct fnic *fnic = iport->fnic;
  670. unsigned long fdmi_tov;
  671. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  672. sizeof(struct fc_frame_header);
  673. if (iport->fabric.fdmi_pending & FDLS_FDMI_PLOGI_PENDING) {
  674. frame = fdls_alloc_init_fdmi_abts_frame(iport,
  675. iport->active_oxid_fdmi_plogi);
  676. if (frame == NULL)
  677. return;
  678. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  679. "0x%x: FDLS send FDMI PLOGI abts. iport->fabric.state: %d oxid: 0x%x",
  680. iport->fcid, iport->fabric.state, iport->active_oxid_fdmi_plogi);
  681. fnic_send_fcoe_frame(iport, frame, frame_size);
  682. } else {
  683. if (iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING) {
  684. frame = fdls_alloc_init_fdmi_abts_frame(iport,
  685. iport->active_oxid_fdmi_rhba);
  686. if (frame == NULL)
  687. return;
  688. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  689. "0x%x: FDLS send FDMI RHBA abts. iport->fabric.state: %d oxid: 0x%x",
  690. iport->fcid, iport->fabric.state, iport->active_oxid_fdmi_rhba);
  691. fnic_send_fcoe_frame(iport, frame, frame_size);
  692. }
  693. if (iport->fabric.fdmi_pending & FDLS_FDMI_RPA_PENDING) {
  694. frame = fdls_alloc_init_fdmi_abts_frame(iport,
  695. iport->active_oxid_fdmi_rpa);
  696. if (frame == NULL) {
  697. if (iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING)
  698. goto arm_timer;
  699. else
  700. return;
  701. }
  702. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  703. "0x%x: FDLS send FDMI RPA abts. iport->fabric.state: %d oxid: 0x%x",
  704. iport->fcid, iport->fabric.state, iport->active_oxid_fdmi_rpa);
  705. fnic_send_fcoe_frame(iport, frame, frame_size);
  706. }
  707. }
  708. arm_timer:
  709. fdmi_tov = jiffies + msecs_to_jiffies(2 * iport->e_d_tov);
  710. mod_timer(&iport->fabric.fdmi_timer, round_jiffies(fdmi_tov));
  711. iport->fabric.fdmi_pending |= FDLS_FDMI_ABORT_PENDING;
  712. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  713. "0x%x: iport->fabric.fdmi_pending: 0x%x",
  714. iport->fcid, iport->fabric.fdmi_pending);
  715. }
  716. static void fdls_send_fabric_flogi(struct fnic_iport_s *iport)
  717. {
  718. uint8_t *frame;
  719. struct fc_std_flogi *pflogi;
  720. struct fnic *fnic = iport->fnic;
  721. uint16_t oxid;
  722. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  723. sizeof(struct fc_std_flogi);
  724. frame = fdls_alloc_frame(iport);
  725. if (frame == NULL) {
  726. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  727. "Failed to allocate frame to send FLOGI");
  728. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  729. goto err_out;
  730. }
  731. pflogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  732. *pflogi = (struct fc_std_flogi) {
  733. .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_d_id = {0xFF, 0xFF, 0xFE},
  734. .fh_type = FC_TYPE_ELS, .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  735. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
  736. .els.fl_cmd = ELS_FLOGI,
  737. .els.fl_csp = {.sp_hi_ver = FNIC_FC_PH_VER_HI,
  738. .sp_lo_ver = FNIC_FC_PH_VER_LO,
  739. .sp_bb_cred = cpu_to_be16(FNIC_FC_B2B_CREDIT),
  740. .sp_bb_data = cpu_to_be16(FNIC_FC_B2B_RDF_SZ)},
  741. .els.fl_cssp[2].cp_class = cpu_to_be16(FC_CPC_VALID | FC_CPC_SEQ)
  742. };
  743. FNIC_STD_SET_NPORT_NAME(&pflogi->els.fl_wwpn, iport->wwpn);
  744. FNIC_STD_SET_NODE_NAME(&pflogi->els.fl_wwnn, iport->wwnn);
  745. FNIC_LOGI_SET_RDF_SIZE(pflogi->els, iport->max_payload_size);
  746. FNIC_LOGI_SET_R_A_TOV(pflogi->els, iport->r_a_tov);
  747. FNIC_LOGI_SET_E_D_TOV(pflogi->els, iport->e_d_tov);
  748. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_FLOGI,
  749. &iport->active_oxid_fabric_req);
  750. if (oxid == FNIC_UNASSIGNED_OXID) {
  751. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  752. "0x%x: Failed to allocate OXID to send FLOGI",
  753. iport->fcid);
  754. mempool_free(frame, fnic->frame_pool);
  755. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  756. goto err_out;
  757. }
  758. FNIC_STD_SET_OX_ID(pflogi->fchdr, oxid);
  759. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  760. "0x%x: FDLS send fabric FLOGI with oxid: 0x%x", iport->fcid,
  761. oxid);
  762. fnic_send_fcoe_frame(iport, frame, frame_size);
  763. atomic64_inc(&iport->iport_stats.fabric_flogi_sent);
  764. err_out:
  765. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  766. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  767. }
  768. static void fdls_send_fabric_plogi(struct fnic_iport_s *iport)
  769. {
  770. uint8_t *frame;
  771. struct fc_std_flogi *pplogi;
  772. struct fnic *fnic = iport->fnic;
  773. uint16_t oxid;
  774. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  775. sizeof(struct fc_std_flogi);
  776. frame = fdls_alloc_frame(iport);
  777. if (frame == NULL) {
  778. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  779. "Failed to allocate frame to send PLOGI");
  780. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  781. goto err_out;
  782. }
  783. pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  784. fdls_init_plogi_frame(frame, iport);
  785. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_PLOGI,
  786. &iport->active_oxid_fabric_req);
  787. if (oxid == FNIC_UNASSIGNED_OXID) {
  788. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  789. "0x%x: Failed to allocate OXID to send fabric PLOGI",
  790. iport->fcid);
  791. mempool_free(frame, fnic->frame_pool);
  792. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  793. goto err_out;
  794. }
  795. FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid);
  796. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  797. "0x%x: FDLS send fabric PLOGI with oxid: 0x%x", iport->fcid,
  798. oxid);
  799. fnic_send_fcoe_frame(iport, frame, frame_size);
  800. atomic64_inc(&iport->iport_stats.fabric_plogi_sent);
  801. err_out:
  802. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  803. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  804. }
  805. static void fdls_send_fdmi_plogi(struct fnic_iport_s *iport)
  806. {
  807. uint8_t *frame;
  808. struct fc_std_flogi *pplogi;
  809. struct fnic *fnic = iport->fnic;
  810. uint16_t oxid;
  811. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  812. sizeof(struct fc_std_flogi);
  813. uint8_t d_id[3];
  814. u64 fdmi_tov;
  815. frame = fdls_alloc_frame(iport);
  816. if (frame == NULL) {
  817. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  818. "Failed to allocate frame to send FDMI PLOGI");
  819. goto err_out;
  820. }
  821. pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  822. fdls_init_plogi_frame(frame, iport);
  823. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_PLOGI,
  824. &iport->active_oxid_fdmi_plogi);
  825. if (oxid == FNIC_UNASSIGNED_OXID) {
  826. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  827. "0x%x: Failed to allocate OXID to send FDMI PLOGI",
  828. iport->fcid);
  829. mempool_free(frame, fnic->frame_pool);
  830. goto err_out;
  831. }
  832. FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid);
  833. hton24(d_id, FC_FID_MGMT_SERV);
  834. FNIC_STD_SET_D_ID(pplogi->fchdr, d_id);
  835. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  836. "0x%x: FDLS send FDMI PLOGI with oxid: 0x%x",
  837. iport->fcid, oxid);
  838. fnic_send_fcoe_frame(iport, frame, frame_size);
  839. err_out:
  840. fdmi_tov = jiffies + msecs_to_jiffies(2 * iport->e_d_tov);
  841. mod_timer(&iport->fabric.fdmi_timer, round_jiffies(fdmi_tov));
  842. iport->fabric.fdmi_pending = FDLS_FDMI_PLOGI_PENDING;
  843. }
  844. static void fdls_send_rpn_id(struct fnic_iport_s *iport)
  845. {
  846. uint8_t *frame;
  847. struct fc_std_rpn_id *prpn_id;
  848. struct fnic *fnic = iport->fnic;
  849. uint16_t oxid;
  850. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  851. sizeof(struct fc_std_rpn_id);
  852. uint8_t fcid[3];
  853. frame = fdls_alloc_frame(iport);
  854. if (frame == NULL) {
  855. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  856. "Failed to allocate frame to send RPN_ID");
  857. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  858. goto err_out;
  859. }
  860. prpn_id = (struct fc_std_rpn_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  861. *prpn_id = (struct fc_std_rpn_id) {
  862. .fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
  863. .fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT,
  864. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  865. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
  866. .fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR,
  867. .ct_fs_subtype = FC_NS_SUBTYPE,
  868. .ct_cmd = cpu_to_be16(FC_NS_RPN_ID)}
  869. };
  870. hton24(fcid, iport->fcid);
  871. FNIC_STD_SET_S_ID(prpn_id->fchdr, fcid);
  872. FNIC_STD_SET_PORT_ID(prpn_id->rpn_id, fcid);
  873. FNIC_STD_SET_PORT_NAME(prpn_id->rpn_id, iport->wwpn);
  874. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RPN,
  875. &iport->active_oxid_fabric_req);
  876. if (oxid == FNIC_UNASSIGNED_OXID) {
  877. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  878. "0x%x: Failed to allocate OXID to send RPN_ID",
  879. iport->fcid);
  880. mempool_free(frame, fnic->frame_pool);
  881. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  882. goto err_out;
  883. }
  884. FNIC_STD_SET_OX_ID(prpn_id->fchdr, oxid);
  885. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  886. "0x%x: FDLS send RPN ID with oxid: 0x%x", iport->fcid,
  887. oxid);
  888. fnic_send_fcoe_frame(iport, frame, frame_size);
  889. err_out:
  890. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  891. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  892. }
  893. static void fdls_send_scr(struct fnic_iport_s *iport)
  894. {
  895. uint8_t *frame;
  896. struct fc_std_scr *pscr;
  897. struct fnic *fnic = iport->fnic;
  898. uint16_t oxid;
  899. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  900. sizeof(struct fc_std_scr);
  901. uint8_t fcid[3];
  902. frame = fdls_alloc_frame(iport);
  903. if (frame == NULL) {
  904. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  905. "Failed to allocate frame to send SCR");
  906. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  907. goto err_out;
  908. }
  909. pscr = (struct fc_std_scr *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  910. *pscr = (struct fc_std_scr) {
  911. .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ,
  912. .fh_d_id = {0xFF, 0xFF, 0xFD}, .fh_type = FC_TYPE_ELS,
  913. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  914. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
  915. .scr = {.scr_cmd = ELS_SCR,
  916. .scr_reg_func = ELS_SCRF_FULL}
  917. };
  918. hton24(fcid, iport->fcid);
  919. FNIC_STD_SET_S_ID(pscr->fchdr, fcid);
  920. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_SCR,
  921. &iport->active_oxid_fabric_req);
  922. if (oxid == FNIC_UNASSIGNED_OXID) {
  923. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  924. "0x%x: Failed to allocate OXID to send SCR",
  925. iport->fcid);
  926. mempool_free(frame, fnic->frame_pool);
  927. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  928. goto err_out;
  929. }
  930. FNIC_STD_SET_OX_ID(pscr->fchdr, oxid);
  931. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  932. "0x%x: FDLS send SCR with oxid: 0x%x", iport->fcid,
  933. oxid);
  934. fnic_send_fcoe_frame(iport, frame, frame_size);
  935. atomic64_inc(&iport->iport_stats.fabric_scr_sent);
  936. err_out:
  937. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  938. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  939. }
  940. static void fdls_send_gpn_ft(struct fnic_iport_s *iport, int fdls_state)
  941. {
  942. uint8_t *frame;
  943. struct fc_std_gpn_ft *pgpn_ft;
  944. struct fnic *fnic = iport->fnic;
  945. uint16_t oxid;
  946. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  947. sizeof(struct fc_std_gpn_ft);
  948. uint8_t fcid[3];
  949. frame = fdls_alloc_frame(iport);
  950. if (frame == NULL) {
  951. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  952. "Failed to allocate frame to send GPN FT");
  953. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  954. goto err_out;
  955. }
  956. pgpn_ft = (struct fc_std_gpn_ft *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  957. *pgpn_ft = (struct fc_std_gpn_ft) {
  958. .fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
  959. .fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT,
  960. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  961. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
  962. .fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR,
  963. .ct_fs_subtype = FC_NS_SUBTYPE,
  964. .ct_cmd = cpu_to_be16(FC_NS_GPN_FT)},
  965. .gpn_ft.fn_fc4_type = 0x08
  966. };
  967. hton24(fcid, iport->fcid);
  968. FNIC_STD_SET_S_ID(pgpn_ft->fchdr, fcid);
  969. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_GPN_FT,
  970. &iport->active_oxid_fabric_req);
  971. if (oxid == FNIC_UNASSIGNED_OXID) {
  972. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  973. "0x%x: Failed to allocate OXID to send GPN FT",
  974. iport->fcid);
  975. mempool_free(frame, fnic->frame_pool);
  976. iport->fabric.flags |= FNIC_FDLS_RETRY_FRAME;
  977. goto err_out;
  978. }
  979. FNIC_STD_SET_OX_ID(pgpn_ft->fchdr, oxid);
  980. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  981. "0x%x: FDLS send GPN FT with oxid: 0x%x", iport->fcid,
  982. oxid);
  983. fnic_send_fcoe_frame(iport, frame, frame_size);
  984. err_out:
  985. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  986. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  987. fdls_set_state((&iport->fabric), fdls_state);
  988. }
  989. static void
  990. fdls_send_tgt_adisc(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
  991. {
  992. uint8_t *frame;
  993. struct fc_std_els_adisc *padisc;
  994. uint8_t s_id[3];
  995. uint8_t d_id[3];
  996. uint16_t oxid;
  997. struct fnic *fnic = iport->fnic;
  998. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  999. sizeof(struct fc_std_els_adisc);
  1000. frame = fdls_alloc_frame(iport);
  1001. if (frame == NULL) {
  1002. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1003. "Failed to allocate frame to send TGT ADISC");
  1004. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  1005. goto err_out;
  1006. }
  1007. padisc = (struct fc_std_els_adisc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1008. hton24(s_id, iport->fcid);
  1009. hton24(d_id, tport->fcid);
  1010. memcpy(padisc->els.adisc_port_id, s_id, 3);
  1011. FNIC_STD_SET_S_ID(padisc->fchdr, s_id);
  1012. FNIC_STD_SET_D_ID(padisc->fchdr, d_id);
  1013. FNIC_STD_SET_F_CTL(padisc->fchdr, FNIC_ELS_REQ_FCTL << 16);
  1014. FNIC_STD_SET_R_CTL(padisc->fchdr, FC_RCTL_ELS_REQ);
  1015. FNIC_STD_SET_TYPE(padisc->fchdr, FC_TYPE_ELS);
  1016. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_ADISC, &tport->active_oxid);
  1017. if (oxid == FNIC_UNASSIGNED_OXID) {
  1018. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1019. "0x%x: Failed to allocate OXID to send TGT ADISC",
  1020. iport->fcid);
  1021. mempool_free(frame, fnic->frame_pool);
  1022. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  1023. goto err_out;
  1024. }
  1025. FNIC_STD_SET_OX_ID(padisc->fchdr, oxid);
  1026. FNIC_STD_SET_RX_ID(padisc->fchdr, FNIC_UNASSIGNED_RXID);
  1027. tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED;
  1028. FNIC_STD_SET_NPORT_NAME(&padisc->els.adisc_wwpn,
  1029. iport->wwpn);
  1030. FNIC_STD_SET_NODE_NAME(&padisc->els.adisc_wwnn,
  1031. iport->wwnn);
  1032. padisc->els.adisc_cmd = ELS_ADISC;
  1033. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1034. "0x%x: FDLS send ADISC to tgt fcid: 0x%x",
  1035. iport->fcid, tport->fcid);
  1036. atomic64_inc(&iport->iport_stats.tport_adisc_sent);
  1037. fnic_send_fcoe_frame(iport, frame, frame_size);
  1038. err_out:
  1039. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  1040. fdls_start_tport_timer(iport, tport, 2 * iport->e_d_tov);
  1041. }
  1042. bool fdls_delete_tport(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
  1043. {
  1044. struct fnic_tport_event_s *tport_del_evt;
  1045. struct fnic *fnic = iport->fnic;
  1046. if ((tport->state == FDLS_TGT_STATE_OFFLINING)
  1047. || (tport->state == FDLS_TGT_STATE_OFFLINE)) {
  1048. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1049. "tport fcid 0x%x: tport state is offlining/offline\n",
  1050. tport->fcid);
  1051. return false;
  1052. }
  1053. fdls_set_tport_state(tport, FDLS_TGT_STATE_OFFLINING);
  1054. /*
  1055. * By setting this flag, the tport will not be seen in a look-up
  1056. * in an RSCN. Even if we move to multithreaded model, this tport
  1057. * will be destroyed and a new RSCN will have to create a new one
  1058. */
  1059. tport->flags |= FNIC_FDLS_TPORT_TERMINATING;
  1060. if (tport->timer_pending) {
  1061. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1062. "tport fcid 0x%x: Canceling disc timer\n",
  1063. tport->fcid);
  1064. fnic_del_tport_timer_sync(fnic, tport);
  1065. tport->timer_pending = 0;
  1066. }
  1067. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  1068. fnic_rport_exch_reset(iport->fnic, tport->fcid);
  1069. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  1070. if (tport->flags & FNIC_FDLS_SCSI_REGISTERED) {
  1071. tport_del_evt =
  1072. kzalloc_obj(struct fnic_tport_event_s, GFP_ATOMIC);
  1073. if (!tport_del_evt) {
  1074. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1075. "Failed to allocate memory for tport fcid: 0x%0x\n",
  1076. tport->fcid);
  1077. return false;
  1078. }
  1079. tport_del_evt->event = TGT_EV_RPORT_DEL;
  1080. tport_del_evt->arg1 = (void *) tport;
  1081. list_add_tail(&tport_del_evt->links, &fnic->tport_event_list);
  1082. queue_work(fnic_event_queue, &fnic->tport_work);
  1083. } else {
  1084. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1085. "tport 0x%x not reg with scsi_transport. Freeing locally",
  1086. tport->fcid);
  1087. list_del(&tport->links);
  1088. kfree(tport);
  1089. }
  1090. return true;
  1091. }
  1092. static void
  1093. fdls_send_tgt_plogi(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
  1094. {
  1095. uint8_t *frame;
  1096. struct fc_std_flogi *pplogi;
  1097. struct fnic *fnic = iport->fnic;
  1098. uint16_t oxid;
  1099. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  1100. sizeof(struct fc_std_flogi);
  1101. uint8_t d_id[3];
  1102. uint32_t timeout;
  1103. frame = fdls_alloc_frame(iport);
  1104. if (frame == NULL) {
  1105. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1106. "Failed to allocate frame to send TGT PLOGI");
  1107. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  1108. goto err_out;
  1109. }
  1110. pplogi = (struct fc_std_flogi *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1111. fdls_init_plogi_frame(frame, iport);
  1112. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_PLOGI, &tport->active_oxid);
  1113. if (oxid == FNIC_UNASSIGNED_OXID) {
  1114. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1115. "0x%x: Failed to allocate oxid to send PLOGI to fcid: 0x%x",
  1116. iport->fcid, tport->fcid);
  1117. mempool_free(frame, fnic->frame_pool);
  1118. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  1119. goto err_out;
  1120. }
  1121. FNIC_STD_SET_OX_ID(pplogi->fchdr, oxid);
  1122. tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED;
  1123. hton24(d_id, tport->fcid);
  1124. FNIC_STD_SET_D_ID(pplogi->fchdr, d_id);
  1125. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1126. "0x%x: FDLS send tgt PLOGI to tgt: 0x%x with oxid: 0x%x",
  1127. iport->fcid, tport->fcid, oxid);
  1128. fnic_send_fcoe_frame(iport, frame, frame_size);
  1129. atomic64_inc(&iport->iport_stats.tport_plogi_sent);
  1130. err_out:
  1131. timeout = max(2 * iport->e_d_tov, iport->plogi_timeout);
  1132. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  1133. fdls_start_tport_timer(iport, tport, timeout);
  1134. }
  1135. static uint16_t
  1136. fnic_fc_plogi_rsp_rdf(struct fnic_iport_s *iport,
  1137. struct fc_std_flogi *plogi_rsp)
  1138. {
  1139. uint16_t b2b_rdf_size =
  1140. be16_to_cpu(FNIC_LOGI_RDF_SIZE(plogi_rsp->els));
  1141. uint16_t spc3_rdf_size =
  1142. be16_to_cpu(plogi_rsp->els.fl_cssp[2].cp_rdfs) & FNIC_FC_C3_RDF;
  1143. struct fnic *fnic = iport->fnic;
  1144. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1145. "MFS: b2b_rdf_size: 0x%x spc3_rdf_size: 0x%x",
  1146. b2b_rdf_size, spc3_rdf_size);
  1147. return min(b2b_rdf_size, spc3_rdf_size);
  1148. }
  1149. static void fdls_send_register_fc4_types(struct fnic_iport_s *iport)
  1150. {
  1151. uint8_t *frame;
  1152. struct fc_std_rft_id *prft_id;
  1153. struct fnic *fnic = iport->fnic;
  1154. uint16_t oxid;
  1155. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  1156. sizeof(struct fc_std_rft_id);
  1157. uint8_t fcid[3];
  1158. frame = fdls_alloc_frame(iport);
  1159. if (frame == NULL) {
  1160. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1161. "Failed to allocate frame to send RFT");
  1162. return;
  1163. }
  1164. prft_id = (struct fc_std_rft_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1165. *prft_id = (struct fc_std_rft_id) {
  1166. .fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
  1167. .fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT,
  1168. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  1169. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
  1170. .fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR,
  1171. .ct_fs_subtype = FC_NS_SUBTYPE,
  1172. .ct_cmd = cpu_to_be16(FC_NS_RFT_ID)}
  1173. };
  1174. hton24(fcid, iport->fcid);
  1175. FNIC_STD_SET_S_ID(prft_id->fchdr, fcid);
  1176. FNIC_STD_SET_PORT_ID(prft_id->rft_id, fcid);
  1177. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RFT,
  1178. &iport->active_oxid_fabric_req);
  1179. if (oxid == FNIC_UNASSIGNED_OXID) {
  1180. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1181. "0x%x: Failed to allocate OXID to send RFT",
  1182. iport->fcid);
  1183. mempool_free(frame, fnic->frame_pool);
  1184. return;
  1185. }
  1186. FNIC_STD_SET_OX_ID(prft_id->fchdr, oxid);
  1187. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1188. "0x%x: FDLS send RFT with oxid: 0x%x", iport->fcid,
  1189. oxid);
  1190. prft_id->rft_id.fr_fts.ff_type_map[0] =
  1191. cpu_to_be32(1 << FC_TYPE_FCP);
  1192. prft_id->rft_id.fr_fts.ff_type_map[1] =
  1193. cpu_to_be32(1 << (FC_TYPE_CT % FC_NS_BPW));
  1194. fnic_send_fcoe_frame(iport, frame, frame_size);
  1195. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  1196. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  1197. }
  1198. static void fdls_send_register_fc4_features(struct fnic_iport_s *iport)
  1199. {
  1200. uint8_t *frame;
  1201. struct fc_std_rff_id *prff_id;
  1202. struct fnic *fnic = iport->fnic;
  1203. uint16_t oxid;
  1204. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  1205. sizeof(struct fc_std_rff_id);
  1206. uint8_t fcid[3];
  1207. frame = fdls_alloc_frame(iport);
  1208. if (frame == NULL) {
  1209. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1210. "Failed to allocate frame to send RFF");
  1211. return;
  1212. }
  1213. prff_id = (struct fc_std_rff_id *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1214. *prff_id = (struct fc_std_rff_id) {
  1215. .fchdr = {.fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
  1216. .fh_d_id = {0xFF, 0xFF, 0xFC}, .fh_type = FC_TYPE_CT,
  1217. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  1218. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
  1219. .fc_std_ct_hdr = {.ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_DIR,
  1220. .ct_fs_subtype = FC_NS_SUBTYPE,
  1221. .ct_cmd = cpu_to_be16(FC_NS_RFF_ID)},
  1222. .rff_id.fr_feat = 0x2,
  1223. .rff_id.fr_type = FC_TYPE_FCP
  1224. };
  1225. hton24(fcid, iport->fcid);
  1226. FNIC_STD_SET_S_ID(prff_id->fchdr, fcid);
  1227. FNIC_STD_SET_PORT_ID(prff_id->rff_id, fcid);
  1228. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_RFF,
  1229. &iport->active_oxid_fabric_req);
  1230. if (oxid == FNIC_UNASSIGNED_OXID) {
  1231. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1232. "0x%x: Failed to allocate OXID to send RFF",
  1233. iport->fcid);
  1234. mempool_free(frame, fnic->frame_pool);
  1235. return;
  1236. }
  1237. FNIC_STD_SET_OX_ID(prff_id->fchdr, oxid);
  1238. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1239. "0x%x: FDLS send RFF with oxid: 0x%x", iport->fcid,
  1240. oxid);
  1241. prff_id->rff_id.fr_type = FC_TYPE_FCP;
  1242. fnic_send_fcoe_frame(iport, frame, frame_size);
  1243. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  1244. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  1245. }
  1246. static void
  1247. fdls_send_tgt_prli(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
  1248. {
  1249. uint8_t *frame;
  1250. struct fc_std_els_prli *pprli;
  1251. struct fnic *fnic = iport->fnic;
  1252. uint16_t oxid;
  1253. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  1254. sizeof(struct fc_std_els_prli);
  1255. uint8_t s_id[3];
  1256. uint8_t d_id[3];
  1257. uint32_t timeout;
  1258. frame = fdls_alloc_frame(iport);
  1259. if (frame == NULL) {
  1260. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1261. "Failed to allocate frame to send TGT PRLI");
  1262. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  1263. goto err_out;
  1264. }
  1265. pprli = (struct fc_std_els_prli *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1266. *pprli = (struct fc_std_els_prli) {
  1267. .fchdr = {.fh_r_ctl = FC_RCTL_ELS_REQ, .fh_type = FC_TYPE_ELS,
  1268. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  1269. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)},
  1270. .els_prli = {.prli_cmd = ELS_PRLI,
  1271. .prli_spp_len = 16,
  1272. .prli_len = cpu_to_be16(0x14)},
  1273. .sp = {.spp_type = 0x08, .spp_flags = 0x0020,
  1274. .spp_params = cpu_to_be32(0xA2)}
  1275. };
  1276. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_PRLI, &tport->active_oxid);
  1277. if (oxid == FNIC_UNASSIGNED_OXID) {
  1278. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1279. "0x%x: Failed to allocate OXID to send TGT PRLI to 0x%x",
  1280. iport->fcid, tport->fcid);
  1281. mempool_free(frame, fnic->frame_pool);
  1282. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  1283. goto err_out;
  1284. }
  1285. tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED;
  1286. hton24(s_id, iport->fcid);
  1287. hton24(d_id, tport->fcid);
  1288. FNIC_STD_SET_OX_ID(pprli->fchdr, oxid);
  1289. FNIC_STD_SET_S_ID(pprli->fchdr, s_id);
  1290. FNIC_STD_SET_D_ID(pprli->fchdr, d_id);
  1291. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1292. "0x%x: FDLS send PRLI to tgt: 0x%x with oxid: 0x%x",
  1293. iport->fcid, tport->fcid, oxid);
  1294. fnic_send_fcoe_frame(iport, frame, frame_size);
  1295. atomic64_inc(&iport->iport_stats.tport_prli_sent);
  1296. err_out:
  1297. timeout = max(2 * iport->e_d_tov, iport->plogi_timeout);
  1298. /* Even if fnic_send_fcoe_frame() fails we want to retry after timeout */
  1299. fdls_start_tport_timer(iport, tport, timeout);
  1300. }
  1301. /**
  1302. * fdls_send_fabric_logo - Send flogo to the fcf
  1303. * @iport: Handle to fnic iport
  1304. *
  1305. * This function does not change or check the fabric state.
  1306. * It the caller's responsibility to set the appropriate iport fabric
  1307. * state when this is called. Normally it is FDLS_STATE_FABRIC_LOGO.
  1308. * Currently this assumes to be called with fnic lock held.
  1309. */
  1310. void fdls_send_fabric_logo(struct fnic_iport_s *iport)
  1311. {
  1312. uint8_t *frame;
  1313. struct fc_std_logo *plogo;
  1314. struct fnic *fnic = iport->fnic;
  1315. uint8_t d_id[3];
  1316. uint16_t oxid;
  1317. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  1318. sizeof(struct fc_std_logo);
  1319. frame = fdls_alloc_frame(iport);
  1320. if (frame == NULL) {
  1321. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1322. "Failed to allocate frame to send fabric LOGO");
  1323. return;
  1324. }
  1325. plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1326. fdls_init_logo_frame(frame, iport);
  1327. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FABRIC_LOGO,
  1328. &iport->active_oxid_fabric_req);
  1329. if (oxid == FNIC_UNASSIGNED_OXID) {
  1330. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1331. "0x%x: Failed to allocate OXID to send fabric LOGO",
  1332. iport->fcid);
  1333. mempool_free(frame, fnic->frame_pool);
  1334. return;
  1335. }
  1336. FNIC_STD_SET_OX_ID(plogo->fchdr, oxid);
  1337. hton24(d_id, FC_FID_FLOGI);
  1338. FNIC_STD_SET_D_ID(plogo->fchdr, d_id);
  1339. iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
  1340. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1341. "0x%x: FDLS send fabric LOGO with oxid: 0x%x",
  1342. iport->fcid, oxid);
  1343. fnic_send_fcoe_frame(iport, frame, frame_size);
  1344. fdls_start_fabric_timer(iport, 2 * iport->e_d_tov);
  1345. }
  1346. /**
  1347. * fdls_tgt_logout - Send plogo to the remote port
  1348. * @iport: Handle to fnic iport
  1349. * @tport: Handle to remote port
  1350. *
  1351. * This function does not change or check the fabric/tport state.
  1352. * It the caller's responsibility to set the appropriate tport/fabric
  1353. * state when this is called. Normally that is fdls_tgt_state_plogo.
  1354. * This could be used to send plogo to nameserver process
  1355. * also not just target processes
  1356. */
  1357. void fdls_tgt_logout(struct fnic_iport_s *iport, struct fnic_tport_s *tport)
  1358. {
  1359. uint8_t *frame;
  1360. struct fc_std_logo *plogo;
  1361. struct fnic *fnic = iport->fnic;
  1362. uint8_t d_id[3];
  1363. uint16_t oxid;
  1364. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  1365. sizeof(struct fc_std_logo);
  1366. frame = fdls_alloc_frame(iport);
  1367. if (frame == NULL) {
  1368. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1369. "Failed to allocate frame to send fabric LOGO");
  1370. return;
  1371. }
  1372. plogo = (struct fc_std_logo *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1373. fdls_init_logo_frame(frame, iport);
  1374. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_TGT_LOGO, &tport->active_oxid);
  1375. if (oxid == FNIC_UNASSIGNED_OXID) {
  1376. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1377. "0x%x: Failed to allocate OXID to send tgt LOGO",
  1378. iport->fcid);
  1379. mempool_free(frame, fnic->frame_pool);
  1380. return;
  1381. }
  1382. FNIC_STD_SET_OX_ID(plogo->fchdr, oxid);
  1383. hton24(d_id, tport->fcid);
  1384. FNIC_STD_SET_D_ID(plogo->fchdr, d_id);
  1385. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1386. "0x%x: FDLS send tgt LOGO with oxid: 0x%x",
  1387. iport->fcid, oxid);
  1388. fnic_send_fcoe_frame(iport, frame, frame_size);
  1389. atomic64_inc(&iport->iport_stats.tport_logo_sent);
  1390. }
  1391. static void fdls_tgt_discovery_start(struct fnic_iport_s *iport)
  1392. {
  1393. struct fnic_tport_s *tport, *next;
  1394. u32 old_link_down_cnt = iport->fnic->link_down_cnt;
  1395. struct fnic *fnic = iport->fnic;
  1396. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1397. "0x%x: Starting FDLS target discovery", iport->fcid);
  1398. list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
  1399. if ((old_link_down_cnt != iport->fnic->link_down_cnt)
  1400. || (iport->state != FNIC_IPORT_STATE_READY)) {
  1401. break;
  1402. }
  1403. /* if we marked the tport as deleted due to GPN_FT
  1404. * We should not send ADISC anymore
  1405. */
  1406. if ((tport->state == FDLS_TGT_STATE_OFFLINING) ||
  1407. (tport->state == FDLS_TGT_STATE_OFFLINE))
  1408. continue;
  1409. /* For tports which have received RSCN */
  1410. if (tport->flags & FNIC_FDLS_TPORT_SEND_ADISC) {
  1411. tport->retry_counter = 0;
  1412. fdls_set_tport_state(tport, FDLS_TGT_STATE_ADISC);
  1413. tport->flags &= ~FNIC_FDLS_TPORT_SEND_ADISC;
  1414. fdls_send_tgt_adisc(iport, tport);
  1415. continue;
  1416. }
  1417. if (fdls_get_tport_state(tport) != FDLS_TGT_STATE_INIT) {
  1418. /* Not a new port, skip */
  1419. continue;
  1420. }
  1421. tport->retry_counter = 0;
  1422. fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI);
  1423. fdls_send_tgt_plogi(iport, tport);
  1424. }
  1425. fdls_set_state((&iport->fabric), FDLS_STATE_TGT_DISCOVERY);
  1426. }
  1427. /*
  1428. * Function to restart the IT nexus if we received any out of
  1429. * sequence PLOGI/PRLI response from the target.
  1430. * The memory for the new tport structure is allocated
  1431. * inside fdls_create_tport and added to the iport's tport list.
  1432. * This will get freed later during tport_offline/linkdown
  1433. * or module unload. The new_tport pointer will go out of scope
  1434. * safely since the memory it is
  1435. * pointing to it will be freed later
  1436. */
  1437. static void fdls_target_restart_nexus(struct fnic_tport_s *tport)
  1438. {
  1439. struct fnic_iport_s *iport = tport->iport;
  1440. struct fnic_tport_s *new_tport = NULL;
  1441. uint32_t fcid;
  1442. uint64_t wwpn;
  1443. int nexus_restart_count;
  1444. struct fnic *fnic = iport->fnic;
  1445. bool retval = true;
  1446. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1447. "tport fcid: 0x%x state: %d restart_count: %d",
  1448. tport->fcid, tport->state, tport->nexus_restart_count);
  1449. fcid = tport->fcid;
  1450. wwpn = tport->wwpn;
  1451. nexus_restart_count = tport->nexus_restart_count;
  1452. retval = fdls_delete_tport(iport, tport);
  1453. if (retval != true) {
  1454. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1455. "Error deleting tport: 0x%x", fcid);
  1456. return;
  1457. }
  1458. if (nexus_restart_count >= FNIC_TPORT_MAX_NEXUS_RESTART) {
  1459. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1460. "Exceeded nexus restart retries tport: 0x%x",
  1461. fcid);
  1462. return;
  1463. }
  1464. /*
  1465. * Allocate memory for the new tport and add it to
  1466. * iport's tport list.
  1467. * This memory will be freed during tport_offline/linkdown
  1468. * or module unload. The pointer new_tport is safe to go
  1469. * out of scope when this function returns, since the memory
  1470. * it is pointing to is guaranteed to be freed later
  1471. * as mentioned above.
  1472. */
  1473. new_tport = fdls_create_tport(iport, fcid, wwpn);
  1474. if (!new_tport) {
  1475. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1476. "Error creating new tport: 0x%x", fcid);
  1477. return;
  1478. }
  1479. new_tport->nexus_restart_count = nexus_restart_count + 1;
  1480. fdls_send_tgt_plogi(iport, new_tport);
  1481. fdls_set_tport_state(new_tport, FDLS_TGT_STATE_PLOGI);
  1482. }
  1483. struct fnic_tport_s *fnic_find_tport_by_fcid(struct fnic_iport_s *iport,
  1484. uint32_t fcid)
  1485. {
  1486. struct fnic_tport_s *tport, *next;
  1487. list_for_each_entry_safe(tport, next, &(iport->tport_list), links) {
  1488. if ((tport->fcid == fcid)
  1489. && !(tport->flags & FNIC_FDLS_TPORT_TERMINATING))
  1490. return tport;
  1491. }
  1492. return NULL;
  1493. }
  1494. static struct fnic_tport_s *fdls_create_tport(struct fnic_iport_s *iport,
  1495. uint32_t fcid, uint64_t wwpn)
  1496. {
  1497. struct fnic_tport_s *tport;
  1498. struct fnic *fnic = iport->fnic;
  1499. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1500. "FDLS create tport: fcid: 0x%x wwpn: 0x%llx", fcid, wwpn);
  1501. tport = kzalloc_obj(struct fnic_tport_s, GFP_ATOMIC);
  1502. if (!tport) {
  1503. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1504. "Memory allocation failure while creating tport: 0x%x\n",
  1505. fcid);
  1506. return NULL;
  1507. }
  1508. tport->max_payload_size = FNIC_FCOE_MAX_FRAME_SZ;
  1509. tport->r_a_tov = FC_DEF_R_A_TOV;
  1510. tport->e_d_tov = FC_DEF_E_D_TOV;
  1511. tport->fcid = fcid;
  1512. tport->wwpn = wwpn;
  1513. tport->iport = iport;
  1514. FNIC_FCS_DBG(KERN_DEBUG, fnic->host, fnic->fnic_num,
  1515. "Need to setup tport timer callback");
  1516. timer_setup(&tport->retry_timer, fdls_tport_timer_callback, 0);
  1517. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1518. "Added tport 0x%x", tport->fcid);
  1519. fdls_set_tport_state(tport, FDLS_TGT_STATE_INIT);
  1520. list_add_tail(&tport->links, &iport->tport_list);
  1521. atomic_set(&tport->in_flight, 0);
  1522. return tport;
  1523. }
  1524. struct fnic_tport_s *fnic_find_tport_by_wwpn(struct fnic_iport_s *iport,
  1525. uint64_t wwpn)
  1526. {
  1527. struct fnic_tport_s *tport, *next;
  1528. list_for_each_entry_safe(tport, next, &(iport->tport_list), links) {
  1529. if ((tport->wwpn == wwpn)
  1530. && !(tport->flags & FNIC_FDLS_TPORT_TERMINATING))
  1531. return tport;
  1532. }
  1533. return NULL;
  1534. }
  1535. static void
  1536. fnic_fdmi_attr_set(void *attr_start, u16 type, u16 len,
  1537. void *data, u32 *off)
  1538. {
  1539. u16 size = len + FC_FDMI_ATTR_ENTRY_HEADER_LEN;
  1540. struct fc_fdmi_attr_entry *fdmi_attr = (struct fc_fdmi_attr_entry *)
  1541. ((u8 *)attr_start + *off);
  1542. put_unaligned_be16(type, &fdmi_attr->type);
  1543. put_unaligned_be16(size, &fdmi_attr->len);
  1544. memcpy(fdmi_attr->value, data, len);
  1545. *off += size;
  1546. }
  1547. static void fdls_fdmi_register_hba(struct fnic_iport_s *iport)
  1548. {
  1549. uint8_t *frame;
  1550. struct fc_std_fdmi_rhba *prhba;
  1551. struct fc_fdmi_attr_entry *fdmi_attr;
  1552. uint8_t fcid[3];
  1553. int err;
  1554. struct fnic *fnic = iport->fnic;
  1555. struct vnic_devcmd_fw_info *fw_info = NULL;
  1556. uint16_t oxid;
  1557. u32 attr_off_bytes, len;
  1558. u8 data[64];
  1559. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET;
  1560. frame = fdls_alloc_frame(iport);
  1561. if (frame == NULL) {
  1562. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1563. "Failed to allocate frame to send FDMI RHBA");
  1564. return;
  1565. }
  1566. prhba = (struct fc_std_fdmi_rhba *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1567. *prhba = (struct fc_std_fdmi_rhba) {
  1568. .fchdr = {
  1569. .fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
  1570. .fh_d_id = {0xFF, 0XFF, 0XFA},
  1571. .fh_type = FC_TYPE_CT,
  1572. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  1573. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)
  1574. },
  1575. .fc_std_ct_hdr = {
  1576. .ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_MGMT,
  1577. .ct_fs_subtype = FC_FDMI_SUBTYPE,
  1578. .ct_cmd = cpu_to_be16(FC_FDMI_RHBA)
  1579. },
  1580. };
  1581. hton24(fcid, iport->fcid);
  1582. FNIC_STD_SET_S_ID(prhba->fchdr, fcid);
  1583. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_RHBA,
  1584. &iport->active_oxid_fdmi_rhba);
  1585. if (oxid == FNIC_UNASSIGNED_OXID) {
  1586. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1587. "0x%x: Failed to allocate OXID to send FDMI RHBA",
  1588. iport->fcid);
  1589. mempool_free(frame, fnic->frame_pool);
  1590. return;
  1591. }
  1592. FNIC_STD_SET_OX_ID(prhba->fchdr, oxid);
  1593. put_unaligned_be64(iport->wwpn, &prhba->rhba.hbaid.id);
  1594. put_unaligned_be32(FNIC_FDMI_NUM_PORTS, &prhba->rhba.port.numport);
  1595. put_unaligned_be64(iport->wwpn, &prhba->rhba.port.port[0].portname);
  1596. put_unaligned_be32(FNIC_FDMI_NUM_HBA_ATTRS,
  1597. &prhba->rhba.hba_attrs.numattrs);
  1598. fdmi_attr = prhba->rhba.hba_attrs.attr;
  1599. attr_off_bytes = 0;
  1600. put_unaligned_be64(iport->wwnn, data);
  1601. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_NODE_NAME,
  1602. FNIC_FDMI_NN_LEN, data, &attr_off_bytes);
  1603. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1604. "NN set, off=%d", attr_off_bytes);
  1605. strscpy_pad(data, FNIC_FDMI_MANUFACTURER, FNIC_FDMI_MANU_LEN);
  1606. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MANUFACTURER,
  1607. FNIC_FDMI_MANU_LEN, data, &attr_off_bytes);
  1608. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1609. "MFG set <%s>, off=%d", data, attr_off_bytes);
  1610. err = vnic_dev_fw_info(fnic->vdev, &fw_info);
  1611. if (!err) {
  1612. strscpy_pad(data, fw_info->hw_serial_number,
  1613. FNIC_FDMI_SERIAL_LEN);
  1614. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_SERIAL_NUMBER,
  1615. FNIC_FDMI_SERIAL_LEN, data, &attr_off_bytes);
  1616. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1617. "SERIAL set <%s>, off=%d", data, attr_off_bytes);
  1618. }
  1619. if (fnic->subsys_desc_len >= FNIC_FDMI_MODEL_LEN)
  1620. fnic->subsys_desc_len = FNIC_FDMI_MODEL_LEN - 1;
  1621. strscpy_pad(data, fnic->subsys_desc, FNIC_FDMI_MODEL_LEN);
  1622. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MODEL, FNIC_FDMI_MODEL_LEN,
  1623. data, &attr_off_bytes);
  1624. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1625. "MODEL set <%s>, off=%d", data, attr_off_bytes);
  1626. strscpy_pad(data, FNIC_FDMI_MODEL_DESCRIPTION, FNIC_FDMI_MODEL_DES_LEN);
  1627. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MODEL_DES,
  1628. FNIC_FDMI_MODEL_DES_LEN, data, &attr_off_bytes);
  1629. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1630. "MODEL_DESC set <%s>, off=%d", data, attr_off_bytes);
  1631. if (!err) {
  1632. strscpy_pad(data, fw_info->hw_version, FNIC_FDMI_HW_VER_LEN);
  1633. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_HARDWARE_VERSION,
  1634. FNIC_FDMI_HW_VER_LEN, data, &attr_off_bytes);
  1635. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1636. "HW_VER set <%s>, off=%d", data, attr_off_bytes);
  1637. }
  1638. strscpy_pad(data, DRV_VERSION, FNIC_FDMI_DR_VER_LEN);
  1639. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_DRIVER_VERSION,
  1640. FNIC_FDMI_DR_VER_LEN, data, &attr_off_bytes);
  1641. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1642. "DRV_VER set <%s>, off=%d", data, attr_off_bytes);
  1643. strscpy_pad(data, "N/A", FNIC_FDMI_ROM_VER_LEN);
  1644. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_ROM_VERSION,
  1645. FNIC_FDMI_ROM_VER_LEN, data, &attr_off_bytes);
  1646. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1647. "ROM_VER set <%s>, off=%d", data, attr_off_bytes);
  1648. if (!err) {
  1649. strscpy_pad(data, fw_info->fw_version, FNIC_FDMI_FW_VER_LEN);
  1650. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_FIRMWARE_VERSION,
  1651. FNIC_FDMI_FW_VER_LEN, data, &attr_off_bytes);
  1652. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1653. "FW_VER set <%s>, off=%d", data, attr_off_bytes);
  1654. }
  1655. len = sizeof(struct fc_std_fdmi_rhba) + attr_off_bytes;
  1656. frame_size += len;
  1657. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1658. "0x%x: FDLS send FDMI RHBA with oxid: 0x%x fs: %d", iport->fcid,
  1659. oxid, frame_size);
  1660. fnic_send_fcoe_frame(iport, frame, frame_size);
  1661. iport->fabric.fdmi_pending |= FDLS_FDMI_REG_HBA_PENDING;
  1662. }
  1663. static void fdls_fdmi_register_pa(struct fnic_iport_s *iport)
  1664. {
  1665. uint8_t *frame;
  1666. struct fc_std_fdmi_rpa *prpa;
  1667. struct fc_fdmi_attr_entry *fdmi_attr;
  1668. uint8_t fcid[3];
  1669. struct fnic *fnic = iport->fnic;
  1670. u32 port_speed_bm;
  1671. u32 port_speed = vnic_dev_port_speed(fnic->vdev);
  1672. uint16_t oxid;
  1673. u32 attr_off_bytes, len;
  1674. u8 tmp_data[16], data[64];
  1675. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET;
  1676. frame = fdls_alloc_frame(iport);
  1677. if (frame == NULL) {
  1678. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  1679. "Failed to allocate frame to send FDMI RPA");
  1680. return;
  1681. }
  1682. prpa = (struct fc_std_fdmi_rpa *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  1683. *prpa = (struct fc_std_fdmi_rpa) {
  1684. .fchdr = {
  1685. .fh_r_ctl = FC_RCTL_DD_UNSOL_CTL,
  1686. .fh_d_id = {0xFF, 0xFF, 0xFA},
  1687. .fh_type = FC_TYPE_CT,
  1688. .fh_f_ctl = {FNIC_ELS_REQ_FCTL, 0, 0},
  1689. .fh_rx_id = cpu_to_be16(FNIC_UNASSIGNED_RXID)
  1690. },
  1691. .fc_std_ct_hdr = {
  1692. .ct_rev = FC_CT_REV, .ct_fs_type = FC_FST_MGMT,
  1693. .ct_fs_subtype = FC_FDMI_SUBTYPE,
  1694. .ct_cmd = cpu_to_be16(FC_FDMI_RPA)
  1695. },
  1696. };
  1697. hton24(fcid, iport->fcid);
  1698. FNIC_STD_SET_S_ID(prpa->fchdr, fcid);
  1699. oxid = fdls_alloc_oxid(iport, FNIC_FRAME_TYPE_FDMI_RPA,
  1700. &iport->active_oxid_fdmi_rpa);
  1701. if (oxid == FNIC_UNASSIGNED_OXID) {
  1702. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1703. "0x%x: Failed to allocate OXID to send FDMI RPA",
  1704. iport->fcid);
  1705. mempool_free(frame, fnic->frame_pool);
  1706. return;
  1707. }
  1708. FNIC_STD_SET_OX_ID(prpa->fchdr, oxid);
  1709. put_unaligned_be64(iport->wwpn, &prpa->rpa.port.portname);
  1710. put_unaligned_be32(FNIC_FDMI_NUM_PORT_ATTRS,
  1711. &prpa->rpa.hba_attrs.numattrs);
  1712. /* MDS does not support GIGE speed.
  1713. * Bit shift standard definitions from scsi_transport_fc.h to
  1714. * match FC spec.
  1715. */
  1716. switch (port_speed) {
  1717. case DCEM_PORTSPEED_10G:
  1718. case DCEM_PORTSPEED_20G:
  1719. /* There is no bit for 20G */
  1720. port_speed_bm = FC_PORTSPEED_10GBIT << PORT_SPEED_BIT_14;
  1721. break;
  1722. case DCEM_PORTSPEED_25G:
  1723. port_speed_bm = FC_PORTSPEED_25GBIT << PORT_SPEED_BIT_8;
  1724. break;
  1725. case DCEM_PORTSPEED_40G:
  1726. case DCEM_PORTSPEED_4x10G:
  1727. port_speed_bm = FC_PORTSPEED_40GBIT << PORT_SPEED_BIT_9;
  1728. break;
  1729. case DCEM_PORTSPEED_100G:
  1730. port_speed_bm = FC_PORTSPEED_100GBIT << PORT_SPEED_BIT_8;
  1731. break;
  1732. default:
  1733. port_speed_bm = FC_PORTSPEED_1GBIT << PORT_SPEED_BIT_15;
  1734. break;
  1735. }
  1736. attr_off_bytes = 0;
  1737. fdmi_attr = prpa->rpa.hba_attrs.attr;
  1738. put_unaligned_be64(iport->wwnn, data);
  1739. memset(data, 0, FNIC_FDMI_FC4_LEN);
  1740. data[2] = 1;
  1741. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_FC4_TYPES,
  1742. FNIC_FDMI_FC4_LEN, data, &attr_off_bytes);
  1743. put_unaligned_be32(port_speed_bm, data);
  1744. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_SUPPORTED_SPEEDS,
  1745. FNIC_FDMI_SUPP_SPEED_LEN, data, &attr_off_bytes);
  1746. put_unaligned_be32(port_speed_bm, data);
  1747. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_CURRENT_SPEED,
  1748. FNIC_FDMI_CUR_SPEED_LEN, data, &attr_off_bytes);
  1749. put_unaligned_be32(FNIC_FDMI_MFS, data);
  1750. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_MAX_FRAME_SIZE,
  1751. FNIC_FDMI_MFS_LEN, data, &attr_off_bytes);
  1752. snprintf(tmp_data, FNIC_FDMI_OS_NAME_LEN - 1, "host%d",
  1753. fnic->host->host_no);
  1754. strscpy_pad(data, tmp_data, FNIC_FDMI_OS_NAME_LEN);
  1755. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_OS_NAME,
  1756. FNIC_FDMI_OS_NAME_LEN, data, &attr_off_bytes);
  1757. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1758. "OS name set <%s>, off=%d", data, attr_off_bytes);
  1759. sprintf(fc_host_system_hostname(fnic->host), "%s", utsname()->nodename);
  1760. strscpy_pad(data, fc_host_system_hostname(fnic->host),
  1761. FNIC_FDMI_HN_LEN);
  1762. fnic_fdmi_attr_set(fdmi_attr, FNIC_FDMI_TYPE_HOST_NAME,
  1763. FNIC_FDMI_HN_LEN, data, &attr_off_bytes);
  1764. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1765. "Host name set <%s>, off=%d", data, attr_off_bytes);
  1766. len = sizeof(struct fc_std_fdmi_rpa) + attr_off_bytes;
  1767. frame_size += len;
  1768. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1769. "0x%x: FDLS send FDMI RPA with oxid: 0x%x fs: %d", iport->fcid,
  1770. oxid, frame_size);
  1771. fnic_send_fcoe_frame(iport, frame, frame_size);
  1772. iport->fabric.fdmi_pending |= FDLS_FDMI_RPA_PENDING;
  1773. }
  1774. void fdls_fabric_timer_callback(struct timer_list *t)
  1775. {
  1776. struct fnic_fdls_fabric_s *fabric = timer_container_of(fabric, t,
  1777. retry_timer);
  1778. struct fnic_iport_s *iport =
  1779. container_of(fabric, struct fnic_iport_s, fabric);
  1780. struct fnic *fnic = iport->fnic;
  1781. unsigned long flags;
  1782. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1783. "tp: %d fab state: %d fab retry counter: %d max_flogi_retries: %d",
  1784. iport->fabric.timer_pending, iport->fabric.state,
  1785. iport->fabric.retry_counter, iport->max_flogi_retries);
  1786. spin_lock_irqsave(&fnic->fnic_lock, flags);
  1787. if (!iport->fabric.timer_pending) {
  1788. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  1789. return;
  1790. }
  1791. if (iport->fabric.del_timer_inprogress) {
  1792. iport->fabric.del_timer_inprogress = 0;
  1793. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  1794. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1795. "fabric_del_timer inprogress(%d). Skip timer cb",
  1796. iport->fabric.del_timer_inprogress);
  1797. return;
  1798. }
  1799. iport->fabric.timer_pending = 0;
  1800. /* The fabric state indicates which frames have time out, and we retry */
  1801. switch (iport->fabric.state) {
  1802. case FDLS_STATE_FABRIC_FLOGI:
  1803. /* Flogi received a LS_RJT with busy we retry from here */
  1804. if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
  1805. && (iport->fabric.retry_counter < iport->max_flogi_retries)) {
  1806. iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
  1807. fdls_send_fabric_flogi(iport);
  1808. } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
  1809. /* Flogi has time out 2*ed_tov send abts */
  1810. fdls_send_fabric_abts(iport);
  1811. } else {
  1812. /* ABTS has timed out
  1813. * Mark the OXID to be freed after 2 * r_a_tov and retry the req
  1814. */
  1815. fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
  1816. if (iport->fabric.retry_counter < iport->max_flogi_retries) {
  1817. iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
  1818. fdls_send_fabric_flogi(iport);
  1819. } else
  1820. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1821. "Exceeded max FLOGI retries");
  1822. }
  1823. break;
  1824. case FDLS_STATE_FABRIC_PLOGI:
  1825. /* Plogi received a LS_RJT with busy we retry from here */
  1826. if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
  1827. && (iport->fabric.retry_counter < iport->max_plogi_retries)) {
  1828. iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
  1829. fdls_send_fabric_plogi(iport);
  1830. } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
  1831. /* Plogi has timed out 2*ed_tov send abts */
  1832. fdls_send_fabric_abts(iport);
  1833. } else {
  1834. /* ABTS has timed out
  1835. * Mark the OXID to be freed after 2 * r_a_tov and retry the req
  1836. */
  1837. fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
  1838. if (iport->fabric.retry_counter < iport->max_plogi_retries) {
  1839. iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
  1840. fdls_send_fabric_plogi(iport);
  1841. } else
  1842. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1843. "Exceeded max PLOGI retries");
  1844. }
  1845. break;
  1846. case FDLS_STATE_RPN_ID:
  1847. /* Rpn_id received a LS_RJT with busy we retry from here */
  1848. if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
  1849. && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
  1850. iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
  1851. fdls_send_rpn_id(iport);
  1852. } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED))
  1853. /* RPN has timed out. Send abts */
  1854. fdls_send_fabric_abts(iport);
  1855. else {
  1856. /* ABTS has timed out */
  1857. fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
  1858. fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
  1859. }
  1860. break;
  1861. case FDLS_STATE_SCR:
  1862. /* scr received a LS_RJT with busy we retry from here */
  1863. if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
  1864. && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
  1865. iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
  1866. fdls_send_scr(iport);
  1867. } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED))
  1868. /* scr has timed out. Send abts */
  1869. fdls_send_fabric_abts(iport);
  1870. else {
  1871. /* ABTS has timed out */
  1872. fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
  1873. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1874. "ABTS timed out. Starting PLOGI: %p", iport);
  1875. fnic_fdls_start_plogi(iport);
  1876. }
  1877. break;
  1878. case FDLS_STATE_REGISTER_FC4_TYPES:
  1879. /* scr received a LS_RJT with busy we retry from here */
  1880. if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
  1881. && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
  1882. iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
  1883. fdls_send_register_fc4_types(iport);
  1884. } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
  1885. /* RFT_ID timed out send abts */
  1886. fdls_send_fabric_abts(iport);
  1887. } else {
  1888. /* ABTS has timed out */
  1889. fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
  1890. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1891. "ABTS timed out. Starting PLOGI: %p", iport);
  1892. fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
  1893. }
  1894. break;
  1895. case FDLS_STATE_REGISTER_FC4_FEATURES:
  1896. /* scr received a LS_RJT with busy we retry from here */
  1897. if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
  1898. && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
  1899. iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
  1900. fdls_send_register_fc4_features(iport);
  1901. } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED))
  1902. /* SCR has timed out. Send abts */
  1903. fdls_send_fabric_abts(iport);
  1904. else {
  1905. /* ABTS has timed out */
  1906. fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
  1907. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1908. "ABTS timed out. Starting PLOGI %p", iport);
  1909. fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
  1910. }
  1911. break;
  1912. case FDLS_STATE_RSCN_GPN_FT:
  1913. case FDLS_STATE_SEND_GPNFT:
  1914. case FDLS_STATE_GPN_FT:
  1915. /* GPN_FT received a LS_RJT with busy we retry from here */
  1916. if ((iport->fabric.flags & FNIC_FDLS_RETRY_FRAME)
  1917. && (iport->fabric.retry_counter < FDLS_RETRY_COUNT)) {
  1918. iport->fabric.flags &= ~FNIC_FDLS_RETRY_FRAME;
  1919. fdls_send_gpn_ft(iport, iport->fabric.state);
  1920. } else if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
  1921. /* gpn_ft has timed out. Send abts */
  1922. fdls_send_fabric_abts(iport);
  1923. } else {
  1924. /* ABTS has timed out */
  1925. fdls_schedule_oxid_free(iport, &iport->active_oxid_fabric_req);
  1926. if (iport->fabric.retry_counter < FDLS_RETRY_COUNT) {
  1927. fdls_send_gpn_ft(iport, iport->fabric.state);
  1928. } else {
  1929. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1930. "ABTS timeout for fabric GPN_FT. Check name server: %p",
  1931. iport);
  1932. }
  1933. }
  1934. break;
  1935. default:
  1936. break;
  1937. }
  1938. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  1939. }
  1940. void fdls_fdmi_retry_plogi(struct fnic_iport_s *iport)
  1941. {
  1942. struct fnic *fnic = iport->fnic;
  1943. iport->fabric.fdmi_pending = 0;
  1944. /* If max retries not exhausted, start over from fdmi plogi */
  1945. if (iport->fabric.fdmi_retry < FDLS_FDMI_MAX_RETRY) {
  1946. iport->fabric.fdmi_retry++;
  1947. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1948. "Retry FDMI PLOGI. FDMI retry: %d",
  1949. iport->fabric.fdmi_retry);
  1950. fdls_send_fdmi_plogi(iport);
  1951. }
  1952. }
  1953. void fdls_fdmi_timer_callback(struct timer_list *t)
  1954. {
  1955. struct fnic_fdls_fabric_s *fabric = timer_container_of(fabric, t,
  1956. fdmi_timer);
  1957. struct fnic_iport_s *iport =
  1958. container_of(fabric, struct fnic_iport_s, fabric);
  1959. struct fnic *fnic = iport->fnic;
  1960. unsigned long flags;
  1961. spin_lock_irqsave(&fnic->fnic_lock, flags);
  1962. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1963. "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending);
  1964. if (!iport->fabric.fdmi_pending) {
  1965. /* timer expired after fdmi responses received. */
  1966. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  1967. return;
  1968. }
  1969. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1970. "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending);
  1971. /* if not abort pending, send an abort */
  1972. if (!(iport->fabric.fdmi_pending & FDLS_FDMI_ABORT_PENDING)) {
  1973. fdls_send_fdmi_abts(iport);
  1974. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  1975. return;
  1976. }
  1977. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1978. "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending);
  1979. /* ABTS pending for an active fdmi request that is pending.
  1980. * That means FDMI ABTS timed out
  1981. * Schedule to free the OXID after 2*r_a_tov and proceed
  1982. */
  1983. if (iport->fabric.fdmi_pending & FDLS_FDMI_PLOGI_PENDING) {
  1984. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1985. "FDMI PLOGI ABTS timed out. Schedule oxid free: 0x%x\n",
  1986. iport->active_oxid_fdmi_plogi);
  1987. fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_plogi);
  1988. } else {
  1989. if (iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING) {
  1990. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1991. "FDMI RHBA ABTS timed out. Schedule oxid free: 0x%x\n",
  1992. iport->active_oxid_fdmi_rhba);
  1993. fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_rhba);
  1994. }
  1995. if (iport->fabric.fdmi_pending & FDLS_FDMI_RPA_PENDING) {
  1996. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  1997. "FDMI RPA ABTS timed out. Schedule oxid free: 0x%x\n",
  1998. iport->active_oxid_fdmi_rpa);
  1999. fdls_schedule_oxid_free(iport, &iport->active_oxid_fdmi_rpa);
  2000. }
  2001. }
  2002. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2003. "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending);
  2004. fdls_fdmi_retry_plogi(iport);
  2005. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2006. "iport->fabric.fdmi_pending: 0x%x\n", iport->fabric.fdmi_pending);
  2007. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  2008. }
  2009. static void fdls_send_delete_tport_msg(struct fnic_tport_s *tport)
  2010. {
  2011. struct fnic_iport_s *iport = (struct fnic_iport_s *) tport->iport;
  2012. struct fnic *fnic = iport->fnic;
  2013. struct fnic_tport_event_s *tport_del_evt;
  2014. tport_del_evt = kzalloc_obj(struct fnic_tport_event_s, GFP_ATOMIC);
  2015. if (!tport_del_evt) {
  2016. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2017. "Failed to allocate memory for tport event fcid: 0x%x",
  2018. tport->fcid);
  2019. return;
  2020. }
  2021. tport_del_evt->event = TGT_EV_TPORT_DELETE;
  2022. tport_del_evt->arg1 = (void *) tport;
  2023. list_add_tail(&tport_del_evt->links, &fnic->tport_event_list);
  2024. queue_work(fnic_event_queue, &fnic->tport_work);
  2025. }
  2026. static void fdls_tport_timer_callback(struct timer_list *t)
  2027. {
  2028. struct fnic_tport_s *tport = timer_container_of(tport, t, retry_timer);
  2029. struct fnic_iport_s *iport = (struct fnic_iport_s *) tport->iport;
  2030. struct fnic *fnic = iport->fnic;
  2031. uint16_t oxid;
  2032. unsigned long flags;
  2033. spin_lock_irqsave(&fnic->fnic_lock, flags);
  2034. if (!tport->timer_pending) {
  2035. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  2036. return;
  2037. }
  2038. if (iport->state != FNIC_IPORT_STATE_READY) {
  2039. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  2040. return;
  2041. }
  2042. if (tport->del_timer_inprogress) {
  2043. tport->del_timer_inprogress = 0;
  2044. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  2045. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2046. "tport_del_timer inprogress. Skip timer cb tport fcid: 0x%x\n",
  2047. tport->fcid);
  2048. return;
  2049. }
  2050. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2051. "tport fcid: 0x%x timer pending: %d state: %d retry counter: %d",
  2052. tport->fcid, tport->timer_pending, tport->state,
  2053. tport->retry_counter);
  2054. tport->timer_pending = 0;
  2055. oxid = tport->active_oxid;
  2056. /* We retry plogi/prli/adisc frames depending on the tport state */
  2057. switch (tport->state) {
  2058. case FDLS_TGT_STATE_PLOGI:
  2059. /* PLOGI frame received a LS_RJT with busy, we retry from here */
  2060. if ((tport->flags & FNIC_FDLS_RETRY_FRAME)
  2061. && (tport->retry_counter < iport->max_plogi_retries)) {
  2062. tport->flags &= ~FNIC_FDLS_RETRY_FRAME;
  2063. fdls_send_tgt_plogi(iport, tport);
  2064. } else if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
  2065. /* Plogi frame has timed out, send abts */
  2066. fdls_send_tport_abts(iport, tport);
  2067. } else if (tport->retry_counter < iport->max_plogi_retries) {
  2068. /*
  2069. * ABTS has timed out
  2070. */
  2071. fdls_schedule_oxid_free(iport, &tport->active_oxid);
  2072. fdls_send_tgt_plogi(iport, tport);
  2073. } else {
  2074. /* exceeded plogi retry count */
  2075. fdls_schedule_oxid_free(iport, &tport->active_oxid);
  2076. fdls_send_delete_tport_msg(tport);
  2077. }
  2078. break;
  2079. case FDLS_TGT_STATE_PRLI:
  2080. /* PRLI received a LS_RJT with busy , hence we retry from here */
  2081. if ((tport->flags & FNIC_FDLS_RETRY_FRAME)
  2082. && (tport->retry_counter < FDLS_RETRY_COUNT)) {
  2083. tport->flags &= ~FNIC_FDLS_RETRY_FRAME;
  2084. fdls_send_tgt_prli(iport, tport);
  2085. } else if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
  2086. /* PRLI has time out, send abts */
  2087. fdls_send_tport_abts(iport, tport);
  2088. } else {
  2089. /* ABTS has timed out for prli, we go back to PLOGI */
  2090. fdls_schedule_oxid_free(iport, &tport->active_oxid);
  2091. fdls_send_tgt_plogi(iport, tport);
  2092. fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI);
  2093. }
  2094. break;
  2095. case FDLS_TGT_STATE_ADISC:
  2096. /* ADISC timed out send an ABTS */
  2097. if (!(tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
  2098. fdls_send_tport_abts(iport, tport);
  2099. } else if ((tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)
  2100. && (tport->retry_counter < FDLS_RETRY_COUNT)) {
  2101. /*
  2102. * ABTS has timed out
  2103. */
  2104. fdls_schedule_oxid_free(iport, &tport->active_oxid);
  2105. fdls_send_tgt_adisc(iport, tport);
  2106. } else {
  2107. /* exceeded retry count */
  2108. fdls_schedule_oxid_free(iport, &tport->active_oxid);
  2109. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2110. "ADISC not responding. Deleting target port: 0x%x",
  2111. tport->fcid);
  2112. fdls_send_delete_tport_msg(tport);
  2113. }
  2114. break;
  2115. default:
  2116. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2117. "oxid: 0x%x Unknown tport state: 0x%x", oxid, tport->state);
  2118. break;
  2119. }
  2120. spin_unlock_irqrestore(&fnic->fnic_lock, flags);
  2121. }
  2122. static void fnic_fdls_start_flogi(struct fnic_iport_s *iport)
  2123. {
  2124. iport->fabric.retry_counter = 0;
  2125. fdls_send_fabric_flogi(iport);
  2126. fdls_set_state((&iport->fabric), FDLS_STATE_FABRIC_FLOGI);
  2127. iport->fabric.flags = 0;
  2128. }
  2129. static void fnic_fdls_start_plogi(struct fnic_iport_s *iport)
  2130. {
  2131. iport->fabric.retry_counter = 0;
  2132. fdls_send_fabric_plogi(iport);
  2133. fdls_set_state((&iport->fabric), FDLS_STATE_FABRIC_PLOGI);
  2134. iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
  2135. if ((fnic_fdmi_support == 1) && (!(iport->flags & FNIC_FDMI_ACTIVE))) {
  2136. /* we can do FDMI at the same time */
  2137. iport->fabric.fdmi_retry = 0;
  2138. timer_setup(&iport->fabric.fdmi_timer, fdls_fdmi_timer_callback,
  2139. 0);
  2140. fdls_send_fdmi_plogi(iport);
  2141. iport->flags |= FNIC_FDMI_ACTIVE;
  2142. }
  2143. }
  2144. static void
  2145. fdls_process_tgt_adisc_rsp(struct fnic_iport_s *iport,
  2146. struct fc_frame_header *fchdr)
  2147. {
  2148. uint32_t tgt_fcid;
  2149. struct fnic_tport_s *tport;
  2150. uint8_t *fcid;
  2151. uint64_t frame_wwnn;
  2152. uint64_t frame_wwpn;
  2153. uint16_t oxid;
  2154. struct fc_std_els_adisc *adisc_rsp = (struct fc_std_els_adisc *)fchdr;
  2155. struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr;
  2156. struct fnic *fnic = iport->fnic;
  2157. fcid = FNIC_STD_GET_S_ID(fchdr);
  2158. tgt_fcid = ntoh24(fcid);
  2159. tport = fnic_find_tport_by_fcid(iport, tgt_fcid);
  2160. if (!tport) {
  2161. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2162. "Tgt ADISC response tport not found: 0x%x", tgt_fcid);
  2163. return;
  2164. }
  2165. if ((iport->state != FNIC_IPORT_STATE_READY)
  2166. || (tport->state != FDLS_TGT_STATE_ADISC)
  2167. || (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
  2168. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2169. "Dropping this ADISC response");
  2170. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2171. "iport state: %d tport state: %d Is abort issued on PRLI? %d",
  2172. iport->state, tport->state,
  2173. (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED));
  2174. return;
  2175. }
  2176. if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) {
  2177. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2178. "Dropping frame from target: 0x%x",
  2179. tgt_fcid);
  2180. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2181. "Reason: Stale ADISC/Aborted ADISC/OOO frame delivery");
  2182. return;
  2183. }
  2184. oxid = FNIC_STD_GET_OX_ID(fchdr);
  2185. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  2186. switch (adisc_rsp->els.adisc_cmd) {
  2187. case ELS_LS_ACC:
  2188. atomic64_inc(&iport->iport_stats.tport_adisc_ls_accepts);
  2189. if (tport->timer_pending) {
  2190. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2191. "tport 0x%p Canceling fabric disc timer\n",
  2192. tport);
  2193. fnic_del_tport_timer_sync(fnic, tport);
  2194. }
  2195. tport->timer_pending = 0;
  2196. tport->retry_counter = 0;
  2197. frame_wwnn = get_unaligned_be64(&adisc_rsp->els.adisc_wwnn);
  2198. frame_wwpn = get_unaligned_be64(&adisc_rsp->els.adisc_wwpn);
  2199. if ((frame_wwnn == tport->wwnn) && (frame_wwpn == tport->wwpn)) {
  2200. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2201. "ADISC accepted from target: 0x%x. Target logged in",
  2202. tgt_fcid);
  2203. fdls_set_tport_state(tport, FDLS_TGT_STATE_READY);
  2204. } else {
  2205. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2206. "Error mismatch frame: ADISC");
  2207. }
  2208. break;
  2209. case ELS_LS_RJT:
  2210. atomic64_inc(&iport->iport_stats.tport_adisc_ls_rejects);
  2211. if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
  2212. || (els_rjt->rej.er_reason == ELS_RJT_UNAB))
  2213. && (tport->retry_counter < FDLS_RETRY_COUNT)) {
  2214. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2215. "ADISC ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x",
  2216. tgt_fcid);
  2217. /* Retry ADISC again from the timer routine. */
  2218. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  2219. } else {
  2220. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2221. "ADISC returned ELS_LS_RJT from target: 0x%x",
  2222. tgt_fcid);
  2223. fdls_delete_tport(iport, tport);
  2224. }
  2225. break;
  2226. }
  2227. }
  2228. static void
  2229. fdls_process_tgt_plogi_rsp(struct fnic_iport_s *iport,
  2230. struct fc_frame_header *fchdr)
  2231. {
  2232. uint32_t tgt_fcid;
  2233. struct fnic_tport_s *tport;
  2234. uint8_t *fcid;
  2235. uint16_t oxid;
  2236. struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *)fchdr;
  2237. struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr;
  2238. uint16_t max_payload_size;
  2239. struct fnic *fnic = iport->fnic;
  2240. fcid = FNIC_STD_GET_S_ID(fchdr);
  2241. tgt_fcid = ntoh24(fcid);
  2242. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2243. "FDLS processing target PLOGI response: tgt_fcid: 0x%x",
  2244. tgt_fcid);
  2245. tport = fnic_find_tport_by_fcid(iport, tgt_fcid);
  2246. if (!tport) {
  2247. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2248. "tport not found: 0x%x", tgt_fcid);
  2249. return;
  2250. }
  2251. if ((iport->state != FNIC_IPORT_STATE_READY)
  2252. || (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
  2253. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2254. "Dropping frame! iport state: %d tport state: %d",
  2255. iport->state, tport->state);
  2256. return;
  2257. }
  2258. if (tport->state != FDLS_TGT_STATE_PLOGI) {
  2259. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2260. "PLOGI rsp recvd in wrong state. Drop the frame and restart nexus");
  2261. fdls_target_restart_nexus(tport);
  2262. return;
  2263. }
  2264. if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) {
  2265. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2266. "PLOGI response from target: 0x%x. Dropping frame",
  2267. tgt_fcid);
  2268. return;
  2269. }
  2270. oxid = FNIC_STD_GET_OX_ID(fchdr);
  2271. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  2272. switch (plogi_rsp->els.fl_cmd) {
  2273. case ELS_LS_ACC:
  2274. atomic64_inc(&iport->iport_stats.tport_plogi_ls_accepts);
  2275. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2276. "PLOGI accepted by target: 0x%x", tgt_fcid);
  2277. break;
  2278. case ELS_LS_RJT:
  2279. atomic64_inc(&iport->iport_stats.tport_plogi_ls_rejects);
  2280. if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
  2281. || (els_rjt->rej.er_reason == ELS_RJT_UNAB))
  2282. && (tport->retry_counter < iport->max_plogi_retries)) {
  2283. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2284. "PLOGI ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x",
  2285. tgt_fcid);
  2286. /* Retry plogi again from the timer routine. */
  2287. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  2288. return;
  2289. }
  2290. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2291. "PLOGI returned ELS_LS_RJT from target: 0x%x",
  2292. tgt_fcid);
  2293. fdls_delete_tport(iport, tport);
  2294. return;
  2295. default:
  2296. atomic64_inc(&iport->iport_stats.tport_plogi_misc_rejects);
  2297. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2298. "PLOGI not accepted from target fcid: 0x%x",
  2299. tgt_fcid);
  2300. return;
  2301. }
  2302. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2303. "Found the PLOGI target: 0x%x and state: %d",
  2304. (unsigned int) tgt_fcid, tport->state);
  2305. if (tport->timer_pending) {
  2306. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2307. "tport fcid 0x%x: Canceling disc timer\n",
  2308. tport->fcid);
  2309. fnic_del_tport_timer_sync(fnic, tport);
  2310. }
  2311. tport->timer_pending = 0;
  2312. tport->wwpn = get_unaligned_be64(&FNIC_LOGI_PORT_NAME(plogi_rsp->els));
  2313. tport->wwnn = get_unaligned_be64(&FNIC_LOGI_NODE_NAME(plogi_rsp->els));
  2314. /* Learn the Service Params */
  2315. /* Max frame size - choose the lowest */
  2316. max_payload_size = fnic_fc_plogi_rsp_rdf(iport, plogi_rsp);
  2317. tport->max_payload_size =
  2318. min(max_payload_size, iport->max_payload_size);
  2319. if (tport->max_payload_size < FNIC_MIN_DATA_FIELD_SIZE) {
  2320. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2321. "MFS: tport max frame size below spec bounds: %d",
  2322. tport->max_payload_size);
  2323. tport->max_payload_size = FNIC_MIN_DATA_FIELD_SIZE;
  2324. }
  2325. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2326. "MAX frame size: %u iport max_payload_size: %d tport mfs: %d",
  2327. max_payload_size, iport->max_payload_size,
  2328. tport->max_payload_size);
  2329. tport->max_concur_seqs = FNIC_FC_PLOGI_RSP_CONCUR_SEQ(plogi_rsp);
  2330. tport->retry_counter = 0;
  2331. fdls_set_tport_state(tport, FDLS_TGT_STATE_PRLI);
  2332. fdls_send_tgt_prli(iport, tport);
  2333. }
  2334. static void
  2335. fdls_process_tgt_prli_rsp(struct fnic_iport_s *iport,
  2336. struct fc_frame_header *fchdr)
  2337. {
  2338. uint32_t tgt_fcid;
  2339. struct fnic_tport_s *tport;
  2340. uint8_t *fcid;
  2341. uint16_t oxid;
  2342. struct fc_std_els_prli *prli_rsp = (struct fc_std_els_prli *)fchdr;
  2343. struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr;
  2344. struct fnic_tport_event_s *tport_add_evt;
  2345. struct fnic *fnic = iport->fnic;
  2346. bool mismatched_tgt = false;
  2347. fcid = FNIC_STD_GET_S_ID(fchdr);
  2348. tgt_fcid = ntoh24(fcid);
  2349. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2350. "FDLS process tgt PRLI response: 0x%x", tgt_fcid);
  2351. tport = fnic_find_tport_by_fcid(iport, tgt_fcid);
  2352. if (!tport) {
  2353. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2354. "tport not found: 0x%x", tgt_fcid);
  2355. /* Handle or just drop? */
  2356. return;
  2357. }
  2358. if ((iport->state != FNIC_IPORT_STATE_READY)
  2359. || (tport->flags & FNIC_FDLS_TGT_ABORT_ISSUED)) {
  2360. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2361. "Dropping frame! iport st: %d tport st: %d tport fcid: 0x%x",
  2362. iport->state, tport->state, tport->fcid);
  2363. return;
  2364. }
  2365. if (tport->state != FDLS_TGT_STATE_PRLI) {
  2366. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2367. "PRLI rsp recvd in wrong state. Drop frame. Restarting nexus");
  2368. fdls_target_restart_nexus(tport);
  2369. return;
  2370. }
  2371. if (FNIC_STD_GET_OX_ID(fchdr) != tport->active_oxid) {
  2372. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2373. "Dropping PRLI response from target: 0x%x ",
  2374. tgt_fcid);
  2375. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2376. "Reason: Stale PRLI response/Aborted PDISC/OOO frame delivery");
  2377. return;
  2378. }
  2379. oxid = FNIC_STD_GET_OX_ID(fchdr);
  2380. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  2381. switch (prli_rsp->els_prli.prli_cmd) {
  2382. case ELS_LS_ACC:
  2383. atomic64_inc(&iport->iport_stats.tport_prli_ls_accepts);
  2384. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2385. "PRLI accepted from target: 0x%x", tgt_fcid);
  2386. if (prli_rsp->sp.spp_type != FC_FC4_TYPE_SCSI) {
  2387. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2388. "mismatched target zoned with FC SCSI initiator: 0x%x",
  2389. tgt_fcid);
  2390. mismatched_tgt = true;
  2391. }
  2392. if (mismatched_tgt) {
  2393. fdls_tgt_logout(iport, tport);
  2394. fdls_delete_tport(iport, tport);
  2395. return;
  2396. }
  2397. break;
  2398. case ELS_LS_RJT:
  2399. atomic64_inc(&iport->iport_stats.tport_prli_ls_rejects);
  2400. if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
  2401. || (els_rjt->rej.er_reason == ELS_RJT_UNAB))
  2402. && (tport->retry_counter < FDLS_RETRY_COUNT)) {
  2403. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2404. "PRLI ret ELS_LS_RJT BUSY. Retry from timer routine: 0x%x",
  2405. tgt_fcid);
  2406. /*Retry Plogi again from the timer routine. */
  2407. tport->flags |= FNIC_FDLS_RETRY_FRAME;
  2408. return;
  2409. }
  2410. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2411. "PRLI returned ELS_LS_RJT from target: 0x%x",
  2412. tgt_fcid);
  2413. fdls_tgt_logout(iport, tport);
  2414. fdls_delete_tport(iport, tport);
  2415. return;
  2416. default:
  2417. atomic64_inc(&iport->iport_stats.tport_prli_misc_rejects);
  2418. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2419. "PRLI not accepted from target: 0x%x", tgt_fcid);
  2420. return;
  2421. }
  2422. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2423. "Found the PRLI target: 0x%x and state: %d",
  2424. (unsigned int) tgt_fcid, tport->state);
  2425. if (tport->timer_pending) {
  2426. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2427. "tport fcid 0x%x: Canceling disc timer\n",
  2428. tport->fcid);
  2429. fnic_del_tport_timer_sync(fnic, tport);
  2430. }
  2431. tport->timer_pending = 0;
  2432. /* Learn Service Params */
  2433. tport->fcp_csp = be32_to_cpu(prli_rsp->sp.spp_params);
  2434. tport->retry_counter = 0;
  2435. if (tport->fcp_csp & FCP_SPPF_RETRY)
  2436. tport->tgt_flags |= FNIC_FC_RP_FLAGS_RETRY;
  2437. /* Check if the device plays Target Mode Function */
  2438. if (!(tport->fcp_csp & FCP_PRLI_FUNC_TARGET)) {
  2439. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2440. "Remote port(0x%x): no target support. Deleting it\n",
  2441. tgt_fcid);
  2442. fdls_tgt_logout(iport, tport);
  2443. fdls_delete_tport(iport, tport);
  2444. return;
  2445. }
  2446. fdls_set_tport_state(tport, FDLS_TGT_STATE_READY);
  2447. /* Inform the driver about new target added */
  2448. tport_add_evt = kzalloc_obj(struct fnic_tport_event_s, GFP_ATOMIC);
  2449. if (!tport_add_evt) {
  2450. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2451. "tport event memory allocation failure: 0x%0x\n",
  2452. tport->fcid);
  2453. return;
  2454. }
  2455. tport_add_evt->event = TGT_EV_RPORT_ADD;
  2456. tport_add_evt->arg1 = (void *) tport;
  2457. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2458. "iport fcid: 0x%x add tport event fcid: 0x%x\n",
  2459. tport->fcid, iport->fcid);
  2460. list_add_tail(&tport_add_evt->links, &fnic->tport_event_list);
  2461. queue_work(fnic_event_queue, &fnic->tport_work);
  2462. }
  2463. static void
  2464. fdls_process_rff_id_rsp(struct fnic_iport_s *iport,
  2465. struct fc_frame_header *fchdr)
  2466. {
  2467. struct fnic *fnic = iport->fnic;
  2468. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  2469. struct fc_std_rff_id *rff_rsp = (struct fc_std_rff_id *) fchdr;
  2470. uint16_t rsp;
  2471. uint8_t reason_code;
  2472. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  2473. if (fdls_get_state(fdls) != FDLS_STATE_REGISTER_FC4_FEATURES) {
  2474. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2475. "RFF_ID resp recvd in state(%d). Dropping.",
  2476. fdls_get_state(fdls));
  2477. return;
  2478. }
  2479. if (iport->active_oxid_fabric_req != oxid) {
  2480. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2481. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  2482. fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
  2483. return;
  2484. }
  2485. rsp = FNIC_STD_GET_FC_CT_CMD((&rff_rsp->fc_std_ct_hdr));
  2486. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2487. "0x%x: FDLS process RFF ID response: 0x%04x", iport->fcid,
  2488. (uint32_t) rsp);
  2489. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  2490. switch (rsp) {
  2491. case FC_FS_ACC:
  2492. if (iport->fabric.timer_pending) {
  2493. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2494. "Canceling fabric disc timer %p\n", iport);
  2495. fnic_del_fabric_timer_sync(fnic);
  2496. }
  2497. iport->fabric.timer_pending = 0;
  2498. fdls->retry_counter = 0;
  2499. fdls_set_state((&iport->fabric), FDLS_STATE_SCR);
  2500. fdls_send_scr(iport);
  2501. break;
  2502. case FC_FS_RJT:
  2503. reason_code = rff_rsp->fc_std_ct_hdr.ct_reason;
  2504. if (((reason_code == FC_FS_RJT_BSY)
  2505. || (reason_code == FC_FS_RJT_UNABL))
  2506. && (fdls->retry_counter < FDLS_RETRY_COUNT)) {
  2507. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2508. "RFF_ID ret ELS_LS_RJT BUSY. Retry from timer routine %p",
  2509. iport);
  2510. /* Retry again from the timer routine */
  2511. fdls->flags |= FNIC_FDLS_RETRY_FRAME;
  2512. } else {
  2513. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2514. "RFF_ID returned ELS_LS_RJT. Halting discovery %p",
  2515. iport);
  2516. if (iport->fabric.timer_pending) {
  2517. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2518. "Canceling fabric disc timer %p\n", iport);
  2519. fnic_del_fabric_timer_sync(fnic);
  2520. }
  2521. fdls->timer_pending = 0;
  2522. fdls->retry_counter = 0;
  2523. }
  2524. break;
  2525. default:
  2526. break;
  2527. }
  2528. }
  2529. static void
  2530. fdls_process_rft_id_rsp(struct fnic_iport_s *iport,
  2531. struct fc_frame_header *fchdr)
  2532. {
  2533. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  2534. struct fc_std_rft_id *rft_rsp = (struct fc_std_rft_id *) fchdr;
  2535. uint16_t rsp;
  2536. uint8_t reason_code;
  2537. struct fnic *fnic = iport->fnic;
  2538. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  2539. if (fdls_get_state(fdls) != FDLS_STATE_REGISTER_FC4_TYPES) {
  2540. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2541. "RFT_ID resp recvd in state(%d). Dropping.",
  2542. fdls_get_state(fdls));
  2543. return;
  2544. }
  2545. if (iport->active_oxid_fabric_req != oxid) {
  2546. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2547. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  2548. fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
  2549. return;
  2550. }
  2551. rsp = FNIC_STD_GET_FC_CT_CMD((&rft_rsp->fc_std_ct_hdr));
  2552. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2553. "0x%x: FDLS process RFT ID response: 0x%04x", iport->fcid,
  2554. (uint32_t) rsp);
  2555. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  2556. switch (rsp) {
  2557. case FC_FS_ACC:
  2558. if (iport->fabric.timer_pending) {
  2559. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2560. "Canceling fabric disc timer %p\n", iport);
  2561. fnic_del_fabric_timer_sync(fnic);
  2562. }
  2563. iport->fabric.timer_pending = 0;
  2564. fdls->retry_counter = 0;
  2565. fdls_send_register_fc4_features(iport);
  2566. fdls_set_state((&iport->fabric), FDLS_STATE_REGISTER_FC4_FEATURES);
  2567. break;
  2568. case FC_FS_RJT:
  2569. reason_code = rft_rsp->fc_std_ct_hdr.ct_reason;
  2570. if (((reason_code == FC_FS_RJT_BSY)
  2571. || (reason_code == FC_FS_RJT_UNABL))
  2572. && (fdls->retry_counter < FDLS_RETRY_COUNT)) {
  2573. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2574. "0x%x: RFT_ID ret ELS_LS_RJT BUSY. Retry from timer routine",
  2575. iport->fcid);
  2576. /* Retry again from the timer routine */
  2577. fdls->flags |= FNIC_FDLS_RETRY_FRAME;
  2578. } else {
  2579. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2580. "0x%x: RFT_ID REJ. Halting discovery reason %d expl %d",
  2581. iport->fcid, reason_code,
  2582. rft_rsp->fc_std_ct_hdr.ct_explan);
  2583. if (iport->fabric.timer_pending) {
  2584. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2585. "Canceling fabric disc timer %p\n", iport);
  2586. fnic_del_fabric_timer_sync(fnic);
  2587. }
  2588. fdls->timer_pending = 0;
  2589. fdls->retry_counter = 0;
  2590. }
  2591. break;
  2592. default:
  2593. break;
  2594. }
  2595. }
  2596. static void
  2597. fdls_process_rpn_id_rsp(struct fnic_iport_s *iport,
  2598. struct fc_frame_header *fchdr)
  2599. {
  2600. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  2601. struct fc_std_rpn_id *rpn_rsp = (struct fc_std_rpn_id *) fchdr;
  2602. uint16_t rsp;
  2603. uint8_t reason_code;
  2604. struct fnic *fnic = iport->fnic;
  2605. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  2606. if (fdls_get_state(fdls) != FDLS_STATE_RPN_ID) {
  2607. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2608. "RPN_ID resp recvd in state(%d). Dropping.",
  2609. fdls_get_state(fdls));
  2610. return;
  2611. }
  2612. if (iport->active_oxid_fabric_req != oxid) {
  2613. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2614. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  2615. fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
  2616. return;
  2617. }
  2618. rsp = FNIC_STD_GET_FC_CT_CMD((&rpn_rsp->fc_std_ct_hdr));
  2619. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2620. "0x%x: FDLS process RPN ID response: 0x%04x", iport->fcid,
  2621. (uint32_t) rsp);
  2622. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  2623. switch (rsp) {
  2624. case FC_FS_ACC:
  2625. if (iport->fabric.timer_pending) {
  2626. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2627. "Canceling fabric disc timer %p\n", iport);
  2628. fnic_del_fabric_timer_sync(fnic);
  2629. }
  2630. iport->fabric.timer_pending = 0;
  2631. fdls->retry_counter = 0;
  2632. fdls_send_register_fc4_types(iport);
  2633. fdls_set_state((&iport->fabric), FDLS_STATE_REGISTER_FC4_TYPES);
  2634. break;
  2635. case FC_FS_RJT:
  2636. reason_code = rpn_rsp->fc_std_ct_hdr.ct_reason;
  2637. if (((reason_code == FC_FS_RJT_BSY)
  2638. || (reason_code == FC_FS_RJT_UNABL))
  2639. && (fdls->retry_counter < FDLS_RETRY_COUNT)) {
  2640. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2641. "RPN_ID returned REJ BUSY. Retry from timer routine %p",
  2642. iport);
  2643. /* Retry again from the timer routine */
  2644. fdls->flags |= FNIC_FDLS_RETRY_FRAME;
  2645. } else {
  2646. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2647. "RPN_ID ELS_LS_RJT. Halting discovery %p", iport);
  2648. if (iport->fabric.timer_pending) {
  2649. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2650. "Canceling fabric disc timer %p\n", iport);
  2651. fnic_del_fabric_timer_sync(fnic);
  2652. }
  2653. fdls->timer_pending = 0;
  2654. fdls->retry_counter = 0;
  2655. }
  2656. break;
  2657. default:
  2658. break;
  2659. }
  2660. }
  2661. static void
  2662. fdls_process_scr_rsp(struct fnic_iport_s *iport,
  2663. struct fc_frame_header *fchdr)
  2664. {
  2665. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  2666. struct fc_std_scr *scr_rsp = (struct fc_std_scr *) fchdr;
  2667. struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *) fchdr;
  2668. struct fnic *fnic = iport->fnic;
  2669. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  2670. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2671. "FDLS process SCR response: 0x%04x",
  2672. (uint32_t) scr_rsp->scr.scr_cmd);
  2673. if (fdls_get_state(fdls) != FDLS_STATE_SCR) {
  2674. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2675. "SCR resp recvd in state(%d). Dropping.",
  2676. fdls_get_state(fdls));
  2677. return;
  2678. }
  2679. if (iport->active_oxid_fabric_req != oxid) {
  2680. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2681. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  2682. fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
  2683. }
  2684. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  2685. switch (scr_rsp->scr.scr_cmd) {
  2686. case ELS_LS_ACC:
  2687. atomic64_inc(&iport->iport_stats.fabric_scr_ls_accepts);
  2688. if (iport->fabric.timer_pending) {
  2689. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2690. "Canceling fabric disc timer %p\n", iport);
  2691. fnic_del_fabric_timer_sync(fnic);
  2692. }
  2693. iport->fabric.timer_pending = 0;
  2694. iport->fabric.retry_counter = 0;
  2695. fdls_send_gpn_ft(iport, FDLS_STATE_GPN_FT);
  2696. break;
  2697. case ELS_LS_RJT:
  2698. atomic64_inc(&iport->iport_stats.fabric_scr_ls_rejects);
  2699. if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
  2700. || (els_rjt->rej.er_reason == ELS_RJT_UNAB))
  2701. && (fdls->retry_counter < FDLS_RETRY_COUNT)) {
  2702. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2703. "SCR ELS_LS_RJT BUSY. Retry from timer routine %p",
  2704. iport);
  2705. /* Retry again from the timer routine */
  2706. fdls->flags |= FNIC_FDLS_RETRY_FRAME;
  2707. } else {
  2708. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2709. "SCR returned ELS_LS_RJT. Halting discovery %p",
  2710. iport);
  2711. if (iport->fabric.timer_pending) {
  2712. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2713. "Canceling fabric disc timer %p\n",
  2714. iport);
  2715. fnic_del_fabric_timer_sync(fnic);
  2716. }
  2717. fdls->timer_pending = 0;
  2718. fdls->retry_counter = 0;
  2719. }
  2720. break;
  2721. default:
  2722. atomic64_inc(&iport->iport_stats.fabric_scr_misc_rejects);
  2723. break;
  2724. }
  2725. }
  2726. static void
  2727. fdls_process_gpn_ft_tgt_list(struct fnic_iport_s *iport,
  2728. struct fc_frame_header *fchdr, int len)
  2729. {
  2730. struct fc_gpn_ft_rsp_iu *gpn_ft_tgt;
  2731. struct fnic_tport_s *tport, *next;
  2732. uint32_t fcid;
  2733. uint64_t wwpn;
  2734. int rem_len = len;
  2735. u32 old_link_down_cnt = iport->fnic->link_down_cnt;
  2736. struct fnic *fnic = iport->fnic;
  2737. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2738. "0x%x: FDLS process GPN_FT tgt list", iport->fcid);
  2739. gpn_ft_tgt =
  2740. (struct fc_gpn_ft_rsp_iu *)((uint8_t *) fchdr +
  2741. sizeof(struct fc_frame_header)
  2742. + sizeof(struct fc_ct_hdr));
  2743. len -= sizeof(struct fc_frame_header) + sizeof(struct fc_ct_hdr);
  2744. while (rem_len > 0) {
  2745. fcid = ntoh24(gpn_ft_tgt->fcid);
  2746. wwpn = be64_to_cpu(gpn_ft_tgt->wwpn);
  2747. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2748. "tport: 0x%x: ctrl:0x%x", fcid, gpn_ft_tgt->ctrl);
  2749. if (fcid == iport->fcid) {
  2750. if (gpn_ft_tgt->ctrl & FC_NS_FID_LAST)
  2751. break;
  2752. gpn_ft_tgt++;
  2753. rem_len -= sizeof(struct fc_gpn_ft_rsp_iu);
  2754. continue;
  2755. }
  2756. tport = fnic_find_tport_by_wwpn(iport, wwpn);
  2757. if (!tport) {
  2758. /*
  2759. * New port registered with the switch or first time query
  2760. */
  2761. tport = fdls_create_tport(iport, fcid, wwpn);
  2762. if (!tport)
  2763. return;
  2764. }
  2765. /*
  2766. * check if this was an existing tport with same fcid
  2767. * but whose wwpn has changed now ,then remove it and
  2768. * create a new one
  2769. */
  2770. if (tport->fcid != fcid) {
  2771. fdls_delete_tport(iport, tport);
  2772. tport = fdls_create_tport(iport, fcid, wwpn);
  2773. if (!tport)
  2774. return;
  2775. }
  2776. /*
  2777. * If this GPN_FT rsp is after RSCN then mark the tports which
  2778. * matches with the new GPN_FT list, if some tport is not
  2779. * found in GPN_FT we went to delete that tport later.
  2780. */
  2781. if (fdls_get_state((&iport->fabric)) == FDLS_STATE_RSCN_GPN_FT)
  2782. tport->flags |= FNIC_FDLS_TPORT_IN_GPN_FT_LIST;
  2783. if (gpn_ft_tgt->ctrl & FC_NS_FID_LAST)
  2784. break;
  2785. gpn_ft_tgt++;
  2786. rem_len -= sizeof(struct fc_gpn_ft_rsp_iu);
  2787. }
  2788. if (rem_len <= 0) {
  2789. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2790. "GPN_FT response: malformed/corrupt frame rxlen: %d remlen: %d",
  2791. len, rem_len);
  2792. }
  2793. /*remove those ports which was not listed in GPN_FT */
  2794. if (fdls_get_state((&iport->fabric)) == FDLS_STATE_RSCN_GPN_FT) {
  2795. list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
  2796. if (!(tport->flags & FNIC_FDLS_TPORT_IN_GPN_FT_LIST)) {
  2797. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2798. "Remove port: 0x%x not found in GPN_FT list",
  2799. tport->fcid);
  2800. fdls_delete_tport(iport, tport);
  2801. } else {
  2802. tport->flags &= ~FNIC_FDLS_TPORT_IN_GPN_FT_LIST;
  2803. }
  2804. if ((old_link_down_cnt != iport->fnic->link_down_cnt)
  2805. || (iport->state != FNIC_IPORT_STATE_READY)) {
  2806. return;
  2807. }
  2808. }
  2809. }
  2810. }
  2811. static void
  2812. fdls_process_gpn_ft_rsp(struct fnic_iport_s *iport,
  2813. struct fc_frame_header *fchdr, int len)
  2814. {
  2815. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  2816. struct fc_std_gpn_ft *gpn_ft_rsp = (struct fc_std_gpn_ft *) fchdr;
  2817. uint16_t rsp;
  2818. uint8_t reason_code;
  2819. int count = 0;
  2820. struct fnic_tport_s *tport, *next;
  2821. u32 old_link_down_cnt = iport->fnic->link_down_cnt;
  2822. struct fnic *fnic = iport->fnic;
  2823. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  2824. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2825. "FDLS process GPN_FT response: iport state: %d len: %d",
  2826. iport->state, len);
  2827. /*
  2828. * GPNFT response :-
  2829. * FDLS_STATE_GPN_FT : GPNFT send after SCR state
  2830. * during fabric discovery(FNIC_IPORT_STATE_FABRIC_DISC)
  2831. * FDLS_STATE_RSCN_GPN_FT : GPNFT send in response to RSCN
  2832. * FDLS_STATE_SEND_GPNFT : GPNFT send after deleting a Target,
  2833. * e.g. after receiving Target LOGO
  2834. * FDLS_STATE_TGT_DISCOVERY :Target discovery is currently in progress
  2835. * from previous GPNFT response,a new GPNFT response has come.
  2836. */
  2837. if (!(((iport->state == FNIC_IPORT_STATE_FABRIC_DISC)
  2838. && (fdls_get_state(fdls) == FDLS_STATE_GPN_FT))
  2839. || ((iport->state == FNIC_IPORT_STATE_READY)
  2840. && ((fdls_get_state(fdls) == FDLS_STATE_RSCN_GPN_FT)
  2841. || (fdls_get_state(fdls) == FDLS_STATE_SEND_GPNFT)
  2842. || (fdls_get_state(fdls) == FDLS_STATE_TGT_DISCOVERY))))) {
  2843. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2844. "GPNFT resp recvd in fab state(%d) iport_state(%d). Dropping.",
  2845. fdls_get_state(fdls), iport->state);
  2846. return;
  2847. }
  2848. if (iport->active_oxid_fabric_req != oxid) {
  2849. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2850. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  2851. fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
  2852. }
  2853. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  2854. iport->state = FNIC_IPORT_STATE_READY;
  2855. rsp = FNIC_STD_GET_FC_CT_CMD((&gpn_ft_rsp->fc_std_ct_hdr));
  2856. switch (rsp) {
  2857. case FC_FS_ACC:
  2858. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2859. "0x%x: GPNFT_RSP accept", iport->fcid);
  2860. if (iport->fabric.timer_pending) {
  2861. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2862. "0x%x: Canceling fabric disc timer\n",
  2863. iport->fcid);
  2864. fnic_del_fabric_timer_sync(fnic);
  2865. }
  2866. iport->fabric.timer_pending = 0;
  2867. iport->fabric.retry_counter = 0;
  2868. fdls_process_gpn_ft_tgt_list(iport, fchdr, len);
  2869. /*
  2870. * iport state can change only if link down event happened
  2871. * We don't need to undo fdls_process_gpn_ft_tgt_list,
  2872. * that will be taken care in next link up event
  2873. */
  2874. if (iport->state != FNIC_IPORT_STATE_READY) {
  2875. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2876. "Halting target discovery: fab st: %d iport st: %d ",
  2877. fdls_get_state(fdls), iport->state);
  2878. break;
  2879. }
  2880. fdls_tgt_discovery_start(iport);
  2881. break;
  2882. case FC_FS_RJT:
  2883. reason_code = gpn_ft_rsp->fc_std_ct_hdr.ct_reason;
  2884. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2885. "0x%x: GPNFT_RSP Reject reason: %d", iport->fcid, reason_code);
  2886. if (((reason_code == FC_FS_RJT_BSY)
  2887. || (reason_code == FC_FS_RJT_UNABL))
  2888. && (fdls->retry_counter < FDLS_RETRY_COUNT)) {
  2889. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2890. "0x%x: GPNFT_RSP ret REJ/BSY. Retry from timer routine",
  2891. iport->fcid);
  2892. /* Retry again from the timer routine */
  2893. fdls->flags |= FNIC_FDLS_RETRY_FRAME;
  2894. } else {
  2895. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2896. "0x%x: GPNFT_RSP reject", iport->fcid);
  2897. if (iport->fabric.timer_pending) {
  2898. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2899. "0x%x: Canceling fabric disc timer\n",
  2900. iport->fcid);
  2901. fnic_del_fabric_timer_sync(fnic);
  2902. }
  2903. iport->fabric.timer_pending = 0;
  2904. iport->fabric.retry_counter = 0;
  2905. /*
  2906. * If GPN_FT ls_rjt then we should delete
  2907. * all existing tports
  2908. */
  2909. count = 0;
  2910. list_for_each_entry_safe(tport, next, &iport->tport_list,
  2911. links) {
  2912. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2913. "GPN_FT_REJECT: Remove port: 0x%x",
  2914. tport->fcid);
  2915. fdls_delete_tport(iport, tport);
  2916. if ((old_link_down_cnt != iport->fnic->link_down_cnt)
  2917. || (iport->state != FNIC_IPORT_STATE_READY)) {
  2918. return;
  2919. }
  2920. count++;
  2921. }
  2922. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2923. "GPN_FT_REJECT: Removed (0x%x) ports", count);
  2924. }
  2925. break;
  2926. default:
  2927. break;
  2928. }
  2929. }
  2930. /**
  2931. * fdls_process_fabric_logo_rsp - Handle an flogo response from the fcf
  2932. * @iport: Handle to fnic iport
  2933. * @fchdr: Incoming frame
  2934. */
  2935. static void
  2936. fdls_process_fabric_logo_rsp(struct fnic_iport_s *iport,
  2937. struct fc_frame_header *fchdr)
  2938. {
  2939. struct fc_std_flogi *flogo_rsp = (struct fc_std_flogi *) fchdr;
  2940. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  2941. struct fnic *fnic = iport->fnic;
  2942. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  2943. if (iport->active_oxid_fabric_req != oxid) {
  2944. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2945. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  2946. fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
  2947. }
  2948. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  2949. switch (flogo_rsp->els.fl_cmd) {
  2950. case ELS_LS_ACC:
  2951. if (iport->fabric.state != FDLS_STATE_FABRIC_LOGO) {
  2952. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2953. "Flogo response. Fabric not in LOGO state. Dropping! %p",
  2954. iport);
  2955. return;
  2956. }
  2957. iport->fabric.state = FDLS_STATE_FLOGO_DONE;
  2958. iport->state = FNIC_IPORT_STATE_LINK_WAIT;
  2959. if (iport->fabric.timer_pending) {
  2960. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2961. "iport 0x%p Canceling fabric disc timer\n",
  2962. iport);
  2963. fnic_del_fabric_timer_sync(fnic);
  2964. }
  2965. iport->fabric.timer_pending = 0;
  2966. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2967. "Flogo response from Fabric for did: 0x%x",
  2968. ntoh24(fchdr->fh_d_id));
  2969. return;
  2970. case ELS_LS_RJT:
  2971. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2972. "Flogo response from Fabric for did: 0x%x returned ELS_LS_RJT",
  2973. ntoh24(fchdr->fh_d_id));
  2974. return;
  2975. default:
  2976. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2977. "FLOGO response not accepted or rejected: 0x%x",
  2978. flogo_rsp->els.fl_cmd);
  2979. }
  2980. }
  2981. static void
  2982. fdls_process_flogi_rsp(struct fnic_iport_s *iport,
  2983. struct fc_frame_header *fchdr, void *rx_frame)
  2984. {
  2985. struct fnic_fdls_fabric_s *fabric = &iport->fabric;
  2986. struct fc_std_flogi *flogi_rsp = (struct fc_std_flogi *) fchdr;
  2987. uint8_t *fcid;
  2988. uint16_t rdf_size;
  2989. uint8_t fcmac[6] = { 0x0E, 0XFC, 0x00, 0x00, 0x00, 0x00 };
  2990. struct fnic *fnic = iport->fnic;
  2991. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  2992. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2993. "0x%x: FDLS processing FLOGI response", iport->fcid);
  2994. if (fdls_get_state(fabric) != FDLS_STATE_FABRIC_FLOGI) {
  2995. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  2996. "FLOGI response received in state (%d). Dropping frame",
  2997. fdls_get_state(fabric));
  2998. return;
  2999. }
  3000. if (iport->active_oxid_fabric_req != oxid) {
  3001. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3002. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  3003. fdls_get_state(fabric), oxid, iport->active_oxid_fabric_req);
  3004. return;
  3005. }
  3006. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  3007. switch (flogi_rsp->els.fl_cmd) {
  3008. case ELS_LS_ACC:
  3009. atomic64_inc(&iport->iport_stats.fabric_flogi_ls_accepts);
  3010. if (iport->fabric.timer_pending) {
  3011. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3012. "iport fcid: 0x%x Canceling fabric disc timer\n",
  3013. iport->fcid);
  3014. fnic_del_fabric_timer_sync(fnic);
  3015. }
  3016. iport->fabric.timer_pending = 0;
  3017. iport->fabric.retry_counter = 0;
  3018. fcid = FNIC_STD_GET_D_ID(fchdr);
  3019. iport->fcid = ntoh24(fcid);
  3020. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3021. "0x%x: FLOGI response accepted", iport->fcid);
  3022. /* Learn the Service Params */
  3023. rdf_size = be16_to_cpu(FNIC_LOGI_RDF_SIZE(flogi_rsp->els));
  3024. if ((rdf_size >= FNIC_MIN_DATA_FIELD_SIZE)
  3025. && (rdf_size < FNIC_FC_MAX_PAYLOAD_LEN))
  3026. iport->max_payload_size = min(rdf_size,
  3027. iport->max_payload_size);
  3028. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3029. "max_payload_size from fabric: %u set: %d", rdf_size,
  3030. iport->max_payload_size);
  3031. iport->r_a_tov = be32_to_cpu(FNIC_LOGI_R_A_TOV(flogi_rsp->els));
  3032. iport->e_d_tov = be32_to_cpu(FNIC_LOGI_E_D_TOV(flogi_rsp->els));
  3033. if (FNIC_LOGI_FEATURES(flogi_rsp->els) & FNIC_FC_EDTOV_NSEC)
  3034. iport->e_d_tov = iport->e_d_tov / FNIC_NSEC_TO_MSEC;
  3035. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3036. "From fabric: R_A_TOV: %d E_D_TOV: %d",
  3037. iport->r_a_tov, iport->e_d_tov);
  3038. fc_host_fabric_name(iport->fnic->host) =
  3039. get_unaligned_be64(&FNIC_LOGI_NODE_NAME(flogi_rsp->els));
  3040. fc_host_port_id(iport->fnic->host) = iport->fcid;
  3041. fnic_fdls_learn_fcoe_macs(iport, rx_frame, fcid);
  3042. if (fnic_fdls_register_portid(iport, iport->fcid, rx_frame) != 0) {
  3043. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3044. "0x%x: FLOGI registration failed", iport->fcid);
  3045. break;
  3046. }
  3047. memcpy(&fcmac[3], fcid, 3);
  3048. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3049. "Adding vNIC device MAC addr: %02x:%02x:%02x:%02x:%02x:%02x",
  3050. fcmac[0], fcmac[1], fcmac[2], fcmac[3], fcmac[4],
  3051. fcmac[5]);
  3052. vnic_dev_add_addr(iport->fnic->vdev, fcmac);
  3053. if (fdls_get_state(fabric) == FDLS_STATE_FABRIC_FLOGI) {
  3054. fnic_fdls_start_plogi(iport);
  3055. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3056. "FLOGI response received. Starting PLOGI");
  3057. } else {
  3058. /* From FDLS_STATE_FABRIC_FLOGI state fabric can only go to
  3059. * FDLS_STATE_LINKDOWN
  3060. * state, hence we don't have to worry about undoing:
  3061. * the fnic_fdls_register_portid and vnic_dev_add_addr
  3062. */
  3063. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3064. "FLOGI response received in state (%d). Dropping frame",
  3065. fdls_get_state(fabric));
  3066. }
  3067. break;
  3068. case ELS_LS_RJT:
  3069. atomic64_inc(&iport->iport_stats.fabric_flogi_ls_rejects);
  3070. if (fabric->retry_counter < iport->max_flogi_retries) {
  3071. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3072. "FLOGI returned ELS_LS_RJT BUSY. Retry from timer routine %p",
  3073. iport);
  3074. /* Retry Flogi again from the timer routine. */
  3075. fabric->flags |= FNIC_FDLS_RETRY_FRAME;
  3076. } else {
  3077. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3078. "FLOGI returned ELS_LS_RJT. Halting discovery %p",
  3079. iport);
  3080. if (iport->fabric.timer_pending) {
  3081. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3082. "iport 0x%p Canceling fabric disc timer\n",
  3083. iport);
  3084. fnic_del_fabric_timer_sync(fnic);
  3085. }
  3086. fabric->timer_pending = 0;
  3087. fabric->retry_counter = 0;
  3088. }
  3089. break;
  3090. default:
  3091. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3092. "FLOGI response not accepted: 0x%x",
  3093. flogi_rsp->els.fl_cmd);
  3094. atomic64_inc(&iport->iport_stats.fabric_flogi_misc_rejects);
  3095. break;
  3096. }
  3097. }
  3098. static void
  3099. fdls_process_fabric_plogi_rsp(struct fnic_iport_s *iport,
  3100. struct fc_frame_header *fchdr)
  3101. {
  3102. struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *) fchdr;
  3103. struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *) fchdr;
  3104. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  3105. struct fnic *fnic = iport->fnic;
  3106. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  3107. if (fdls_get_state((&iport->fabric)) != FDLS_STATE_FABRIC_PLOGI) {
  3108. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3109. "Fabric PLOGI response received in state (%d). Dropping frame",
  3110. fdls_get_state(&iport->fabric));
  3111. return;
  3112. }
  3113. if (iport->active_oxid_fabric_req != oxid) {
  3114. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3115. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  3116. fdls_get_state(fdls), oxid, iport->active_oxid_fabric_req);
  3117. return;
  3118. }
  3119. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  3120. switch (plogi_rsp->els.fl_cmd) {
  3121. case ELS_LS_ACC:
  3122. atomic64_inc(&iport->iport_stats.fabric_plogi_ls_accepts);
  3123. if (iport->fabric.timer_pending) {
  3124. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3125. "iport fcid: 0x%x fabric PLOGI response: Accepted\n",
  3126. iport->fcid);
  3127. fnic_del_fabric_timer_sync(fnic);
  3128. }
  3129. iport->fabric.timer_pending = 0;
  3130. iport->fabric.retry_counter = 0;
  3131. fdls_set_state(&iport->fabric, FDLS_STATE_RPN_ID);
  3132. fdls_send_rpn_id(iport);
  3133. break;
  3134. case ELS_LS_RJT:
  3135. atomic64_inc(&iport->iport_stats.fabric_plogi_ls_rejects);
  3136. if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
  3137. || (els_rjt->rej.er_reason == ELS_RJT_UNAB))
  3138. && (iport->fabric.retry_counter < iport->max_plogi_retries)) {
  3139. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3140. "0x%x: Fabric PLOGI ELS_LS_RJT BUSY. Retry from timer routine",
  3141. iport->fcid);
  3142. } else {
  3143. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3144. "0x%x: Fabric PLOGI ELS_LS_RJT. Halting discovery",
  3145. iport->fcid);
  3146. if (iport->fabric.timer_pending) {
  3147. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3148. "iport fcid: 0x%x Canceling fabric disc timer\n",
  3149. iport->fcid);
  3150. fnic_del_fabric_timer_sync(fnic);
  3151. }
  3152. iport->fabric.timer_pending = 0;
  3153. iport->fabric.retry_counter = 0;
  3154. return;
  3155. }
  3156. break;
  3157. default:
  3158. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3159. "PLOGI response not accepted: 0x%x",
  3160. plogi_rsp->els.fl_cmd);
  3161. atomic64_inc(&iport->iport_stats.fabric_plogi_misc_rejects);
  3162. break;
  3163. }
  3164. }
  3165. static void fdls_process_fdmi_plogi_rsp(struct fnic_iport_s *iport,
  3166. struct fc_frame_header *fchdr)
  3167. {
  3168. struct fc_std_flogi *plogi_rsp = (struct fc_std_flogi *)fchdr;
  3169. struct fc_std_els_rjt_rsp *els_rjt = (struct fc_std_els_rjt_rsp *)fchdr;
  3170. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  3171. struct fnic *fnic = iport->fnic;
  3172. u64 fdmi_tov;
  3173. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  3174. if (iport->active_oxid_fdmi_plogi != oxid) {
  3175. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3176. "Incorrect OXID in response. state: %d, oxid recvd: 0x%x, active oxid: 0x%x\n",
  3177. fdls_get_state(fdls), oxid, iport->active_oxid_fdmi_plogi);
  3178. return;
  3179. }
  3180. iport->fabric.fdmi_pending &= ~FDLS_FDMI_PLOGI_PENDING;
  3181. fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_plogi);
  3182. if (ntoh24(fchdr->fh_s_id) == FC_FID_MGMT_SERV) {
  3183. timer_delete_sync(&iport->fabric.fdmi_timer);
  3184. iport->fabric.fdmi_pending = 0;
  3185. switch (plogi_rsp->els.fl_cmd) {
  3186. case ELS_LS_ACC:
  3187. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3188. "FDLS process fdmi PLOGI response status: ELS_LS_ACC\n");
  3189. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3190. "Sending fdmi registration for port 0x%x\n",
  3191. iport->fcid);
  3192. fdls_fdmi_register_hba(iport);
  3193. fdls_fdmi_register_pa(iport);
  3194. fdmi_tov = jiffies + msecs_to_jiffies(5000);
  3195. mod_timer(&iport->fabric.fdmi_timer,
  3196. round_jiffies(fdmi_tov));
  3197. break;
  3198. case ELS_LS_RJT:
  3199. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3200. "Fabric FDMI PLOGI returned ELS_LS_RJT reason: 0x%x",
  3201. els_rjt->rej.er_reason);
  3202. if (((els_rjt->rej.er_reason == ELS_RJT_BUSY)
  3203. || (els_rjt->rej.er_reason == ELS_RJT_UNAB))
  3204. && (iport->fabric.fdmi_retry < 7)) {
  3205. iport->fabric.fdmi_retry++;
  3206. fdls_send_fdmi_plogi(iport);
  3207. }
  3208. break;
  3209. default:
  3210. break;
  3211. }
  3212. }
  3213. }
  3214. static void fdls_process_fdmi_reg_ack(struct fnic_iport_s *iport,
  3215. struct fc_frame_header *fchdr,
  3216. int rsp_type)
  3217. {
  3218. struct fnic *fnic = iport->fnic;
  3219. uint16_t oxid;
  3220. if (!iport->fabric.fdmi_pending) {
  3221. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3222. "Received FDMI ack while not waiting: 0x%x\n",
  3223. FNIC_STD_GET_OX_ID(fchdr));
  3224. return;
  3225. }
  3226. oxid = FNIC_STD_GET_OX_ID(fchdr);
  3227. if ((iport->active_oxid_fdmi_rhba != oxid) &&
  3228. (iport->active_oxid_fdmi_rpa != oxid)) {
  3229. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3230. "Incorrect OXID in response. oxid recvd: 0x%x, active oxids(rhba,rpa): 0x%x, 0x%x\n",
  3231. oxid, iport->active_oxid_fdmi_rhba, iport->active_oxid_fdmi_rpa);
  3232. return;
  3233. }
  3234. if (FNIC_FRAME_TYPE(oxid) == FNIC_FRAME_TYPE_FDMI_RHBA) {
  3235. iport->fabric.fdmi_pending &= ~FDLS_FDMI_REG_HBA_PENDING;
  3236. fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rhba);
  3237. } else {
  3238. iport->fabric.fdmi_pending &= ~FDLS_FDMI_RPA_PENDING;
  3239. fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rpa);
  3240. }
  3241. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3242. "iport fcid: 0x%x: Received FDMI registration ack\n",
  3243. iport->fcid);
  3244. if (!iport->fabric.fdmi_pending) {
  3245. timer_delete_sync(&iport->fabric.fdmi_timer);
  3246. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3247. "iport fcid: 0x%x: Canceling FDMI timer\n",
  3248. iport->fcid);
  3249. }
  3250. }
  3251. static void fdls_process_fdmi_abts_rsp(struct fnic_iport_s *iport,
  3252. struct fc_frame_header *fchdr)
  3253. {
  3254. uint32_t s_id;
  3255. struct fnic *fnic = iport->fnic;
  3256. uint16_t oxid;
  3257. s_id = ntoh24(FNIC_STD_GET_S_ID(fchdr));
  3258. if (!(s_id != FC_FID_MGMT_SERV)) {
  3259. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3260. "Received abts rsp with invalid SID: 0x%x. Dropping frame",
  3261. s_id);
  3262. return;
  3263. }
  3264. oxid = FNIC_STD_GET_OX_ID(fchdr);
  3265. switch (FNIC_FRAME_TYPE(oxid)) {
  3266. case FNIC_FRAME_TYPE_FDMI_PLOGI:
  3267. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3268. "Received FDMI PLOGI ABTS rsp with oxid: 0x%x", oxid);
  3269. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3270. "0x%x: iport->fabric.fdmi_pending: 0x%x",
  3271. iport->fcid, iport->fabric.fdmi_pending);
  3272. fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_plogi);
  3273. iport->fabric.fdmi_pending &= ~FDLS_FDMI_PLOGI_PENDING;
  3274. iport->fabric.fdmi_pending &= ~FDLS_FDMI_ABORT_PENDING;
  3275. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3276. "0x%x: iport->fabric.fdmi_pending: 0x%x",
  3277. iport->fcid, iport->fabric.fdmi_pending);
  3278. break;
  3279. case FNIC_FRAME_TYPE_FDMI_RHBA:
  3280. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3281. "Received FDMI RHBA ABTS rsp with oxid: 0x%x", oxid);
  3282. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3283. "0x%x: iport->fabric.fdmi_pending: 0x%x",
  3284. iport->fcid, iport->fabric.fdmi_pending);
  3285. iport->fabric.fdmi_pending &= ~FDLS_FDMI_REG_HBA_PENDING;
  3286. /* If RPA is still pending, don't turn off ABORT PENDING.
  3287. * We count on the timer to detect the ABTS timeout and take
  3288. * corrective action.
  3289. */
  3290. if (!(iport->fabric.fdmi_pending & FDLS_FDMI_RPA_PENDING))
  3291. iport->fabric.fdmi_pending &= ~FDLS_FDMI_ABORT_PENDING;
  3292. fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rhba);
  3293. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3294. "0x%x: iport->fabric.fdmi_pending: 0x%x",
  3295. iport->fcid, iport->fabric.fdmi_pending);
  3296. break;
  3297. case FNIC_FRAME_TYPE_FDMI_RPA:
  3298. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3299. "Received FDMI RPA ABTS rsp with oxid: 0x%x", oxid);
  3300. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3301. "0x%x: iport->fabric.fdmi_pending: 0x%x",
  3302. iport->fcid, iport->fabric.fdmi_pending);
  3303. iport->fabric.fdmi_pending &= ~FDLS_FDMI_RPA_PENDING;
  3304. /* If RHBA is still pending, don't turn off ABORT PENDING.
  3305. * We count on the timer to detect the ABTS timeout and take
  3306. * corrective action.
  3307. */
  3308. if (!(iport->fabric.fdmi_pending & FDLS_FDMI_REG_HBA_PENDING))
  3309. iport->fabric.fdmi_pending &= ~FDLS_FDMI_ABORT_PENDING;
  3310. fdls_free_oxid(iport, oxid, &iport->active_oxid_fdmi_rpa);
  3311. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3312. "0x%x: iport->fabric.fdmi_pending: 0x%x",
  3313. iport->fcid, iport->fabric.fdmi_pending);
  3314. break;
  3315. default:
  3316. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3317. "Received abts rsp with invalid oxid: 0x%x. Dropping frame",
  3318. oxid);
  3319. break;
  3320. }
  3321. /*
  3322. * Only if ABORT PENDING is off, delete the timer, and if no other
  3323. * operations are pending, retry FDMI.
  3324. * Otherwise, let the timer pop and take the appropriate action.
  3325. */
  3326. if (!(iport->fabric.fdmi_pending & FDLS_FDMI_ABORT_PENDING)) {
  3327. timer_delete_sync(&iport->fabric.fdmi_timer);
  3328. if (!iport->fabric.fdmi_pending)
  3329. fdls_fdmi_retry_plogi(iport);
  3330. }
  3331. }
  3332. static void
  3333. fdls_process_fabric_abts_rsp(struct fnic_iport_s *iport,
  3334. struct fc_frame_header *fchdr)
  3335. {
  3336. uint32_t s_id;
  3337. struct fc_std_abts_ba_acc *ba_acc = (struct fc_std_abts_ba_acc *)fchdr;
  3338. struct fc_std_abts_ba_rjt *ba_rjt;
  3339. uint32_t fabric_state = iport->fabric.state;
  3340. struct fnic *fnic = iport->fnic;
  3341. int frame_type;
  3342. uint16_t oxid;
  3343. s_id = ntoh24(fchdr->fh_s_id);
  3344. ba_rjt = (struct fc_std_abts_ba_rjt *) fchdr;
  3345. if (!((s_id == FC_FID_DIR_SERV) || (s_id == FC_FID_FLOGI)
  3346. || (s_id == FC_FID_FCTRL))) {
  3347. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3348. "Received abts rsp with invalid SID: 0x%x. Dropping frame",
  3349. s_id);
  3350. return;
  3351. }
  3352. oxid = FNIC_STD_GET_OX_ID(fchdr);
  3353. if (iport->active_oxid_fabric_req != oxid) {
  3354. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3355. "Received abts rsp with invalid oxid: 0x%x. Dropping frame",
  3356. oxid);
  3357. return;
  3358. }
  3359. if (iport->fabric.timer_pending) {
  3360. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3361. "Canceling fabric disc timer %p\n", iport);
  3362. fnic_del_fabric_timer_sync(fnic);
  3363. }
  3364. iport->fabric.timer_pending = 0;
  3365. iport->fabric.flags &= ~FNIC_FDLS_FABRIC_ABORT_ISSUED;
  3366. if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) {
  3367. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3368. "Received abts rsp BA_ACC for fabric_state: %d OX_ID: 0x%x",
  3369. fabric_state, be16_to_cpu(ba_acc->acc.ba_ox_id));
  3370. } else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) {
  3371. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3372. "BA_RJT fs: %d OX_ID: 0x%x rc: 0x%x rce: 0x%x",
  3373. fabric_state, FNIC_STD_GET_OX_ID(&ba_rjt->fchdr),
  3374. ba_rjt->rjt.br_reason, ba_rjt->rjt.br_explan);
  3375. }
  3376. frame_type = FNIC_FRAME_TYPE(oxid);
  3377. fdls_free_oxid(iport, oxid, &iport->active_oxid_fabric_req);
  3378. /* currently error handling/retry logic is same for ABTS BA_ACC & BA_RJT */
  3379. switch (frame_type) {
  3380. case FNIC_FRAME_TYPE_FABRIC_FLOGI:
  3381. if (iport->fabric.retry_counter < iport->max_flogi_retries)
  3382. fdls_send_fabric_flogi(iport);
  3383. else
  3384. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3385. "Exceeded max FLOGI retries");
  3386. break;
  3387. case FNIC_FRAME_TYPE_FABRIC_LOGO:
  3388. if (iport->fabric.retry_counter < FABRIC_LOGO_MAX_RETRY)
  3389. fdls_send_fabric_logo(iport);
  3390. break;
  3391. case FNIC_FRAME_TYPE_FABRIC_PLOGI:
  3392. if (iport->fabric.retry_counter < iport->max_plogi_retries)
  3393. fdls_send_fabric_plogi(iport);
  3394. else
  3395. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3396. "Exceeded max PLOGI retries");
  3397. break;
  3398. case FNIC_FRAME_TYPE_FABRIC_RPN:
  3399. if (iport->fabric.retry_counter < FDLS_RETRY_COUNT)
  3400. fdls_send_rpn_id(iport);
  3401. else
  3402. /* go back to fabric Plogi */
  3403. fnic_fdls_start_plogi(iport);
  3404. break;
  3405. case FNIC_FRAME_TYPE_FABRIC_SCR:
  3406. if (iport->fabric.retry_counter < FDLS_RETRY_COUNT)
  3407. fdls_send_scr(iport);
  3408. else {
  3409. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3410. "SCR exhausted retries. Start fabric PLOGI %p",
  3411. iport);
  3412. fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
  3413. }
  3414. break;
  3415. case FNIC_FRAME_TYPE_FABRIC_RFT:
  3416. if (iport->fabric.retry_counter < FDLS_RETRY_COUNT)
  3417. fdls_send_register_fc4_types(iport);
  3418. else {
  3419. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3420. "RFT exhausted retries. Start fabric PLOGI %p",
  3421. iport);
  3422. fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
  3423. }
  3424. break;
  3425. case FNIC_FRAME_TYPE_FABRIC_RFF:
  3426. if (iport->fabric.retry_counter < FDLS_RETRY_COUNT)
  3427. fdls_send_register_fc4_features(iport);
  3428. else {
  3429. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3430. "RFF exhausted retries. Start fabric PLOGI %p",
  3431. iport);
  3432. fnic_fdls_start_plogi(iport); /* go back to fabric Plogi */
  3433. }
  3434. break;
  3435. case FNIC_FRAME_TYPE_FABRIC_GPN_FT:
  3436. if (iport->fabric.retry_counter <= FDLS_RETRY_COUNT)
  3437. fdls_send_gpn_ft(iport, fabric_state);
  3438. else
  3439. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3440. "GPN FT exhausted retries. Start fabric PLOGI %p",
  3441. iport);
  3442. break;
  3443. default:
  3444. /*
  3445. * We should not be here since we already validated rx oxid with
  3446. * our active_oxid_fabric_req
  3447. */
  3448. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3449. "Invalid OXID/active oxid 0x%x\n", oxid);
  3450. WARN_ON(true);
  3451. return;
  3452. }
  3453. }
  3454. static void
  3455. fdls_process_abts_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
  3456. {
  3457. uint8_t *frame;
  3458. struct fc_std_abts_ba_acc *pba_acc;
  3459. uint32_t nport_id;
  3460. uint16_t oxid = FNIC_STD_GET_OX_ID(fchdr);
  3461. struct fnic_tport_s *tport;
  3462. struct fnic *fnic = iport->fnic;
  3463. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  3464. sizeof(struct fc_std_abts_ba_acc);
  3465. nport_id = ntoh24(fchdr->fh_s_id);
  3466. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3467. "Received abort from SID 0x%8x", nport_id);
  3468. tport = fnic_find_tport_by_fcid(iport, nport_id);
  3469. if (tport) {
  3470. if (tport->active_oxid == oxid) {
  3471. tport->flags |= FNIC_FDLS_TGT_ABORT_ISSUED;
  3472. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  3473. }
  3474. }
  3475. frame = fdls_alloc_frame(iport);
  3476. if (frame == NULL) {
  3477. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3478. "0x%x: Failed to allocate frame to send response for ABTS req",
  3479. iport->fcid);
  3480. return;
  3481. }
  3482. pba_acc = (struct fc_std_abts_ba_acc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  3483. *pba_acc = (struct fc_std_abts_ba_acc) {
  3484. .fchdr = {.fh_r_ctl = FC_RCTL_BA_ACC,
  3485. .fh_f_ctl = {FNIC_FCP_RSP_FCTL, 0, 0}},
  3486. .acc = {.ba_low_seq_cnt = 0, .ba_high_seq_cnt = cpu_to_be16(0xFFFF)}
  3487. };
  3488. FNIC_STD_SET_S_ID(pba_acc->fchdr, fchdr->fh_d_id);
  3489. FNIC_STD_SET_D_ID(pba_acc->fchdr, fchdr->fh_s_id);
  3490. FNIC_STD_SET_OX_ID(pba_acc->fchdr, FNIC_STD_GET_OX_ID(fchdr));
  3491. FNIC_STD_SET_RX_ID(pba_acc->fchdr, FNIC_STD_GET_RX_ID(fchdr));
  3492. pba_acc->acc.ba_rx_id = cpu_to_be16(FNIC_STD_GET_RX_ID(fchdr));
  3493. pba_acc->acc.ba_ox_id = cpu_to_be16(FNIC_STD_GET_OX_ID(fchdr));
  3494. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3495. "0x%x: FDLS send BA ACC with oxid: 0x%x",
  3496. iport->fcid, oxid);
  3497. fnic_send_fcoe_frame(iport, frame, frame_size);
  3498. }
  3499. static void
  3500. fdls_process_unsupported_els_req(struct fnic_iport_s *iport,
  3501. struct fc_frame_header *fchdr)
  3502. {
  3503. uint8_t *frame;
  3504. struct fc_std_els_rjt_rsp *pls_rsp;
  3505. uint16_t oxid;
  3506. uint32_t d_id = ntoh24(fchdr->fh_d_id);
  3507. struct fnic *fnic = iport->fnic;
  3508. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  3509. sizeof(struct fc_std_els_rjt_rsp);
  3510. if (iport->fcid != d_id) {
  3511. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3512. "Dropping unsupported ELS with illegal frame bits 0x%x\n",
  3513. d_id);
  3514. atomic64_inc(&iport->iport_stats.unsupported_frames_dropped);
  3515. return;
  3516. }
  3517. if ((iport->state != FNIC_IPORT_STATE_READY)
  3518. && (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) {
  3519. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3520. "Dropping unsupported ELS request in iport state: %d",
  3521. iport->state);
  3522. atomic64_inc(&iport->iport_stats.unsupported_frames_dropped);
  3523. return;
  3524. }
  3525. frame = fdls_alloc_frame(iport);
  3526. if (frame == NULL) {
  3527. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3528. "Failed to allocate frame to send response to unsupported ELS request");
  3529. return;
  3530. }
  3531. pls_rsp = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  3532. fdls_init_els_rjt_frame(frame, iport);
  3533. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3534. "0x%x: Process unsupported ELS request from SID: 0x%x",
  3535. iport->fcid, ntoh24(fchdr->fh_s_id));
  3536. /* We don't support this ELS request, send a reject */
  3537. pls_rsp->rej.er_reason = 0x0B;
  3538. pls_rsp->rej.er_explan = 0x0;
  3539. pls_rsp->rej.er_vendor = 0x0;
  3540. FNIC_STD_SET_S_ID(pls_rsp->fchdr, fchdr->fh_d_id);
  3541. FNIC_STD_SET_D_ID(pls_rsp->fchdr, fchdr->fh_s_id);
  3542. oxid = FNIC_STD_GET_OX_ID(fchdr);
  3543. FNIC_STD_SET_OX_ID(pls_rsp->fchdr, oxid);
  3544. fnic_send_fcoe_frame(iport, frame, frame_size);
  3545. }
  3546. static void
  3547. fdls_process_rls_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
  3548. {
  3549. uint8_t *frame;
  3550. struct fc_std_rls_acc *prls_acc_rsp;
  3551. uint16_t oxid;
  3552. struct fnic *fnic = iport->fnic;
  3553. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  3554. sizeof(struct fc_std_rls_acc);
  3555. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3556. "Process RLS request %d", iport->fnic->fnic_num);
  3557. if ((iport->state != FNIC_IPORT_STATE_READY)
  3558. && (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) {
  3559. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3560. "Received RLS req in iport state: %d. Dropping the frame.",
  3561. iport->state);
  3562. return;
  3563. }
  3564. frame = fdls_alloc_frame(iport);
  3565. if (frame == NULL) {
  3566. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3567. "Failed to allocate frame to send RLS accept");
  3568. return;
  3569. }
  3570. prls_acc_rsp = (struct fc_std_rls_acc *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  3571. FNIC_STD_SET_S_ID(prls_acc_rsp->fchdr, fchdr->fh_d_id);
  3572. FNIC_STD_SET_D_ID(prls_acc_rsp->fchdr, fchdr->fh_s_id);
  3573. oxid = FNIC_STD_GET_OX_ID(fchdr);
  3574. FNIC_STD_SET_OX_ID(prls_acc_rsp->fchdr, oxid);
  3575. FNIC_STD_SET_RX_ID(prls_acc_rsp->fchdr, FNIC_UNASSIGNED_RXID);
  3576. FNIC_STD_SET_F_CTL(prls_acc_rsp->fchdr, FNIC_ELS_REP_FCTL << 16);
  3577. FNIC_STD_SET_R_CTL(prls_acc_rsp->fchdr, FC_RCTL_ELS_REP);
  3578. FNIC_STD_SET_TYPE(prls_acc_rsp->fchdr, FC_TYPE_ELS);
  3579. prls_acc_rsp->els.rls_cmd = ELS_LS_ACC;
  3580. prls_acc_rsp->els.rls_lesb.lesb_link_fail =
  3581. cpu_to_be32(iport->fnic->link_down_cnt);
  3582. fnic_send_fcoe_frame(iport, frame, frame_size);
  3583. }
  3584. static void
  3585. fdls_process_els_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr,
  3586. uint32_t len)
  3587. {
  3588. uint8_t *frame;
  3589. struct fc_std_els_acc_rsp *pels_acc;
  3590. uint16_t oxid;
  3591. uint8_t *fc_payload;
  3592. uint8_t type;
  3593. struct fnic *fnic = iport->fnic;
  3594. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET;
  3595. fc_payload = (uint8_t *) fchdr + sizeof(struct fc_frame_header);
  3596. type = *fc_payload;
  3597. if ((iport->state != FNIC_IPORT_STATE_READY)
  3598. && (iport->state != FNIC_IPORT_STATE_FABRIC_DISC)) {
  3599. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3600. "Dropping ELS frame type: 0x%x in iport state: %d",
  3601. type, iport->state);
  3602. return;
  3603. }
  3604. switch (type) {
  3605. case ELS_ECHO:
  3606. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3607. "sending LS_ACC for ECHO request %d\n",
  3608. iport->fnic->fnic_num);
  3609. break;
  3610. case ELS_RRQ:
  3611. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3612. "sending LS_ACC for RRQ request %d\n",
  3613. iport->fnic->fnic_num);
  3614. break;
  3615. default:
  3616. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3617. "sending LS_ACC for 0x%x ELS frame\n", type);
  3618. break;
  3619. }
  3620. frame = fdls_alloc_frame(iport);
  3621. if (frame == NULL) {
  3622. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3623. "Failed to allocate frame to send ELS response for 0x%x",
  3624. type);
  3625. return;
  3626. }
  3627. if (type == ELS_ECHO) {
  3628. /* Brocade sends a longer payload, copy all frame back */
  3629. memcpy(frame, fchdr, len);
  3630. }
  3631. pels_acc = (struct fc_std_els_acc_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  3632. fdls_init_els_acc_frame(frame, iport);
  3633. FNIC_STD_SET_D_ID(pels_acc->fchdr, fchdr->fh_s_id);
  3634. oxid = FNIC_STD_GET_OX_ID(fchdr);
  3635. FNIC_STD_SET_OX_ID(pels_acc->fchdr, oxid);
  3636. if (type == ELS_ECHO)
  3637. frame_size += len;
  3638. else
  3639. frame_size += sizeof(struct fc_std_els_acc_rsp);
  3640. fnic_send_fcoe_frame(iport, frame, frame_size);
  3641. }
  3642. static void
  3643. fdls_process_tgt_abts_rsp(struct fnic_iport_s *iport,
  3644. struct fc_frame_header *fchdr)
  3645. {
  3646. uint32_t s_id;
  3647. struct fnic_tport_s *tport;
  3648. uint32_t tport_state;
  3649. struct fc_std_abts_ba_acc *ba_acc;
  3650. struct fc_std_abts_ba_rjt *ba_rjt;
  3651. uint16_t oxid;
  3652. struct fnic *fnic = iport->fnic;
  3653. int frame_type;
  3654. s_id = ntoh24(fchdr->fh_s_id);
  3655. ba_acc = (struct fc_std_abts_ba_acc *)fchdr;
  3656. ba_rjt = (struct fc_std_abts_ba_rjt *)fchdr;
  3657. tport = fnic_find_tport_by_fcid(iport, s_id);
  3658. if (!tport) {
  3659. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3660. "Received tgt abts rsp with invalid SID: 0x%x", s_id);
  3661. return;
  3662. }
  3663. if (tport->timer_pending) {
  3664. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3665. "tport 0x%p Canceling fabric disc timer\n", tport);
  3666. fnic_del_tport_timer_sync(fnic, tport);
  3667. }
  3668. if (iport->state != FNIC_IPORT_STATE_READY) {
  3669. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3670. "Received tgt abts rsp in iport state(%d). Dropping.",
  3671. iport->state);
  3672. return;
  3673. }
  3674. tport->timer_pending = 0;
  3675. tport->flags &= ~FNIC_FDLS_TGT_ABORT_ISSUED;
  3676. tport_state = tport->state;
  3677. oxid = FNIC_STD_GET_OX_ID(fchdr);
  3678. /*This abort rsp is for ADISC */
  3679. frame_type = FNIC_FRAME_TYPE(oxid);
  3680. switch (frame_type) {
  3681. case FNIC_FRAME_TYPE_TGT_ADISC:
  3682. if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) {
  3683. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3684. "OX_ID: 0x%x tgt_fcid: 0x%x rcvd tgt adisc abts resp BA_ACC",
  3685. be16_to_cpu(ba_acc->acc.ba_ox_id),
  3686. tport->fcid);
  3687. } else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) {
  3688. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3689. "ADISC BA_RJT rcvd tport_fcid: 0x%x tport_state: %d ",
  3690. tport->fcid, tport_state);
  3691. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3692. "reason code: 0x%x reason code explanation:0x%x ",
  3693. ba_rjt->rjt.br_reason,
  3694. ba_rjt->rjt.br_explan);
  3695. }
  3696. if ((tport->retry_counter < FDLS_RETRY_COUNT)
  3697. && (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) {
  3698. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  3699. fdls_send_tgt_adisc(iport, tport);
  3700. return;
  3701. }
  3702. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  3703. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3704. "ADISC not responding. Deleting target port: 0x%x",
  3705. tport->fcid);
  3706. fdls_delete_tport(iport, tport);
  3707. /* Restart discovery of targets */
  3708. if ((iport->state == FNIC_IPORT_STATE_READY)
  3709. && (iport->fabric.state != FDLS_STATE_SEND_GPNFT)
  3710. && (iport->fabric.state != FDLS_STATE_RSCN_GPN_FT)) {
  3711. fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT);
  3712. }
  3713. break;
  3714. case FNIC_FRAME_TYPE_TGT_PLOGI:
  3715. if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) {
  3716. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3717. "Received tgt PLOGI abts response BA_ACC tgt_fcid: 0x%x",
  3718. tport->fcid);
  3719. } else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) {
  3720. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3721. "PLOGI BA_RJT received for tport_fcid: 0x%x OX_ID: 0x%x",
  3722. tport->fcid, FNIC_STD_GET_OX_ID(fchdr));
  3723. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3724. "reason code: 0x%x reason code explanation: 0x%x",
  3725. ba_rjt->rjt.br_reason,
  3726. ba_rjt->rjt.br_explan);
  3727. }
  3728. if ((tport->retry_counter < iport->max_plogi_retries)
  3729. && (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) {
  3730. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  3731. fdls_send_tgt_plogi(iport, tport);
  3732. return;
  3733. }
  3734. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  3735. fdls_delete_tport(iport, tport);
  3736. /* Restart discovery of targets */
  3737. if ((iport->state == FNIC_IPORT_STATE_READY)
  3738. && (iport->fabric.state != FDLS_STATE_SEND_GPNFT)
  3739. && (iport->fabric.state != FDLS_STATE_RSCN_GPN_FT)) {
  3740. fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT);
  3741. }
  3742. break;
  3743. case FNIC_FRAME_TYPE_TGT_PRLI:
  3744. if (fchdr->fh_r_ctl == FC_RCTL_BA_ACC) {
  3745. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3746. "0x%x: Received tgt PRLI abts response BA_ACC",
  3747. tport->fcid);
  3748. } else if (fchdr->fh_r_ctl == FC_RCTL_BA_RJT) {
  3749. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3750. "PRLI BA_RJT received for tport_fcid: 0x%x OX_ID: 0x%x ",
  3751. tport->fcid, FNIC_STD_GET_OX_ID(fchdr));
  3752. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3753. "reason code: 0x%x reason code explanation: 0x%x",
  3754. ba_rjt->rjt.br_reason,
  3755. ba_rjt->rjt.br_explan);
  3756. }
  3757. if ((tport->retry_counter < FDLS_RETRY_COUNT)
  3758. && (fchdr->fh_r_ctl == FC_RCTL_BA_ACC)) {
  3759. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  3760. fdls_send_tgt_prli(iport, tport);
  3761. return;
  3762. }
  3763. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  3764. fdls_send_tgt_plogi(iport, tport); /* go back to plogi */
  3765. fdls_set_tport_state(tport, FDLS_TGT_STATE_PLOGI);
  3766. break;
  3767. default:
  3768. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3769. "Received ABTS response for unknown frame %p", iport);
  3770. break;
  3771. }
  3772. }
  3773. static void
  3774. fdls_process_plogi_req(struct fnic_iport_s *iport,
  3775. struct fc_frame_header *fchdr)
  3776. {
  3777. uint8_t *frame;
  3778. struct fc_std_els_rjt_rsp *pplogi_rsp;
  3779. uint16_t oxid;
  3780. uint32_t d_id = ntoh24(fchdr->fh_d_id);
  3781. struct fnic *fnic = iport->fnic;
  3782. uint16_t frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  3783. sizeof(struct fc_std_els_rjt_rsp);
  3784. if (iport->fcid != d_id) {
  3785. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3786. "Received PLOGI with illegal frame bits. Dropping frame from 0x%x",
  3787. d_id);
  3788. return;
  3789. }
  3790. if (iport->state != FNIC_IPORT_STATE_READY) {
  3791. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3792. "Received PLOGI request in iport state: %d Dropping frame",
  3793. iport->state);
  3794. return;
  3795. }
  3796. frame = fdls_alloc_frame(iport);
  3797. if (frame == NULL) {
  3798. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3799. "Failed to allocate frame to send response to PLOGI request");
  3800. return;
  3801. }
  3802. pplogi_rsp = (struct fc_std_els_rjt_rsp *) (frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  3803. fdls_init_els_rjt_frame(frame, iport);
  3804. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3805. "0x%x: Process PLOGI request from SID: 0x%x",
  3806. iport->fcid, ntoh24(fchdr->fh_s_id));
  3807. /* We don't support PLOGI request, send a reject */
  3808. pplogi_rsp->rej.er_reason = 0x0B;
  3809. pplogi_rsp->rej.er_explan = 0x0;
  3810. pplogi_rsp->rej.er_vendor = 0x0;
  3811. FNIC_STD_SET_S_ID(pplogi_rsp->fchdr, fchdr->fh_d_id);
  3812. FNIC_STD_SET_D_ID(pplogi_rsp->fchdr, fchdr->fh_s_id);
  3813. oxid = FNIC_STD_GET_OX_ID(fchdr);
  3814. FNIC_STD_SET_OX_ID(pplogi_rsp->fchdr, oxid);
  3815. fnic_send_fcoe_frame(iport, frame, frame_size);
  3816. }
  3817. static void
  3818. fdls_process_logo_req(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
  3819. {
  3820. struct fc_std_logo *logo = (struct fc_std_logo *)fchdr;
  3821. uint32_t nport_id;
  3822. uint64_t nport_name;
  3823. struct fnic_tport_s *tport;
  3824. struct fnic *fnic = iport->fnic;
  3825. uint16_t oxid;
  3826. nport_id = ntoh24(logo->els.fl_n_port_id);
  3827. nport_name = be64_to_cpu(logo->els.fl_n_port_wwn);
  3828. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3829. "Process LOGO request from fcid: 0x%x", nport_id);
  3830. if (iport->state != FNIC_IPORT_STATE_READY) {
  3831. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3832. "Dropping LOGO req from 0x%x in iport state: %d",
  3833. nport_id, iport->state);
  3834. return;
  3835. }
  3836. tport = fnic_find_tport_by_fcid(iport, nport_id);
  3837. if (!tport) {
  3838. /* We are not logged in with the nport, log and drop... */
  3839. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3840. "Received LOGO from an nport not logged in: 0x%x(0x%llx)",
  3841. nport_id, nport_name);
  3842. return;
  3843. }
  3844. if (tport->fcid != nport_id) {
  3845. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3846. "Received LOGO with invalid target port fcid: 0x%x(0x%llx)",
  3847. nport_id, nport_name);
  3848. return;
  3849. }
  3850. if (tport->timer_pending) {
  3851. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3852. "tport fcid 0x%x: Canceling disc timer\n",
  3853. tport->fcid);
  3854. fnic_del_tport_timer_sync(fnic, tport);
  3855. tport->timer_pending = 0;
  3856. }
  3857. /* got a logo in response to adisc to a target which has logged out */
  3858. if (tport->state == FDLS_TGT_STATE_ADISC) {
  3859. tport->retry_counter = 0;
  3860. oxid = tport->active_oxid;
  3861. fdls_free_oxid(iport, oxid, &tport->active_oxid);
  3862. fdls_delete_tport(iport, tport);
  3863. fdls_send_logo_resp(iport, &logo->fchdr);
  3864. if ((iport->state == FNIC_IPORT_STATE_READY)
  3865. && (fdls_get_state(&iport->fabric) != FDLS_STATE_SEND_GPNFT)
  3866. && (fdls_get_state(&iport->fabric) != FDLS_STATE_RSCN_GPN_FT)) {
  3867. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3868. "Sending GPNFT in response to LOGO from Target:0x%x",
  3869. nport_id);
  3870. fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT);
  3871. return;
  3872. }
  3873. } else {
  3874. fdls_delete_tport(iport, tport);
  3875. }
  3876. if (iport->state == FNIC_IPORT_STATE_READY) {
  3877. fdls_send_logo_resp(iport, &logo->fchdr);
  3878. if ((fdls_get_state(&iport->fabric) != FDLS_STATE_SEND_GPNFT) &&
  3879. (fdls_get_state(&iport->fabric) != FDLS_STATE_RSCN_GPN_FT)) {
  3880. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  3881. "Sending GPNFT in response to LOGO from Target:0x%x",
  3882. nport_id);
  3883. fdls_send_gpn_ft(iport, FDLS_STATE_SEND_GPNFT);
  3884. }
  3885. }
  3886. }
  3887. static void
  3888. fdls_process_rscn(struct fnic_iport_s *iport, struct fc_frame_header *fchdr)
  3889. {
  3890. struct fc_std_rscn *rscn;
  3891. struct fc_els_rscn_page *rscn_port = NULL;
  3892. int num_ports;
  3893. struct fnic_tport_s *tport, *next;
  3894. uint32_t nport_id;
  3895. uint8_t fcid[3];
  3896. int newports = 0;
  3897. struct fnic_fdls_fabric_s *fdls = &iport->fabric;
  3898. struct fnic *fnic = iport->fnic;
  3899. int rscn_type = NOT_PC_RSCN;
  3900. uint32_t sid = ntoh24(fchdr->fh_s_id);
  3901. unsigned long reset_fnic_list_lock_flags = 0;
  3902. uint16_t rscn_payload_len;
  3903. atomic64_inc(&iport->iport_stats.num_rscns);
  3904. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3905. "FDLS process RSCN %p", iport);
  3906. if (iport->state != FNIC_IPORT_STATE_READY) {
  3907. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3908. "FDLS RSCN received in state(%d). Dropping",
  3909. fdls_get_state(fdls));
  3910. return;
  3911. }
  3912. rscn = (struct fc_std_rscn *)fchdr;
  3913. rscn_payload_len = be16_to_cpu(rscn->els.rscn_plen);
  3914. /* frame validation */
  3915. if ((rscn_payload_len % 4 != 0) || (rscn_payload_len < 8)
  3916. || (rscn_payload_len > 1024)
  3917. || (rscn->els.rscn_page_len != 4)) {
  3918. num_ports = 0;
  3919. if ((rscn_payload_len == 0xFFFF)
  3920. && (sid == FC_FID_FCTRL)) {
  3921. rscn_type = PC_RSCN;
  3922. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3923. "pcrscn: PCRSCN received. sid: 0x%x payload len: 0x%x",
  3924. sid, rscn_payload_len);
  3925. } else {
  3926. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3927. "RSCN payload_len: 0x%x page_len: 0x%x",
  3928. rscn_payload_len, rscn->els.rscn_page_len);
  3929. /* if this happens then we need to send ADISC to all the tports. */
  3930. list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
  3931. if (tport->state == FDLS_TGT_STATE_READY)
  3932. tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC;
  3933. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3934. "RSCN for port id: 0x%x", tport->fcid);
  3935. }
  3936. } /* end else */
  3937. } else {
  3938. num_ports = (rscn_payload_len - 4) / rscn->els.rscn_page_len;
  3939. rscn_port = (struct fc_els_rscn_page *)(rscn + 1);
  3940. }
  3941. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3942. "RSCN received for num_ports: %d payload_len: %d page_len: %d ",
  3943. num_ports, rscn_payload_len, rscn->els.rscn_page_len);
  3944. /*
  3945. * RSCN have at least one Port_ID page , but may not have any port_id
  3946. * in it. If no port_id is specified in the Port_ID page , we send
  3947. * ADISC to all the tports
  3948. */
  3949. while (num_ports) {
  3950. memcpy(fcid, rscn_port->rscn_fid, 3);
  3951. nport_id = ntoh24(fcid);
  3952. rscn_port++;
  3953. num_ports--;
  3954. /* if this happens then we need to send ADISC to all the tports. */
  3955. if (nport_id == 0) {
  3956. list_for_each_entry_safe(tport, next, &iport->tport_list,
  3957. links) {
  3958. if (tport->state == FDLS_TGT_STATE_READY)
  3959. tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC;
  3960. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3961. "RSCN for port id: 0x%x", tport->fcid);
  3962. }
  3963. break;
  3964. }
  3965. tport = fnic_find_tport_by_fcid(iport, nport_id);
  3966. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3967. "RSCN port id list: 0x%x", nport_id);
  3968. if (!tport) {
  3969. newports++;
  3970. continue;
  3971. }
  3972. if (tport->state == FDLS_TGT_STATE_READY)
  3973. tport->flags |= FNIC_FDLS_TPORT_SEND_ADISC;
  3974. }
  3975. if (pc_rscn_handling_feature_flag == PC_RSCN_HANDLING_FEATURE_ON &&
  3976. rscn_type == PC_RSCN && fnic->role == FNIC_ROLE_FCP_INITIATOR) {
  3977. if (fnic->pc_rscn_handling_status == PC_RSCN_HANDLING_IN_PROGRESS) {
  3978. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3979. "PCRSCN handling already in progress. Skip host reset: %d",
  3980. iport->fnic->fnic_num);
  3981. return;
  3982. }
  3983. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3984. "Processing PCRSCN. Queuing fnic for host reset: %d",
  3985. iport->fnic->fnic_num);
  3986. fnic->pc_rscn_handling_status = PC_RSCN_HANDLING_IN_PROGRESS;
  3987. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  3988. spin_lock_irqsave(&reset_fnic_list_lock,
  3989. reset_fnic_list_lock_flags);
  3990. list_add_tail(&fnic->links, &reset_fnic_list);
  3991. spin_unlock_irqrestore(&reset_fnic_list_lock,
  3992. reset_fnic_list_lock_flags);
  3993. queue_work(reset_fnic_work_queue, &reset_fnic_work);
  3994. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  3995. } else {
  3996. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  3997. "FDLS process RSCN sending GPN_FT: newports: %d", newports);
  3998. fdls_send_gpn_ft(iport, FDLS_STATE_RSCN_GPN_FT);
  3999. fdls_send_rscn_resp(iport, fchdr);
  4000. }
  4001. }
  4002. void fnic_fdls_disc_start(struct fnic_iport_s *iport)
  4003. {
  4004. struct fnic *fnic = iport->fnic;
  4005. fc_host_fabric_name(iport->fnic->host) = 0;
  4006. fc_host_post_event(iport->fnic->host, fc_get_event_number(),
  4007. FCH_EVT_LIPRESET, 0);
  4008. if (!iport->usefip) {
  4009. if (iport->flags & FNIC_FIRST_LINK_UP) {
  4010. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  4011. fnic_scsi_fcpio_reset(iport->fnic);
  4012. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  4013. iport->flags &= ~FNIC_FIRST_LINK_UP;
  4014. }
  4015. fnic_fdls_start_flogi(iport);
  4016. } else
  4017. fnic_fdls_start_plogi(iport);
  4018. }
  4019. static void
  4020. fdls_process_adisc_req(struct fnic_iport_s *iport,
  4021. struct fc_frame_header *fchdr)
  4022. {
  4023. struct fc_std_els_adisc *padisc_acc;
  4024. struct fc_std_els_adisc *adisc_req = (struct fc_std_els_adisc *)fchdr;
  4025. uint64_t frame_wwnn;
  4026. uint64_t frame_wwpn;
  4027. uint32_t tgt_fcid;
  4028. struct fnic_tport_s *tport;
  4029. uint8_t *fcid;
  4030. uint8_t *rjt_frame;
  4031. uint8_t *acc_frame;
  4032. struct fc_std_els_rjt_rsp *prjts_rsp;
  4033. uint16_t oxid;
  4034. struct fnic *fnic = iport->fnic;
  4035. uint16_t rjt_frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  4036. sizeof(struct fc_std_els_rjt_rsp);
  4037. uint16_t acc_frame_size = FNIC_ETH_FCOE_HDRS_OFFSET +
  4038. sizeof(struct fc_std_els_adisc);
  4039. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4040. "Process ADISC request %d", iport->fnic->fnic_num);
  4041. fcid = FNIC_STD_GET_S_ID(fchdr);
  4042. tgt_fcid = ntoh24(fcid);
  4043. tport = fnic_find_tport_by_fcid(iport, tgt_fcid);
  4044. if (!tport) {
  4045. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  4046. "tport for fcid: 0x%x not found. Dropping ADISC req.",
  4047. tgt_fcid);
  4048. return;
  4049. }
  4050. if (iport->state != FNIC_IPORT_STATE_READY) {
  4051. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  4052. "Dropping ADISC req from fcid: 0x%x in iport state: %d",
  4053. tgt_fcid, iport->state);
  4054. return;
  4055. }
  4056. frame_wwnn = be64_to_cpu(adisc_req->els.adisc_wwnn);
  4057. frame_wwpn = be64_to_cpu(adisc_req->els.adisc_wwpn);
  4058. if ((frame_wwnn != tport->wwnn) || (frame_wwpn != tport->wwpn)) {
  4059. /* send reject */
  4060. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  4061. "ADISC req from fcid: 0x%x mismatch wwpn: 0x%llx wwnn: 0x%llx",
  4062. tgt_fcid, frame_wwpn, frame_wwnn);
  4063. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  4064. "local tport wwpn: 0x%llx wwnn: 0x%llx. Sending RJT",
  4065. tport->wwpn, tport->wwnn);
  4066. rjt_frame = fdls_alloc_frame(iport);
  4067. if (rjt_frame == NULL) {
  4068. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  4069. "Failed to allocate rjt_frame to send response to ADISC request");
  4070. return;
  4071. }
  4072. prjts_rsp = (struct fc_std_els_rjt_rsp *) (rjt_frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  4073. fdls_init_els_rjt_frame(rjt_frame, iport);
  4074. prjts_rsp->rej.er_reason = 0x03; /* logical error */
  4075. prjts_rsp->rej.er_explan = 0x1E; /* N_port login required */
  4076. prjts_rsp->rej.er_vendor = 0x0;
  4077. FNIC_STD_SET_S_ID(prjts_rsp->fchdr, fchdr->fh_d_id);
  4078. FNIC_STD_SET_D_ID(prjts_rsp->fchdr, fchdr->fh_s_id);
  4079. oxid = FNIC_STD_GET_OX_ID(fchdr);
  4080. FNIC_STD_SET_OX_ID(prjts_rsp->fchdr, oxid);
  4081. fnic_send_fcoe_frame(iport, rjt_frame, rjt_frame_size);
  4082. return;
  4083. }
  4084. acc_frame = fdls_alloc_frame(iport);
  4085. if (acc_frame == NULL) {
  4086. FNIC_FCS_DBG(KERN_ERR, fnic->host, fnic->fnic_num,
  4087. "Failed to allocate frame to send ADISC accept");
  4088. return;
  4089. }
  4090. padisc_acc = (struct fc_std_els_adisc *) (acc_frame + FNIC_ETH_FCOE_HDRS_OFFSET);
  4091. FNIC_STD_SET_S_ID(padisc_acc->fchdr, fchdr->fh_d_id);
  4092. FNIC_STD_SET_D_ID(padisc_acc->fchdr, fchdr->fh_s_id);
  4093. FNIC_STD_SET_F_CTL(padisc_acc->fchdr, FNIC_ELS_REP_FCTL << 16);
  4094. FNIC_STD_SET_R_CTL(padisc_acc->fchdr, FC_RCTL_ELS_REP);
  4095. FNIC_STD_SET_TYPE(padisc_acc->fchdr, FC_TYPE_ELS);
  4096. oxid = FNIC_STD_GET_OX_ID(fchdr);
  4097. FNIC_STD_SET_OX_ID(padisc_acc->fchdr, oxid);
  4098. FNIC_STD_SET_RX_ID(padisc_acc->fchdr, FNIC_UNASSIGNED_RXID);
  4099. padisc_acc->els.adisc_cmd = ELS_LS_ACC;
  4100. FNIC_STD_SET_NPORT_NAME(&padisc_acc->els.adisc_wwpn,
  4101. iport->wwpn);
  4102. FNIC_STD_SET_NODE_NAME(&padisc_acc->els.adisc_wwnn,
  4103. iport->wwnn);
  4104. memcpy(padisc_acc->els.adisc_port_id, fchdr->fh_d_id, 3);
  4105. fnic_send_fcoe_frame(iport, acc_frame, acc_frame_size);
  4106. }
  4107. /*
  4108. * Performs a validation for all FCOE frames and return the frame type
  4109. */
  4110. int
  4111. fnic_fdls_validate_and_get_frame_type(struct fnic_iport_s *iport,
  4112. struct fc_frame_header *fchdr)
  4113. {
  4114. uint8_t type;
  4115. uint8_t *fc_payload;
  4116. uint16_t oxid;
  4117. uint32_t s_id;
  4118. uint32_t d_id;
  4119. struct fnic *fnic = iport->fnic;
  4120. struct fnic_fdls_fabric_s *fabric = &iport->fabric;
  4121. int oxid_frame_type;
  4122. oxid = FNIC_STD_GET_OX_ID(fchdr);
  4123. fc_payload = (uint8_t *) fchdr + sizeof(struct fc_frame_header);
  4124. type = *fc_payload;
  4125. s_id = ntoh24(fchdr->fh_s_id);
  4126. d_id = ntoh24(fchdr->fh_d_id);
  4127. /* some common validation */
  4128. if (fdls_get_state(fabric) > FDLS_STATE_FABRIC_FLOGI) {
  4129. if (iport->fcid != d_id || (!FNIC_FC_FRAME_CS_CTL(fchdr))) {
  4130. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4131. "invalid frame received. Dropping frame");
  4132. return -1;
  4133. }
  4134. }
  4135. /* BLS ABTS response */
  4136. if ((fchdr->fh_r_ctl == FC_RCTL_BA_ACC)
  4137. || (fchdr->fh_r_ctl == FC_RCTL_BA_RJT)) {
  4138. if (!(FNIC_FC_FRAME_TYPE_BLS(fchdr))) {
  4139. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4140. "Received ABTS invalid frame. Dropping frame");
  4141. return -1;
  4142. }
  4143. if (fdls_is_oxid_fabric_req(oxid)) {
  4144. if (!(iport->fabric.flags & FNIC_FDLS_FABRIC_ABORT_ISSUED)) {
  4145. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4146. "Received unexpected ABTS RSP(oxid:0x%x) from 0x%x. Dropping frame",
  4147. oxid, s_id);
  4148. return -1;
  4149. }
  4150. return FNIC_FABRIC_BLS_ABTS_RSP;
  4151. } else if (fdls_is_oxid_fdmi_req(oxid)) {
  4152. return FNIC_FDMI_BLS_ABTS_RSP;
  4153. } else if (fdls_is_oxid_tgt_req(oxid)) {
  4154. return FNIC_TPORT_BLS_ABTS_RSP;
  4155. }
  4156. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4157. "Received ABTS rsp with unknown oxid(0x%x) from 0x%x. Dropping frame",
  4158. oxid, s_id);
  4159. return -1;
  4160. }
  4161. /* BLS ABTS Req */
  4162. if ((fchdr->fh_r_ctl == FC_RCTL_BA_ABTS)
  4163. && (FNIC_FC_FRAME_TYPE_BLS(fchdr))) {
  4164. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4165. "Receiving Abort Request from s_id: 0x%x", s_id);
  4166. return FNIC_BLS_ABTS_REQ;
  4167. }
  4168. /* unsolicited requests frames */
  4169. if (FNIC_FC_FRAME_UNSOLICITED(fchdr)) {
  4170. switch (type) {
  4171. case ELS_LOGO:
  4172. if ((!FNIC_FC_FRAME_FCTL_FIRST_LAST_SEQINIT(fchdr))
  4173. || (!FNIC_FC_FRAME_UNSOLICITED(fchdr))
  4174. || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) {
  4175. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4176. "Received LOGO invalid frame. Dropping frame");
  4177. return -1;
  4178. }
  4179. return FNIC_ELS_LOGO_REQ;
  4180. case ELS_RSCN:
  4181. if ((!FNIC_FC_FRAME_FCTL_FIRST_LAST_SEQINIT(fchdr))
  4182. || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))
  4183. || (!FNIC_FC_FRAME_UNSOLICITED(fchdr))) {
  4184. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4185. "Received RSCN invalid FCTL. Dropping frame");
  4186. return -1;
  4187. }
  4188. if (s_id != FC_FID_FCTRL)
  4189. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4190. "Received RSCN from target FCTL: 0x%x type: 0x%x s_id: 0x%x.",
  4191. fchdr->fh_f_ctl[0], fchdr->fh_type, s_id);
  4192. return FNIC_ELS_RSCN_REQ;
  4193. case ELS_PLOGI:
  4194. return FNIC_ELS_PLOGI_REQ;
  4195. case ELS_ECHO:
  4196. return FNIC_ELS_ECHO_REQ;
  4197. case ELS_ADISC:
  4198. return FNIC_ELS_ADISC;
  4199. case ELS_RLS:
  4200. return FNIC_ELS_RLS;
  4201. case ELS_RRQ:
  4202. return FNIC_ELS_RRQ;
  4203. default:
  4204. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4205. "Unsupported frame (type:0x%02x) from fcid: 0x%x",
  4206. type, s_id);
  4207. return FNIC_ELS_UNSUPPORTED_REQ;
  4208. }
  4209. }
  4210. /* solicited response from fabric or target */
  4211. oxid_frame_type = FNIC_FRAME_TYPE(oxid);
  4212. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4213. "oxid frame code: 0x%x, oxid: 0x%x\n", oxid_frame_type, oxid);
  4214. switch (oxid_frame_type) {
  4215. case FNIC_FRAME_TYPE_FABRIC_FLOGI:
  4216. if (type == ELS_LS_ACC) {
  4217. if ((s_id != FC_FID_FLOGI)
  4218. || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) {
  4219. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4220. "Received unknown frame. Dropping frame");
  4221. return -1;
  4222. }
  4223. }
  4224. return FNIC_FABRIC_FLOGI_RSP;
  4225. case FNIC_FRAME_TYPE_FABRIC_PLOGI:
  4226. if (type == ELS_LS_ACC) {
  4227. if ((s_id != FC_FID_DIR_SERV)
  4228. || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) {
  4229. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4230. "Received unknown frame. Dropping frame");
  4231. return -1;
  4232. }
  4233. }
  4234. return FNIC_FABRIC_PLOGI_RSP;
  4235. case FNIC_FRAME_TYPE_FABRIC_SCR:
  4236. if (type == ELS_LS_ACC) {
  4237. if ((s_id != FC_FID_FCTRL)
  4238. || (!FNIC_FC_FRAME_TYPE_ELS(fchdr))) {
  4239. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4240. "Received unknown frame. Dropping frame");
  4241. return -1;
  4242. }
  4243. }
  4244. return FNIC_FABRIC_SCR_RSP;
  4245. case FNIC_FRAME_TYPE_FABRIC_RPN:
  4246. if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) {
  4247. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4248. "Received unknown frame. Dropping frame");
  4249. return -1;
  4250. }
  4251. return FNIC_FABRIC_RPN_RSP;
  4252. case FNIC_FRAME_TYPE_FABRIC_RFT:
  4253. if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) {
  4254. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4255. "Received unknown frame. Dropping frame");
  4256. return -1;
  4257. }
  4258. return FNIC_FABRIC_RFT_RSP;
  4259. case FNIC_FRAME_TYPE_FABRIC_RFF:
  4260. if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) {
  4261. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4262. "Received unknown frame. Dropping frame");
  4263. return -1;
  4264. }
  4265. return FNIC_FABRIC_RFF_RSP;
  4266. case FNIC_FRAME_TYPE_FABRIC_GPN_FT:
  4267. if ((s_id != FC_FID_DIR_SERV) || (!FNIC_FC_FRAME_TYPE_FC_GS(fchdr))) {
  4268. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4269. "Received unknown frame. Dropping frame");
  4270. return -1;
  4271. }
  4272. return FNIC_FABRIC_GPN_FT_RSP;
  4273. case FNIC_FRAME_TYPE_FABRIC_LOGO:
  4274. return FNIC_FABRIC_LOGO_RSP;
  4275. case FNIC_FRAME_TYPE_FDMI_PLOGI:
  4276. return FNIC_FDMI_PLOGI_RSP;
  4277. case FNIC_FRAME_TYPE_FDMI_RHBA:
  4278. return FNIC_FDMI_REG_HBA_RSP;
  4279. case FNIC_FRAME_TYPE_FDMI_RPA:
  4280. return FNIC_FDMI_RPA_RSP;
  4281. case FNIC_FRAME_TYPE_TGT_PLOGI:
  4282. return FNIC_TPORT_PLOGI_RSP;
  4283. case FNIC_FRAME_TYPE_TGT_PRLI:
  4284. return FNIC_TPORT_PRLI_RSP;
  4285. case FNIC_FRAME_TYPE_TGT_ADISC:
  4286. return FNIC_TPORT_ADISC_RSP;
  4287. case FNIC_FRAME_TYPE_TGT_LOGO:
  4288. if (!FNIC_FC_FRAME_TYPE_ELS(fchdr)) {
  4289. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4290. "Dropping Unknown frame in tport solicited exchange range type: 0x%x.",
  4291. fchdr->fh_type);
  4292. return -1;
  4293. }
  4294. return FNIC_TPORT_LOGO_RSP;
  4295. default:
  4296. /* Drop the Rx frame and log/stats it */
  4297. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4298. "Solicited response: unknown OXID: 0x%x", oxid);
  4299. return -1;
  4300. }
  4301. return -1;
  4302. }
  4303. void fnic_fdls_recv_frame(struct fnic_iport_s *iport, void *rx_frame,
  4304. int len, int fchdr_offset)
  4305. {
  4306. struct fc_frame_header *fchdr;
  4307. uint32_t s_id = 0;
  4308. uint32_t d_id = 0;
  4309. struct fnic *fnic = iport->fnic;
  4310. int frame_type;
  4311. fchdr = (struct fc_frame_header *) ((uint8_t *) rx_frame + fchdr_offset);
  4312. s_id = ntoh24(fchdr->fh_s_id);
  4313. d_id = ntoh24(fchdr->fh_d_id);
  4314. fnic_debug_dump_fc_frame(fnic, fchdr, len, "Incoming");
  4315. frame_type =
  4316. fnic_fdls_validate_and_get_frame_type(iport, fchdr);
  4317. /*if we are in flogo drop everything else */
  4318. if (iport->fabric.state == FDLS_STATE_FABRIC_LOGO &&
  4319. frame_type != FNIC_FABRIC_LOGO_RSP)
  4320. return;
  4321. switch (frame_type) {
  4322. case FNIC_FABRIC_FLOGI_RSP:
  4323. fdls_process_flogi_rsp(iport, fchdr, rx_frame);
  4324. break;
  4325. case FNIC_FABRIC_PLOGI_RSP:
  4326. fdls_process_fabric_plogi_rsp(iport, fchdr);
  4327. break;
  4328. case FNIC_FDMI_PLOGI_RSP:
  4329. fdls_process_fdmi_plogi_rsp(iport, fchdr);
  4330. break;
  4331. case FNIC_FABRIC_RPN_RSP:
  4332. fdls_process_rpn_id_rsp(iport, fchdr);
  4333. break;
  4334. case FNIC_FABRIC_RFT_RSP:
  4335. fdls_process_rft_id_rsp(iport, fchdr);
  4336. break;
  4337. case FNIC_FABRIC_RFF_RSP:
  4338. fdls_process_rff_id_rsp(iport, fchdr);
  4339. break;
  4340. case FNIC_FABRIC_SCR_RSP:
  4341. fdls_process_scr_rsp(iport, fchdr);
  4342. break;
  4343. case FNIC_FABRIC_GPN_FT_RSP:
  4344. fdls_process_gpn_ft_rsp(iport, fchdr, len);
  4345. break;
  4346. case FNIC_TPORT_PLOGI_RSP:
  4347. fdls_process_tgt_plogi_rsp(iport, fchdr);
  4348. break;
  4349. case FNIC_TPORT_PRLI_RSP:
  4350. fdls_process_tgt_prli_rsp(iport, fchdr);
  4351. break;
  4352. case FNIC_TPORT_ADISC_RSP:
  4353. fdls_process_tgt_adisc_rsp(iport, fchdr);
  4354. break;
  4355. case FNIC_TPORT_BLS_ABTS_RSP:
  4356. fdls_process_tgt_abts_rsp(iport, fchdr);
  4357. break;
  4358. case FNIC_TPORT_LOGO_RSP:
  4359. /* Logo response from tgt which we have deleted */
  4360. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4361. "Logo response from tgt: 0x%x",
  4362. ntoh24(fchdr->fh_s_id));
  4363. break;
  4364. case FNIC_FABRIC_LOGO_RSP:
  4365. fdls_process_fabric_logo_rsp(iport, fchdr);
  4366. break;
  4367. case FNIC_FABRIC_BLS_ABTS_RSP:
  4368. fdls_process_fabric_abts_rsp(iport, fchdr);
  4369. break;
  4370. case FNIC_FDMI_BLS_ABTS_RSP:
  4371. fdls_process_fdmi_abts_rsp(iport, fchdr);
  4372. break;
  4373. case FNIC_BLS_ABTS_REQ:
  4374. fdls_process_abts_req(iport, fchdr);
  4375. break;
  4376. case FNIC_ELS_UNSUPPORTED_REQ:
  4377. fdls_process_unsupported_els_req(iport, fchdr);
  4378. break;
  4379. case FNIC_ELS_PLOGI_REQ:
  4380. fdls_process_plogi_req(iport, fchdr);
  4381. break;
  4382. case FNIC_ELS_RSCN_REQ:
  4383. fdls_process_rscn(iport, fchdr);
  4384. break;
  4385. case FNIC_ELS_LOGO_REQ:
  4386. fdls_process_logo_req(iport, fchdr);
  4387. break;
  4388. case FNIC_ELS_RRQ:
  4389. case FNIC_ELS_ECHO_REQ:
  4390. fdls_process_els_req(iport, fchdr, len);
  4391. break;
  4392. case FNIC_ELS_ADISC:
  4393. fdls_process_adisc_req(iport, fchdr);
  4394. break;
  4395. case FNIC_ELS_RLS:
  4396. fdls_process_rls_req(iport, fchdr);
  4397. break;
  4398. case FNIC_FDMI_REG_HBA_RSP:
  4399. case FNIC_FDMI_RPA_RSP:
  4400. fdls_process_fdmi_reg_ack(iport, fchdr, frame_type);
  4401. break;
  4402. default:
  4403. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4404. "s_id: 0x%x d_did: 0x%x", s_id, d_id);
  4405. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4406. "Received unknown FCoE frame of len: %d. Dropping frame", len);
  4407. break;
  4408. }
  4409. }
  4410. void fnic_fdls_disc_init(struct fnic_iport_s *iport)
  4411. {
  4412. fdls_reset_oxid_pool(iport);
  4413. fdls_set_state((&iport->fabric), FDLS_STATE_INIT);
  4414. }
  4415. void fnic_fdls_link_down(struct fnic_iport_s *iport)
  4416. {
  4417. struct fnic_tport_s *tport, *next;
  4418. struct fnic *fnic = iport->fnic;
  4419. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4420. "0x%x: FDLS processing link down", iport->fcid);
  4421. fdls_set_state((&iport->fabric), FDLS_STATE_LINKDOWN);
  4422. iport->fabric.flags = 0;
  4423. spin_unlock_irqrestore(&fnic->fnic_lock, fnic->lock_flags);
  4424. fnic_scsi_fcpio_reset(iport->fnic);
  4425. spin_lock_irqsave(&fnic->fnic_lock, fnic->lock_flags);
  4426. list_for_each_entry_safe(tport, next, &iport->tport_list, links) {
  4427. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4428. "removing rport: 0x%x", tport->fcid);
  4429. fdls_delete_tport(iport, tport);
  4430. }
  4431. if (fnic_fdmi_support == 1) {
  4432. if (iport->fabric.fdmi_pending > 0) {
  4433. timer_delete_sync(&iport->fabric.fdmi_timer);
  4434. iport->fabric.fdmi_pending = 0;
  4435. }
  4436. iport->flags &= ~FNIC_FDMI_ACTIVE;
  4437. }
  4438. FNIC_FCS_DBG(KERN_INFO, fnic->host, fnic->fnic_num,
  4439. "0x%x: FDLS finish processing link down", iport->fcid);
  4440. }