aachba.c 113 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Adaptec AAC series RAID controller driver
  4. * (c) Copyright 2001 Red Hat Inc.
  5. *
  6. * based on the old aacraid driver that is..
  7. * Adaptec aacraid device driver for Linux.
  8. *
  9. * Copyright (c) 2000-2010 Adaptec, Inc.
  10. * 2010-2015 PMC-Sierra, Inc. ([email protected])
  11. * 2016-2017 Microsemi Corp. ([email protected])
  12. *
  13. * Module Name:
  14. * aachba.c
  15. *
  16. * Abstract: Contains Interfaces to manage IOs.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/types.h>
  21. #include <linux/pci.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/slab.h>
  24. #include <linux/completion.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/module.h>
  28. #include <asm/unaligned.h>
  29. #include <scsi/scsi.h>
  30. #include <scsi/scsi_cmnd.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include "aacraid.h"
  34. /* values for inqd_pdt: Peripheral device type in plain English */
  35. #define INQD_PDT_DA 0x00 /* Direct-access (DISK) device */
  36. #define INQD_PDT_PROC 0x03 /* Processor device */
  37. #define INQD_PDT_CHNGR 0x08 /* Changer (jukebox, scsi2) */
  38. #define INQD_PDT_COMM 0x09 /* Communication device (scsi2) */
  39. #define INQD_PDT_NOLUN2 0x1f /* Unknown Device (scsi2) */
  40. #define INQD_PDT_NOLUN 0x7f /* Logical Unit Not Present */
  41. #define INQD_PDT_DMASK 0x1F /* Peripheral Device Type Mask */
  42. #define INQD_PDT_QMASK 0xE0 /* Peripheral Device Qualifer Mask */
  43. /*
  44. * Sense codes
  45. */
  46. #define SENCODE_NO_SENSE 0x00
  47. #define SENCODE_END_OF_DATA 0x00
  48. #define SENCODE_BECOMING_READY 0x04
  49. #define SENCODE_INIT_CMD_REQUIRED 0x04
  50. #define SENCODE_UNRECOVERED_READ_ERROR 0x11
  51. #define SENCODE_PARAM_LIST_LENGTH_ERROR 0x1A
  52. #define SENCODE_INVALID_COMMAND 0x20
  53. #define SENCODE_LBA_OUT_OF_RANGE 0x21
  54. #define SENCODE_INVALID_CDB_FIELD 0x24
  55. #define SENCODE_LUN_NOT_SUPPORTED 0x25
  56. #define SENCODE_INVALID_PARAM_FIELD 0x26
  57. #define SENCODE_PARAM_NOT_SUPPORTED 0x26
  58. #define SENCODE_PARAM_VALUE_INVALID 0x26
  59. #define SENCODE_RESET_OCCURRED 0x29
  60. #define SENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x3E
  61. #define SENCODE_INQUIRY_DATA_CHANGED 0x3F
  62. #define SENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x39
  63. #define SENCODE_DIAGNOSTIC_FAILURE 0x40
  64. #define SENCODE_INTERNAL_TARGET_FAILURE 0x44
  65. #define SENCODE_INVALID_MESSAGE_ERROR 0x49
  66. #define SENCODE_LUN_FAILED_SELF_CONFIG 0x4c
  67. #define SENCODE_OVERLAPPED_COMMAND 0x4E
  68. /*
  69. * Additional sense codes
  70. */
  71. #define ASENCODE_NO_SENSE 0x00
  72. #define ASENCODE_END_OF_DATA 0x05
  73. #define ASENCODE_BECOMING_READY 0x01
  74. #define ASENCODE_INIT_CMD_REQUIRED 0x02
  75. #define ASENCODE_PARAM_LIST_LENGTH_ERROR 0x00
  76. #define ASENCODE_INVALID_COMMAND 0x00
  77. #define ASENCODE_LBA_OUT_OF_RANGE 0x00
  78. #define ASENCODE_INVALID_CDB_FIELD 0x00
  79. #define ASENCODE_LUN_NOT_SUPPORTED 0x00
  80. #define ASENCODE_INVALID_PARAM_FIELD 0x00
  81. #define ASENCODE_PARAM_NOT_SUPPORTED 0x01
  82. #define ASENCODE_PARAM_VALUE_INVALID 0x02
  83. #define ASENCODE_RESET_OCCURRED 0x00
  84. #define ASENCODE_LUN_NOT_SELF_CONFIGURED_YET 0x00
  85. #define ASENCODE_INQUIRY_DATA_CHANGED 0x03
  86. #define ASENCODE_SAVING_PARAMS_NOT_SUPPORTED 0x00
  87. #define ASENCODE_DIAGNOSTIC_FAILURE 0x80
  88. #define ASENCODE_INTERNAL_TARGET_FAILURE 0x00
  89. #define ASENCODE_INVALID_MESSAGE_ERROR 0x00
  90. #define ASENCODE_LUN_FAILED_SELF_CONFIG 0x00
  91. #define ASENCODE_OVERLAPPED_COMMAND 0x00
  92. #define BYTE0(x) (unsigned char)(x)
  93. #define BYTE1(x) (unsigned char)((x) >> 8)
  94. #define BYTE2(x) (unsigned char)((x) >> 16)
  95. #define BYTE3(x) (unsigned char)((x) >> 24)
  96. /* MODE_SENSE data format */
  97. typedef struct {
  98. struct {
  99. u8 data_length;
  100. u8 med_type;
  101. u8 dev_par;
  102. u8 bd_length;
  103. } __attribute__((packed)) hd;
  104. struct {
  105. u8 dens_code;
  106. u8 block_count[3];
  107. u8 reserved;
  108. u8 block_length[3];
  109. } __attribute__((packed)) bd;
  110. u8 mpc_buf[3];
  111. } __attribute__((packed)) aac_modep_data;
  112. /* MODE_SENSE_10 data format */
  113. typedef struct {
  114. struct {
  115. u8 data_length[2];
  116. u8 med_type;
  117. u8 dev_par;
  118. u8 rsrvd[2];
  119. u8 bd_length[2];
  120. } __attribute__((packed)) hd;
  121. struct {
  122. u8 dens_code;
  123. u8 block_count[3];
  124. u8 reserved;
  125. u8 block_length[3];
  126. } __attribute__((packed)) bd;
  127. u8 mpc_buf[3];
  128. } __attribute__((packed)) aac_modep10_data;
  129. /*------------------------------------------------------------------------------
  130. * S T R U C T S / T Y P E D E F S
  131. *----------------------------------------------------------------------------*/
  132. /* SCSI inquiry data */
  133. struct inquiry_data {
  134. u8 inqd_pdt; /* Peripheral qualifier | Peripheral Device Type */
  135. u8 inqd_dtq; /* RMB | Device Type Qualifier */
  136. u8 inqd_ver; /* ISO version | ECMA version | ANSI-approved version */
  137. u8 inqd_rdf; /* AENC | TrmIOP | Response data format */
  138. u8 inqd_len; /* Additional length (n-4) */
  139. u8 inqd_pad1[2];/* Reserved - must be zero */
  140. u8 inqd_pad2; /* RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
  141. u8 inqd_vid[8]; /* Vendor ID */
  142. u8 inqd_pid[16];/* Product ID */
  143. u8 inqd_prl[4]; /* Product Revision Level */
  144. };
  145. /* Added for VPD 0x83 */
  146. struct tvpd_id_descriptor_type_1 {
  147. u8 codeset:4; /* VPD_CODE_SET */
  148. u8 reserved:4;
  149. u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
  150. u8 reserved2:4;
  151. u8 reserved3;
  152. u8 identifierlength;
  153. u8 venid[8];
  154. u8 productid[16];
  155. u8 serialnumber[8]; /* SN in ASCII */
  156. };
  157. struct tvpd_id_descriptor_type_2 {
  158. u8 codeset:4; /* VPD_CODE_SET */
  159. u8 reserved:4;
  160. u8 identifiertype:4; /* VPD_IDENTIFIER_TYPE */
  161. u8 reserved2:4;
  162. u8 reserved3;
  163. u8 identifierlength;
  164. struct teu64id {
  165. u32 Serial;
  166. /* The serial number supposed to be 40 bits,
  167. * bit we only support 32, so make the last byte zero. */
  168. u8 reserved;
  169. u8 venid[3];
  170. } eu64id;
  171. };
  172. struct tvpd_id_descriptor_type_3 {
  173. u8 codeset : 4; /* VPD_CODE_SET */
  174. u8 reserved : 4;
  175. u8 identifiertype : 4; /* VPD_IDENTIFIER_TYPE */
  176. u8 reserved2 : 4;
  177. u8 reserved3;
  178. u8 identifierlength;
  179. u8 Identifier[16];
  180. };
  181. struct tvpd_page83 {
  182. u8 DeviceType:5;
  183. u8 DeviceTypeQualifier:3;
  184. u8 PageCode;
  185. u8 reserved;
  186. u8 PageLength;
  187. struct tvpd_id_descriptor_type_1 type1;
  188. struct tvpd_id_descriptor_type_2 type2;
  189. struct tvpd_id_descriptor_type_3 type3;
  190. };
  191. /*
  192. * M O D U L E G L O B A L S
  193. */
  194. static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *sgmap);
  195. static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg);
  196. static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg);
  197. static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
  198. struct aac_raw_io2 *rio2, int sg_max);
  199. static long aac_build_sghba(struct scsi_cmnd *scsicmd,
  200. struct aac_hba_cmd_req *hbacmd,
  201. int sg_max, u64 sg_address);
  202. static int aac_convert_sgraw2(struct aac_raw_io2 *rio2,
  203. int pages, int nseg, int nseg_new);
  204. static void aac_probe_container_scsi_done(struct scsi_cmnd *scsi_cmnd);
  205. static int aac_send_srb_fib(struct scsi_cmnd* scsicmd);
  206. static int aac_send_hba_fib(struct scsi_cmnd *scsicmd);
  207. #ifdef AAC_DETAILED_STATUS_INFO
  208. static char *aac_get_status_string(u32 status);
  209. #endif
  210. /*
  211. * Non dasd selection is handled entirely in aachba now
  212. */
  213. static int nondasd = -1;
  214. static int aac_cache = 2; /* WCE=0 to avoid performance problems */
  215. static int dacmode = -1;
  216. int aac_msi;
  217. int aac_commit = -1;
  218. int startup_timeout = 180;
  219. int aif_timeout = 120;
  220. int aac_sync_mode; /* Only Sync. transfer - disabled */
  221. static int aac_convert_sgl = 1; /* convert non-conformable s/g list - enabled */
  222. module_param(aac_sync_mode, int, S_IRUGO|S_IWUSR);
  223. MODULE_PARM_DESC(aac_sync_mode, "Force sync. transfer mode"
  224. " 0=off, 1=on");
  225. module_param(aac_convert_sgl, int, S_IRUGO|S_IWUSR);
  226. MODULE_PARM_DESC(aac_convert_sgl, "Convert non-conformable s/g list"
  227. " 0=off, 1=on");
  228. module_param(nondasd, int, S_IRUGO|S_IWUSR);
  229. MODULE_PARM_DESC(nondasd, "Control scanning of hba for nondasd devices."
  230. " 0=off, 1=on");
  231. module_param_named(cache, aac_cache, int, S_IRUGO|S_IWUSR);
  232. MODULE_PARM_DESC(cache, "Disable Queue Flush commands:\n"
  233. "\tbit 0 - Disable FUA in WRITE SCSI commands\n"
  234. "\tbit 1 - Disable SYNCHRONIZE_CACHE SCSI command\n"
  235. "\tbit 2 - Disable only if Battery is protecting Cache");
  236. module_param(dacmode, int, S_IRUGO|S_IWUSR);
  237. MODULE_PARM_DESC(dacmode, "Control whether dma addressing is using 64 bit DAC."
  238. " 0=off, 1=on");
  239. module_param_named(commit, aac_commit, int, S_IRUGO|S_IWUSR);
  240. MODULE_PARM_DESC(commit, "Control whether a COMMIT_CONFIG is issued to the"
  241. " adapter for foreign arrays.\n"
  242. "This is typically needed in systems that do not have a BIOS."
  243. " 0=off, 1=on");
  244. module_param_named(msi, aac_msi, int, S_IRUGO|S_IWUSR);
  245. MODULE_PARM_DESC(msi, "IRQ handling."
  246. " 0=PIC(default), 1=MSI, 2=MSI-X)");
  247. module_param(startup_timeout, int, S_IRUGO|S_IWUSR);
  248. MODULE_PARM_DESC(startup_timeout, "The duration of time in seconds to wait for"
  249. " adapter to have its kernel up and\n"
  250. "running. This is typically adjusted for large systems that do not"
  251. " have a BIOS.");
  252. module_param(aif_timeout, int, S_IRUGO|S_IWUSR);
  253. MODULE_PARM_DESC(aif_timeout, "The duration of time in seconds to wait for"
  254. " applications to pick up AIFs before\n"
  255. "deregistering them. This is typically adjusted for heavily burdened"
  256. " systems.");
  257. int aac_fib_dump;
  258. module_param(aac_fib_dump, int, 0644);
  259. MODULE_PARM_DESC(aac_fib_dump, "Dump controller fibs prior to IOP_RESET 0=off, 1=on");
  260. int numacb = -1;
  261. module_param(numacb, int, S_IRUGO|S_IWUSR);
  262. MODULE_PARM_DESC(numacb, "Request a limit to the number of adapter control"
  263. " blocks (FIB) allocated. Valid values are 512 and down. Default is"
  264. " to use suggestion from Firmware.");
  265. static int acbsize = -1;
  266. module_param(acbsize, int, S_IRUGO|S_IWUSR);
  267. MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB)"
  268. " size. Valid values are 512, 2048, 4096 and 8192. Default is to use"
  269. " suggestion from Firmware.");
  270. int update_interval = 30 * 60;
  271. module_param(update_interval, int, S_IRUGO|S_IWUSR);
  272. MODULE_PARM_DESC(update_interval, "Interval in seconds between time sync"
  273. " updates issued to adapter.");
  274. int check_interval = 60;
  275. module_param(check_interval, int, S_IRUGO|S_IWUSR);
  276. MODULE_PARM_DESC(check_interval, "Interval in seconds between adapter health"
  277. " checks.");
  278. int aac_check_reset = 1;
  279. module_param_named(check_reset, aac_check_reset, int, S_IRUGO|S_IWUSR);
  280. MODULE_PARM_DESC(check_reset, "If adapter fails health check, reset the"
  281. " adapter. a value of -1 forces the reset to adapters programmed to"
  282. " ignore it.");
  283. int expose_physicals = -1;
  284. module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
  285. MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays."
  286. " -1=protect 0=off, 1=on");
  287. int aac_reset_devices;
  288. module_param_named(reset_devices, aac_reset_devices, int, S_IRUGO|S_IWUSR);
  289. MODULE_PARM_DESC(reset_devices, "Force an adapter reset at initialization.");
  290. static int aac_wwn = 1;
  291. module_param_named(wwn, aac_wwn, int, S_IRUGO|S_IWUSR);
  292. MODULE_PARM_DESC(wwn, "Select a WWN type for the arrays:\n"
  293. "\t0 - Disable\n"
  294. "\t1 - Array Meta Data Signature (default)\n"
  295. "\t2 - Adapter Serial Number");
  296. static inline int aac_valid_context(struct scsi_cmnd *scsicmd,
  297. struct fib *fibptr) {
  298. struct scsi_device *device;
  299. if (unlikely(!scsicmd)) {
  300. dprintk((KERN_WARNING "aac_valid_context: scsi command corrupt\n"));
  301. aac_fib_complete(fibptr);
  302. return 0;
  303. }
  304. aac_priv(scsicmd)->owner = AAC_OWNER_MIDLEVEL;
  305. device = scsicmd->device;
  306. if (unlikely(!device)) {
  307. dprintk((KERN_WARNING "aac_valid_context: scsi device corrupt\n"));
  308. aac_fib_complete(fibptr);
  309. return 0;
  310. }
  311. return 1;
  312. }
  313. /**
  314. * aac_get_config_status - check the adapter configuration
  315. * @dev: aac driver data
  316. * @commit_flag: force sending CT_COMMIT_CONFIG
  317. *
  318. * Query config status, and commit the configuration if needed.
  319. */
  320. int aac_get_config_status(struct aac_dev *dev, int commit_flag)
  321. {
  322. int status = 0;
  323. struct fib * fibptr;
  324. if (!(fibptr = aac_fib_alloc(dev)))
  325. return -ENOMEM;
  326. aac_fib_init(fibptr);
  327. {
  328. struct aac_get_config_status *dinfo;
  329. dinfo = (struct aac_get_config_status *) fib_data(fibptr);
  330. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  331. dinfo->type = cpu_to_le32(CT_GET_CONFIG_STATUS);
  332. dinfo->count = cpu_to_le32(sizeof(((struct aac_get_config_status_resp *)NULL)->data));
  333. }
  334. status = aac_fib_send(ContainerCommand,
  335. fibptr,
  336. sizeof (struct aac_get_config_status),
  337. FsaNormal,
  338. 1, 1,
  339. NULL, NULL);
  340. if (status < 0) {
  341. printk(KERN_WARNING "aac_get_config_status: SendFIB failed.\n");
  342. } else {
  343. struct aac_get_config_status_resp *reply
  344. = (struct aac_get_config_status_resp *) fib_data(fibptr);
  345. dprintk((KERN_WARNING
  346. "aac_get_config_status: response=%d status=%d action=%d\n",
  347. le32_to_cpu(reply->response),
  348. le32_to_cpu(reply->status),
  349. le32_to_cpu(reply->data.action)));
  350. if ((le32_to_cpu(reply->response) != ST_OK) ||
  351. (le32_to_cpu(reply->status) != CT_OK) ||
  352. (le32_to_cpu(reply->data.action) > CFACT_PAUSE)) {
  353. printk(KERN_WARNING "aac_get_config_status: Will not issue the Commit Configuration\n");
  354. status = -EINVAL;
  355. }
  356. }
  357. /* Do not set XferState to zero unless receives a response from F/W */
  358. if (status >= 0)
  359. aac_fib_complete(fibptr);
  360. /* Send a CT_COMMIT_CONFIG to enable discovery of devices */
  361. if (status >= 0) {
  362. if ((aac_commit == 1) || commit_flag) {
  363. struct aac_commit_config * dinfo;
  364. aac_fib_init(fibptr);
  365. dinfo = (struct aac_commit_config *) fib_data(fibptr);
  366. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  367. dinfo->type = cpu_to_le32(CT_COMMIT_CONFIG);
  368. status = aac_fib_send(ContainerCommand,
  369. fibptr,
  370. sizeof (struct aac_commit_config),
  371. FsaNormal,
  372. 1, 1,
  373. NULL, NULL);
  374. /* Do not set XferState to zero unless
  375. * receives a response from F/W */
  376. if (status >= 0)
  377. aac_fib_complete(fibptr);
  378. } else if (aac_commit == 0) {
  379. printk(KERN_WARNING
  380. "aac_get_config_status: Foreign device configurations are being ignored\n");
  381. }
  382. }
  383. /* FIB should be freed only after getting the response from the F/W */
  384. if (status != -ERESTARTSYS)
  385. aac_fib_free(fibptr);
  386. return status;
  387. }
  388. static void aac_expose_phy_device(struct scsi_cmnd *scsicmd)
  389. {
  390. char inq_data;
  391. scsi_sg_copy_to_buffer(scsicmd, &inq_data, sizeof(inq_data));
  392. if ((inq_data & 0x20) && (inq_data & 0x1f) == TYPE_DISK) {
  393. inq_data &= 0xdf;
  394. scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
  395. }
  396. }
  397. /**
  398. * aac_get_containers - list containers
  399. * @dev: aac driver data
  400. *
  401. * Make a list of all containers on this controller
  402. */
  403. int aac_get_containers(struct aac_dev *dev)
  404. {
  405. struct fsa_dev_info *fsa_dev_ptr;
  406. u32 index;
  407. int status = 0;
  408. struct fib * fibptr;
  409. struct aac_get_container_count *dinfo;
  410. struct aac_get_container_count_resp *dresp;
  411. int maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
  412. if (!(fibptr = aac_fib_alloc(dev)))
  413. return -ENOMEM;
  414. aac_fib_init(fibptr);
  415. dinfo = (struct aac_get_container_count *) fib_data(fibptr);
  416. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  417. dinfo->type = cpu_to_le32(CT_GET_CONTAINER_COUNT);
  418. status = aac_fib_send(ContainerCommand,
  419. fibptr,
  420. sizeof (struct aac_get_container_count),
  421. FsaNormal,
  422. 1, 1,
  423. NULL, NULL);
  424. if (status >= 0) {
  425. dresp = (struct aac_get_container_count_resp *)fib_data(fibptr);
  426. maximum_num_containers = le32_to_cpu(dresp->ContainerSwitchEntries);
  427. if (fibptr->dev->supplement_adapter_info.supported_options2 &
  428. AAC_OPTION_SUPPORTED_240_VOLUMES) {
  429. maximum_num_containers =
  430. le32_to_cpu(dresp->MaxSimpleVolumes);
  431. }
  432. aac_fib_complete(fibptr);
  433. }
  434. /* FIB should be freed only after getting the response from the F/W */
  435. if (status != -ERESTARTSYS)
  436. aac_fib_free(fibptr);
  437. if (maximum_num_containers < MAXIMUM_NUM_CONTAINERS)
  438. maximum_num_containers = MAXIMUM_NUM_CONTAINERS;
  439. if (dev->fsa_dev == NULL ||
  440. dev->maximum_num_containers != maximum_num_containers) {
  441. fsa_dev_ptr = dev->fsa_dev;
  442. dev->fsa_dev = kcalloc(maximum_num_containers,
  443. sizeof(*fsa_dev_ptr), GFP_KERNEL);
  444. kfree(fsa_dev_ptr);
  445. fsa_dev_ptr = NULL;
  446. if (!dev->fsa_dev)
  447. return -ENOMEM;
  448. dev->maximum_num_containers = maximum_num_containers;
  449. }
  450. for (index = 0; index < dev->maximum_num_containers; index++) {
  451. dev->fsa_dev[index].devname[0] = '\0';
  452. dev->fsa_dev[index].valid = 0;
  453. status = aac_probe_container(dev, index);
  454. if (status < 0) {
  455. printk(KERN_WARNING "aac_get_containers: SendFIB failed.\n");
  456. break;
  457. }
  458. }
  459. return status;
  460. }
  461. static void aac_scsi_done(struct scsi_cmnd *scmd)
  462. {
  463. if (scmd->device->request_queue) {
  464. /* SCSI command has been submitted by the SCSI mid-layer. */
  465. scsi_done(scmd);
  466. } else {
  467. /* SCSI command has been submitted by aac_probe_container(). */
  468. aac_probe_container_scsi_done(scmd);
  469. }
  470. }
  471. static void get_container_name_callback(void *context, struct fib * fibptr)
  472. {
  473. struct aac_get_name_resp * get_name_reply;
  474. struct scsi_cmnd * scsicmd;
  475. scsicmd = (struct scsi_cmnd *) context;
  476. if (!aac_valid_context(scsicmd, fibptr))
  477. return;
  478. dprintk((KERN_DEBUG "get_container_name_callback[cpu %d]: t = %ld.\n", smp_processor_id(), jiffies));
  479. BUG_ON(fibptr == NULL);
  480. get_name_reply = (struct aac_get_name_resp *) fib_data(fibptr);
  481. /* Failure is irrelevant, using default value instead */
  482. if ((le32_to_cpu(get_name_reply->status) == CT_OK)
  483. && (get_name_reply->data[0] != '\0')) {
  484. char *sp = get_name_reply->data;
  485. int data_size = sizeof_field(struct aac_get_name_resp, data);
  486. sp[data_size - 1] = '\0';
  487. while (*sp == ' ')
  488. ++sp;
  489. if (*sp) {
  490. struct inquiry_data inq;
  491. char d[sizeof(((struct inquiry_data *)NULL)->inqd_pid)];
  492. int count = sizeof(d);
  493. char *dp = d;
  494. do {
  495. *dp++ = (*sp) ? *sp++ : ' ';
  496. } while (--count > 0);
  497. scsi_sg_copy_to_buffer(scsicmd, &inq, sizeof(inq));
  498. memcpy(inq.inqd_pid, d, sizeof(d));
  499. scsi_sg_copy_from_buffer(scsicmd, &inq, sizeof(inq));
  500. }
  501. }
  502. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  503. aac_fib_complete(fibptr);
  504. aac_scsi_done(scsicmd);
  505. }
  506. /*
  507. * aac_get_container_name - get container name, none blocking.
  508. */
  509. static int aac_get_container_name(struct scsi_cmnd * scsicmd)
  510. {
  511. int status;
  512. int data_size;
  513. struct aac_get_name *dinfo;
  514. struct fib * cmd_fibcontext;
  515. struct aac_dev * dev;
  516. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  517. data_size = sizeof_field(struct aac_get_name_resp, data);
  518. cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
  519. aac_fib_init(cmd_fibcontext);
  520. dinfo = (struct aac_get_name *) fib_data(cmd_fibcontext);
  521. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  522. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  523. dinfo->type = cpu_to_le32(CT_READ_NAME);
  524. dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
  525. dinfo->count = cpu_to_le32(data_size - 1);
  526. status = aac_fib_send(ContainerCommand,
  527. cmd_fibcontext,
  528. sizeof(struct aac_get_name_resp),
  529. FsaNormal,
  530. 0, 1,
  531. (fib_callback)get_container_name_callback,
  532. (void *) scsicmd);
  533. /*
  534. * Check that the command queued to the controller
  535. */
  536. if (status == -EINPROGRESS)
  537. return 0;
  538. printk(KERN_WARNING "aac_get_container_name: aac_fib_send failed with status: %d.\n", status);
  539. aac_fib_complete(cmd_fibcontext);
  540. return -1;
  541. }
  542. static int aac_probe_container_callback2(struct scsi_cmnd * scsicmd)
  543. {
  544. struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
  545. if ((fsa_dev_ptr[scmd_id(scsicmd)].valid & 1))
  546. return aac_scsi_cmd(scsicmd);
  547. scsicmd->result = DID_NO_CONNECT << 16;
  548. aac_scsi_done(scsicmd);
  549. return 0;
  550. }
  551. static void _aac_probe_container2(void * context, struct fib * fibptr)
  552. {
  553. struct fsa_dev_info *fsa_dev_ptr;
  554. int (*callback)(struct scsi_cmnd *);
  555. struct scsi_cmnd *scsicmd = context;
  556. struct aac_cmd_priv *cmd_priv = aac_priv(scsicmd);
  557. int i;
  558. if (!aac_valid_context(scsicmd, fibptr))
  559. return;
  560. cmd_priv->status = 0;
  561. fsa_dev_ptr = fibptr->dev->fsa_dev;
  562. if (fsa_dev_ptr) {
  563. struct aac_mount * dresp = (struct aac_mount *) fib_data(fibptr);
  564. __le32 sup_options2;
  565. fsa_dev_ptr += scmd_id(scsicmd);
  566. sup_options2 =
  567. fibptr->dev->supplement_adapter_info.supported_options2;
  568. if ((le32_to_cpu(dresp->status) == ST_OK) &&
  569. (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE) &&
  570. (le32_to_cpu(dresp->mnt[0].state) != FSCS_HIDDEN)) {
  571. if (!(sup_options2 & AAC_OPTION_VARIABLE_BLOCK_SIZE)) {
  572. dresp->mnt[0].fileinfo.bdevinfo.block_size = 0x200;
  573. fsa_dev_ptr->block_size = 0x200;
  574. } else {
  575. fsa_dev_ptr->block_size =
  576. le32_to_cpu(dresp->mnt[0].fileinfo.bdevinfo.block_size);
  577. }
  578. for (i = 0; i < 16; i++)
  579. fsa_dev_ptr->identifier[i] =
  580. dresp->mnt[0].fileinfo.bdevinfo
  581. .identifier[i];
  582. fsa_dev_ptr->valid = 1;
  583. /* sense_key holds the current state of the spin-up */
  584. if (dresp->mnt[0].state & cpu_to_le32(FSCS_NOT_READY))
  585. fsa_dev_ptr->sense_data.sense_key = NOT_READY;
  586. else if (fsa_dev_ptr->sense_data.sense_key == NOT_READY)
  587. fsa_dev_ptr->sense_data.sense_key = NO_SENSE;
  588. fsa_dev_ptr->type = le32_to_cpu(dresp->mnt[0].vol);
  589. fsa_dev_ptr->size
  590. = ((u64)le32_to_cpu(dresp->mnt[0].capacity)) +
  591. (((u64)le32_to_cpu(dresp->mnt[0].capacityhigh)) << 32);
  592. fsa_dev_ptr->ro = ((le32_to_cpu(dresp->mnt[0].state) & FSCS_READONLY) != 0);
  593. }
  594. if ((fsa_dev_ptr->valid & 1) == 0)
  595. fsa_dev_ptr->valid = 0;
  596. cmd_priv->status = le32_to_cpu(dresp->count);
  597. }
  598. aac_fib_complete(fibptr);
  599. aac_fib_free(fibptr);
  600. callback = cmd_priv->callback;
  601. cmd_priv->callback = NULL;
  602. (*callback)(scsicmd);
  603. return;
  604. }
  605. static void _aac_probe_container1(void * context, struct fib * fibptr)
  606. {
  607. struct scsi_cmnd * scsicmd;
  608. struct aac_mount * dresp;
  609. struct aac_query_mount *dinfo;
  610. int status;
  611. dresp = (struct aac_mount *) fib_data(fibptr);
  612. if (!aac_supports_2T(fibptr->dev)) {
  613. dresp->mnt[0].capacityhigh = 0;
  614. if ((le32_to_cpu(dresp->status) == ST_OK) &&
  615. (le32_to_cpu(dresp->mnt[0].vol) != CT_NONE)) {
  616. _aac_probe_container2(context, fibptr);
  617. return;
  618. }
  619. }
  620. scsicmd = (struct scsi_cmnd *) context;
  621. if (!aac_valid_context(scsicmd, fibptr))
  622. return;
  623. aac_fib_init(fibptr);
  624. dinfo = (struct aac_query_mount *)fib_data(fibptr);
  625. if (fibptr->dev->supplement_adapter_info.supported_options2 &
  626. AAC_OPTION_VARIABLE_BLOCK_SIZE)
  627. dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
  628. else
  629. dinfo->command = cpu_to_le32(VM_NameServe64);
  630. dinfo->count = cpu_to_le32(scmd_id(scsicmd));
  631. dinfo->type = cpu_to_le32(FT_FILESYS);
  632. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  633. status = aac_fib_send(ContainerCommand,
  634. fibptr,
  635. sizeof(struct aac_query_mount),
  636. FsaNormal,
  637. 0, 1,
  638. _aac_probe_container2,
  639. (void *) scsicmd);
  640. /*
  641. * Check that the command queued to the controller
  642. */
  643. if (status < 0 && status != -EINPROGRESS) {
  644. /* Inherit results from VM_NameServe, if any */
  645. dresp->status = cpu_to_le32(ST_OK);
  646. _aac_probe_container2(context, fibptr);
  647. }
  648. }
  649. static int _aac_probe_container(struct scsi_cmnd * scsicmd, int (*callback)(struct scsi_cmnd *))
  650. {
  651. struct aac_cmd_priv *cmd_priv = aac_priv(scsicmd);
  652. struct fib * fibptr;
  653. int status = -ENOMEM;
  654. if ((fibptr = aac_fib_alloc((struct aac_dev *)scsicmd->device->host->hostdata))) {
  655. struct aac_query_mount *dinfo;
  656. aac_fib_init(fibptr);
  657. dinfo = (struct aac_query_mount *)fib_data(fibptr);
  658. if (fibptr->dev->supplement_adapter_info.supported_options2 &
  659. AAC_OPTION_VARIABLE_BLOCK_SIZE)
  660. dinfo->command = cpu_to_le32(VM_NameServeAllBlk);
  661. else
  662. dinfo->command = cpu_to_le32(VM_NameServe);
  663. dinfo->count = cpu_to_le32(scmd_id(scsicmd));
  664. dinfo->type = cpu_to_le32(FT_FILESYS);
  665. cmd_priv->callback = callback;
  666. cmd_priv->owner = AAC_OWNER_FIRMWARE;
  667. status = aac_fib_send(ContainerCommand,
  668. fibptr,
  669. sizeof(struct aac_query_mount),
  670. FsaNormal,
  671. 0, 1,
  672. _aac_probe_container1,
  673. (void *) scsicmd);
  674. /*
  675. * Check that the command queued to the controller
  676. */
  677. if (status == -EINPROGRESS)
  678. return 0;
  679. if (status < 0) {
  680. cmd_priv->callback = NULL;
  681. aac_fib_complete(fibptr);
  682. aac_fib_free(fibptr);
  683. }
  684. }
  685. if (status < 0) {
  686. struct fsa_dev_info *fsa_dev_ptr = ((struct aac_dev *)(scsicmd->device->host->hostdata))->fsa_dev;
  687. if (fsa_dev_ptr) {
  688. fsa_dev_ptr += scmd_id(scsicmd);
  689. if ((fsa_dev_ptr->valid & 1) == 0) {
  690. fsa_dev_ptr->valid = 0;
  691. return (*callback)(scsicmd);
  692. }
  693. }
  694. }
  695. return status;
  696. }
  697. /**
  698. * aac_probe_container_callback1 - query a logical volume
  699. * @scsicmd: the scsi command block
  700. *
  701. * Queries the controller about the given volume. The volume information
  702. * is updated in the struct fsa_dev_info structure rather than returned.
  703. */
  704. static int aac_probe_container_callback1(struct scsi_cmnd * scsicmd)
  705. {
  706. scsicmd->device = NULL;
  707. return 0;
  708. }
  709. static void aac_probe_container_scsi_done(struct scsi_cmnd *scsi_cmnd)
  710. {
  711. aac_probe_container_callback1(scsi_cmnd);
  712. }
  713. int aac_probe_container(struct aac_dev *dev, int cid)
  714. {
  715. struct aac_cmd_priv *cmd_priv;
  716. struct scsi_cmnd *scsicmd = kzalloc(sizeof(*scsicmd) + sizeof(*cmd_priv), GFP_KERNEL);
  717. struct scsi_device *scsidev = kzalloc(sizeof(*scsidev), GFP_KERNEL);
  718. int status;
  719. if (!scsicmd || !scsidev) {
  720. kfree(scsicmd);
  721. kfree(scsidev);
  722. return -ENOMEM;
  723. }
  724. scsicmd->device = scsidev;
  725. scsidev->sdev_state = 0;
  726. scsidev->id = cid;
  727. scsidev->host = dev->scsi_host_ptr;
  728. if (_aac_probe_container(scsicmd, aac_probe_container_callback1) == 0)
  729. while (scsicmd->device == scsidev)
  730. schedule();
  731. kfree(scsidev);
  732. cmd_priv = aac_priv(scsicmd);
  733. status = cmd_priv->status;
  734. kfree(scsicmd);
  735. return status;
  736. }
  737. /* Local Structure to set SCSI inquiry data strings */
  738. struct scsi_inq {
  739. char vid[8]; /* Vendor ID */
  740. char pid[16]; /* Product ID */
  741. char prl[4]; /* Product Revision Level */
  742. };
  743. /**
  744. * inqstrcpy - string merge
  745. * @a: string to copy from
  746. * @b: string to copy to
  747. *
  748. * Copy a String from one location to another
  749. * without copying \0
  750. */
  751. static void inqstrcpy(char *a, char *b)
  752. {
  753. while (*a != (char)0)
  754. *b++ = *a++;
  755. }
  756. static char *container_types[] = {
  757. "None",
  758. "Volume",
  759. "Mirror",
  760. "Stripe",
  761. "RAID5",
  762. "SSRW",
  763. "SSRO",
  764. "Morph",
  765. "Legacy",
  766. "RAID4",
  767. "RAID10",
  768. "RAID00",
  769. "V-MIRRORS",
  770. "PSEUDO R4",
  771. "RAID50",
  772. "RAID5D",
  773. "RAID5D0",
  774. "RAID1E",
  775. "RAID6",
  776. "RAID60",
  777. "Unknown"
  778. };
  779. char * get_container_type(unsigned tindex)
  780. {
  781. if (tindex >= ARRAY_SIZE(container_types))
  782. tindex = ARRAY_SIZE(container_types) - 1;
  783. return container_types[tindex];
  784. }
  785. /* Function: setinqstr
  786. *
  787. * Arguments: [1] pointer to void [1] int
  788. *
  789. * Purpose: Sets SCSI inquiry data strings for vendor, product
  790. * and revision level. Allows strings to be set in platform dependent
  791. * files instead of in OS dependent driver source.
  792. */
  793. static void setinqstr(struct aac_dev *dev, void *data, int tindex)
  794. {
  795. struct scsi_inq *str;
  796. struct aac_supplement_adapter_info *sup_adap_info;
  797. sup_adap_info = &dev->supplement_adapter_info;
  798. str = (struct scsi_inq *)(data); /* cast data to scsi inq block */
  799. memset(str, ' ', sizeof(*str));
  800. if (sup_adap_info->adapter_type_text[0]) {
  801. int c;
  802. char *cp;
  803. char *cname = kmemdup(sup_adap_info->adapter_type_text,
  804. sizeof(sup_adap_info->adapter_type_text),
  805. GFP_ATOMIC);
  806. if (!cname)
  807. return;
  808. cp = cname;
  809. if ((cp[0] == 'A') && (cp[1] == 'O') && (cp[2] == 'C'))
  810. inqstrcpy("SMC", str->vid);
  811. else {
  812. c = sizeof(str->vid);
  813. while (*cp && *cp != ' ' && --c)
  814. ++cp;
  815. c = *cp;
  816. *cp = '\0';
  817. inqstrcpy(cname, str->vid);
  818. *cp = c;
  819. while (*cp && *cp != ' ')
  820. ++cp;
  821. }
  822. while (*cp == ' ')
  823. ++cp;
  824. /* last six chars reserved for vol type */
  825. if (strlen(cp) > sizeof(str->pid))
  826. cp[sizeof(str->pid)] = '\0';
  827. inqstrcpy (cp, str->pid);
  828. kfree(cname);
  829. } else {
  830. struct aac_driver_ident *mp = aac_get_driver_ident(dev->cardtype);
  831. inqstrcpy (mp->vname, str->vid);
  832. /* last six chars reserved for vol type */
  833. inqstrcpy (mp->model, str->pid);
  834. }
  835. if (tindex < ARRAY_SIZE(container_types)){
  836. char *findit = str->pid;
  837. for ( ; *findit != ' '; findit++); /* walk till we find a space */
  838. /* RAID is superfluous in the context of a RAID device */
  839. if (memcmp(findit-4, "RAID", 4) == 0)
  840. *(findit -= 4) = ' ';
  841. if (((findit - str->pid) + strlen(container_types[tindex]))
  842. < (sizeof(str->pid) + sizeof(str->prl)))
  843. inqstrcpy (container_types[tindex], findit + 1);
  844. }
  845. inqstrcpy ("V1.0", str->prl);
  846. }
  847. static void build_vpd83_type3(struct tvpd_page83 *vpdpage83data,
  848. struct aac_dev *dev, struct scsi_cmnd *scsicmd)
  849. {
  850. int container;
  851. vpdpage83data->type3.codeset = 1;
  852. vpdpage83data->type3.identifiertype = 3;
  853. vpdpage83data->type3.identifierlength = sizeof(vpdpage83data->type3)
  854. - 4;
  855. for (container = 0; container < dev->maximum_num_containers;
  856. container++) {
  857. if (scmd_id(scsicmd) == container) {
  858. memcpy(vpdpage83data->type3.Identifier,
  859. dev->fsa_dev[container].identifier,
  860. 16);
  861. break;
  862. }
  863. }
  864. }
  865. static void get_container_serial_callback(void *context, struct fib * fibptr)
  866. {
  867. struct aac_get_serial_resp * get_serial_reply;
  868. struct scsi_cmnd * scsicmd;
  869. BUG_ON(fibptr == NULL);
  870. scsicmd = (struct scsi_cmnd *) context;
  871. if (!aac_valid_context(scsicmd, fibptr))
  872. return;
  873. get_serial_reply = (struct aac_get_serial_resp *) fib_data(fibptr);
  874. /* Failure is irrelevant, using default value instead */
  875. if (le32_to_cpu(get_serial_reply->status) == CT_OK) {
  876. /*Check to see if it's for VPD 0x83 or 0x80 */
  877. if (scsicmd->cmnd[2] == 0x83) {
  878. /* vpd page 0x83 - Device Identification Page */
  879. struct aac_dev *dev;
  880. int i;
  881. struct tvpd_page83 vpdpage83data;
  882. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  883. memset(((u8 *)&vpdpage83data), 0,
  884. sizeof(vpdpage83data));
  885. /* DIRECT_ACCESS_DEVIC */
  886. vpdpage83data.DeviceType = 0;
  887. /* DEVICE_CONNECTED */
  888. vpdpage83data.DeviceTypeQualifier = 0;
  889. /* VPD_DEVICE_IDENTIFIERS */
  890. vpdpage83data.PageCode = 0x83;
  891. vpdpage83data.reserved = 0;
  892. vpdpage83data.PageLength =
  893. sizeof(vpdpage83data.type1) +
  894. sizeof(vpdpage83data.type2);
  895. /* VPD 83 Type 3 is not supported for ARC */
  896. if (dev->sa_firmware)
  897. vpdpage83data.PageLength +=
  898. sizeof(vpdpage83data.type3);
  899. /* T10 Vendor Identifier Field Format */
  900. /* VpdcodesetAscii */
  901. vpdpage83data.type1.codeset = 2;
  902. /* VpdIdentifierTypeVendorId */
  903. vpdpage83data.type1.identifiertype = 1;
  904. vpdpage83data.type1.identifierlength =
  905. sizeof(vpdpage83data.type1) - 4;
  906. /* "ADAPTEC " for adaptec */
  907. memcpy(vpdpage83data.type1.venid,
  908. "ADAPTEC ",
  909. sizeof(vpdpage83data.type1.venid));
  910. memcpy(vpdpage83data.type1.productid,
  911. "ARRAY ",
  912. sizeof(
  913. vpdpage83data.type1.productid));
  914. /* Convert to ascii based serial number.
  915. * The LSB is the end.
  916. */
  917. for (i = 0; i < 8; i++) {
  918. u8 temp =
  919. (u8)((get_serial_reply->uid >> ((7 - i) * 4)) & 0xF);
  920. if (temp > 0x9) {
  921. vpdpage83data.type1.serialnumber[i] =
  922. 'A' + (temp - 0xA);
  923. } else {
  924. vpdpage83data.type1.serialnumber[i] =
  925. '0' + temp;
  926. }
  927. }
  928. /* VpdCodeSetBinary */
  929. vpdpage83data.type2.codeset = 1;
  930. /* VpdidentifiertypeEUI64 */
  931. vpdpage83data.type2.identifiertype = 2;
  932. vpdpage83data.type2.identifierlength =
  933. sizeof(vpdpage83data.type2) - 4;
  934. vpdpage83data.type2.eu64id.venid[0] = 0xD0;
  935. vpdpage83data.type2.eu64id.venid[1] = 0;
  936. vpdpage83data.type2.eu64id.venid[2] = 0;
  937. vpdpage83data.type2.eu64id.Serial =
  938. get_serial_reply->uid;
  939. vpdpage83data.type2.eu64id.reserved = 0;
  940. /*
  941. * VpdIdentifierTypeFCPHName
  942. * VPD 0x83 Type 3 not supported for ARC
  943. */
  944. if (dev->sa_firmware) {
  945. build_vpd83_type3(&vpdpage83data,
  946. dev, scsicmd);
  947. }
  948. /* Move the inquiry data to the response buffer. */
  949. scsi_sg_copy_from_buffer(scsicmd, &vpdpage83data,
  950. sizeof(vpdpage83data));
  951. } else {
  952. /* It must be for VPD 0x80 */
  953. char sp[13];
  954. /* EVPD bit set */
  955. sp[0] = INQD_PDT_DA;
  956. sp[1] = scsicmd->cmnd[2];
  957. sp[2] = 0;
  958. sp[3] = snprintf(sp+4, sizeof(sp)-4, "%08X",
  959. le32_to_cpu(get_serial_reply->uid));
  960. scsi_sg_copy_from_buffer(scsicmd, sp,
  961. sizeof(sp));
  962. }
  963. }
  964. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  965. aac_fib_complete(fibptr);
  966. aac_scsi_done(scsicmd);
  967. }
  968. /*
  969. * aac_get_container_serial - get container serial, none blocking.
  970. */
  971. static int aac_get_container_serial(struct scsi_cmnd * scsicmd)
  972. {
  973. int status;
  974. struct aac_get_serial *dinfo;
  975. struct fib * cmd_fibcontext;
  976. struct aac_dev * dev;
  977. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  978. cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
  979. aac_fib_init(cmd_fibcontext);
  980. dinfo = (struct aac_get_serial *) fib_data(cmd_fibcontext);
  981. dinfo->command = cpu_to_le32(VM_ContainerConfig);
  982. dinfo->type = cpu_to_le32(CT_CID_TO_32BITS_UID);
  983. dinfo->cid = cpu_to_le32(scmd_id(scsicmd));
  984. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  985. status = aac_fib_send(ContainerCommand,
  986. cmd_fibcontext,
  987. sizeof(struct aac_get_serial_resp),
  988. FsaNormal,
  989. 0, 1,
  990. (fib_callback) get_container_serial_callback,
  991. (void *) scsicmd);
  992. /*
  993. * Check that the command queued to the controller
  994. */
  995. if (status == -EINPROGRESS)
  996. return 0;
  997. printk(KERN_WARNING "aac_get_container_serial: aac_fib_send failed with status: %d.\n", status);
  998. aac_fib_complete(cmd_fibcontext);
  999. return -1;
  1000. }
  1001. /* Function: setinqserial
  1002. *
  1003. * Arguments: [1] pointer to void [1] int
  1004. *
  1005. * Purpose: Sets SCSI Unit Serial number.
  1006. * This is a fake. We should read a proper
  1007. * serial number from the container. <SuSE>But
  1008. * without docs it's quite hard to do it :-)
  1009. * So this will have to do in the meantime.</SuSE>
  1010. */
  1011. static int setinqserial(struct aac_dev *dev, void *data, int cid)
  1012. {
  1013. /*
  1014. * This breaks array migration.
  1015. */
  1016. return snprintf((char *)(data), sizeof(struct scsi_inq) - 4, "%08X%02X",
  1017. le32_to_cpu(dev->adapter_info.serial[0]), cid);
  1018. }
  1019. static inline void set_sense(struct sense_data *sense_data, u8 sense_key,
  1020. u8 sense_code, u8 a_sense_code, u8 bit_pointer, u16 field_pointer)
  1021. {
  1022. u8 *sense_buf = (u8 *)sense_data;
  1023. /* Sense data valid, err code 70h */
  1024. sense_buf[0] = 0x70; /* No info field */
  1025. sense_buf[1] = 0; /* Segment number, always zero */
  1026. sense_buf[2] = sense_key; /* Sense key */
  1027. sense_buf[12] = sense_code; /* Additional sense code */
  1028. sense_buf[13] = a_sense_code; /* Additional sense code qualifier */
  1029. if (sense_key == ILLEGAL_REQUEST) {
  1030. sense_buf[7] = 10; /* Additional sense length */
  1031. sense_buf[15] = bit_pointer;
  1032. /* Illegal parameter is in the parameter block */
  1033. if (sense_code == SENCODE_INVALID_CDB_FIELD)
  1034. sense_buf[15] |= 0xc0;/* Std sense key specific field */
  1035. /* Illegal parameter is in the CDB block */
  1036. sense_buf[16] = field_pointer >> 8; /* MSB */
  1037. sense_buf[17] = field_pointer; /* LSB */
  1038. } else
  1039. sense_buf[7] = 6; /* Additional sense length */
  1040. }
  1041. static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
  1042. {
  1043. if (lba & 0xffffffff00000000LL) {
  1044. int cid = scmd_id(cmd);
  1045. dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
  1046. cmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  1047. set_sense(&dev->fsa_dev[cid].sense_data,
  1048. HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
  1049. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
  1050. memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  1051. min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
  1052. SCSI_SENSE_BUFFERSIZE));
  1053. aac_scsi_done(cmd);
  1054. return 1;
  1055. }
  1056. return 0;
  1057. }
  1058. static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
  1059. {
  1060. return 0;
  1061. }
  1062. static void io_callback(void *context, struct fib * fibptr);
  1063. static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  1064. {
  1065. struct aac_dev *dev = fib->dev;
  1066. u16 fibsize, command;
  1067. long ret;
  1068. aac_fib_init(fib);
  1069. if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
  1070. dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
  1071. !dev->sync_mode) {
  1072. struct aac_raw_io2 *readcmd2;
  1073. readcmd2 = (struct aac_raw_io2 *) fib_data(fib);
  1074. memset(readcmd2, 0, sizeof(struct aac_raw_io2));
  1075. readcmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
  1076. readcmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
  1077. readcmd2->byteCount = cpu_to_le32(count *
  1078. dev->fsa_dev[scmd_id(cmd)].block_size);
  1079. readcmd2->cid = cpu_to_le16(scmd_id(cmd));
  1080. readcmd2->flags = cpu_to_le16(RIO2_IO_TYPE_READ);
  1081. ret = aac_build_sgraw2(cmd, readcmd2,
  1082. dev->scsi_host_ptr->sg_tablesize);
  1083. if (ret < 0)
  1084. return ret;
  1085. command = ContainerRawIo2;
  1086. fibsize = struct_size(readcmd2, sge,
  1087. le32_to_cpu(readcmd2->sgeCnt));
  1088. } else {
  1089. struct aac_raw_io *readcmd;
  1090. readcmd = (struct aac_raw_io *) fib_data(fib);
  1091. readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
  1092. readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
  1093. readcmd->count = cpu_to_le32(count *
  1094. dev->fsa_dev[scmd_id(cmd)].block_size);
  1095. readcmd->cid = cpu_to_le16(scmd_id(cmd));
  1096. readcmd->flags = cpu_to_le16(RIO_TYPE_READ);
  1097. readcmd->bpTotal = 0;
  1098. readcmd->bpComplete = 0;
  1099. ret = aac_build_sgraw(cmd, &readcmd->sg);
  1100. if (ret < 0)
  1101. return ret;
  1102. command = ContainerRawIo;
  1103. fibsize = sizeof(struct aac_raw_io) +
  1104. ((le32_to_cpu(readcmd->sg.count)-1) * sizeof(struct sgentryraw));
  1105. }
  1106. BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
  1107. /*
  1108. * Now send the Fib to the adapter
  1109. */
  1110. return aac_fib_send(command,
  1111. fib,
  1112. fibsize,
  1113. FsaNormal,
  1114. 0, 1,
  1115. (fib_callback) io_callback,
  1116. (void *) cmd);
  1117. }
  1118. static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  1119. {
  1120. u16 fibsize;
  1121. struct aac_read64 *readcmd;
  1122. long ret;
  1123. aac_fib_init(fib);
  1124. readcmd = (struct aac_read64 *) fib_data(fib);
  1125. readcmd->command = cpu_to_le32(VM_CtHostRead64);
  1126. readcmd->cid = cpu_to_le16(scmd_id(cmd));
  1127. readcmd->sector_count = cpu_to_le16(count);
  1128. readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  1129. readcmd->pad = 0;
  1130. readcmd->flags = 0;
  1131. ret = aac_build_sg64(cmd, &readcmd->sg);
  1132. if (ret < 0)
  1133. return ret;
  1134. fibsize = sizeof(struct aac_read64) +
  1135. ((le32_to_cpu(readcmd->sg.count) - 1) *
  1136. sizeof (struct sgentry64));
  1137. BUG_ON (fibsize > (fib->dev->max_fib_size -
  1138. sizeof(struct aac_fibhdr)));
  1139. /*
  1140. * Now send the Fib to the adapter
  1141. */
  1142. return aac_fib_send(ContainerCommand64,
  1143. fib,
  1144. fibsize,
  1145. FsaNormal,
  1146. 0, 1,
  1147. (fib_callback) io_callback,
  1148. (void *) cmd);
  1149. }
  1150. static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
  1151. {
  1152. u16 fibsize;
  1153. struct aac_read *readcmd;
  1154. struct aac_dev *dev = fib->dev;
  1155. long ret;
  1156. aac_fib_init(fib);
  1157. readcmd = (struct aac_read *) fib_data(fib);
  1158. readcmd->command = cpu_to_le32(VM_CtBlockRead);
  1159. readcmd->cid = cpu_to_le32(scmd_id(cmd));
  1160. readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  1161. readcmd->count = cpu_to_le32(count *
  1162. dev->fsa_dev[scmd_id(cmd)].block_size);
  1163. ret = aac_build_sg(cmd, &readcmd->sg);
  1164. if (ret < 0)
  1165. return ret;
  1166. fibsize = sizeof(struct aac_read) +
  1167. ((le32_to_cpu(readcmd->sg.count) - 1) *
  1168. sizeof (struct sgentry));
  1169. BUG_ON (fibsize > (fib->dev->max_fib_size -
  1170. sizeof(struct aac_fibhdr)));
  1171. /*
  1172. * Now send the Fib to the adapter
  1173. */
  1174. return aac_fib_send(ContainerCommand,
  1175. fib,
  1176. fibsize,
  1177. FsaNormal,
  1178. 0, 1,
  1179. (fib_callback) io_callback,
  1180. (void *) cmd);
  1181. }
  1182. static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
  1183. {
  1184. struct aac_dev *dev = fib->dev;
  1185. u16 fibsize, command;
  1186. long ret;
  1187. aac_fib_init(fib);
  1188. if ((dev->comm_interface == AAC_COMM_MESSAGE_TYPE2 ||
  1189. dev->comm_interface == AAC_COMM_MESSAGE_TYPE3) &&
  1190. !dev->sync_mode) {
  1191. struct aac_raw_io2 *writecmd2;
  1192. writecmd2 = (struct aac_raw_io2 *) fib_data(fib);
  1193. memset(writecmd2, 0, sizeof(struct aac_raw_io2));
  1194. writecmd2->blockLow = cpu_to_le32((u32)(lba&0xffffffff));
  1195. writecmd2->blockHigh = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
  1196. writecmd2->byteCount = cpu_to_le32(count *
  1197. dev->fsa_dev[scmd_id(cmd)].block_size);
  1198. writecmd2->cid = cpu_to_le16(scmd_id(cmd));
  1199. writecmd2->flags = (fua && ((aac_cache & 5) != 1) &&
  1200. (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
  1201. cpu_to_le16(RIO2_IO_TYPE_WRITE|RIO2_IO_SUREWRITE) :
  1202. cpu_to_le16(RIO2_IO_TYPE_WRITE);
  1203. ret = aac_build_sgraw2(cmd, writecmd2,
  1204. dev->scsi_host_ptr->sg_tablesize);
  1205. if (ret < 0)
  1206. return ret;
  1207. command = ContainerRawIo2;
  1208. fibsize = struct_size(writecmd2, sge,
  1209. le32_to_cpu(writecmd2->sgeCnt));
  1210. } else {
  1211. struct aac_raw_io *writecmd;
  1212. writecmd = (struct aac_raw_io *) fib_data(fib);
  1213. writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
  1214. writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
  1215. writecmd->count = cpu_to_le32(count *
  1216. dev->fsa_dev[scmd_id(cmd)].block_size);
  1217. writecmd->cid = cpu_to_le16(scmd_id(cmd));
  1218. writecmd->flags = (fua && ((aac_cache & 5) != 1) &&
  1219. (((aac_cache & 5) != 5) || !fib->dev->cache_protected)) ?
  1220. cpu_to_le16(RIO_TYPE_WRITE|RIO_SUREWRITE) :
  1221. cpu_to_le16(RIO_TYPE_WRITE);
  1222. writecmd->bpTotal = 0;
  1223. writecmd->bpComplete = 0;
  1224. ret = aac_build_sgraw(cmd, &writecmd->sg);
  1225. if (ret < 0)
  1226. return ret;
  1227. command = ContainerRawIo;
  1228. fibsize = sizeof(struct aac_raw_io) +
  1229. ((le32_to_cpu(writecmd->sg.count)-1) * sizeof (struct sgentryraw));
  1230. }
  1231. BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
  1232. /*
  1233. * Now send the Fib to the adapter
  1234. */
  1235. return aac_fib_send(command,
  1236. fib,
  1237. fibsize,
  1238. FsaNormal,
  1239. 0, 1,
  1240. (fib_callback) io_callback,
  1241. (void *) cmd);
  1242. }
  1243. static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
  1244. {
  1245. u16 fibsize;
  1246. struct aac_write64 *writecmd;
  1247. long ret;
  1248. aac_fib_init(fib);
  1249. writecmd = (struct aac_write64 *) fib_data(fib);
  1250. writecmd->command = cpu_to_le32(VM_CtHostWrite64);
  1251. writecmd->cid = cpu_to_le16(scmd_id(cmd));
  1252. writecmd->sector_count = cpu_to_le16(count);
  1253. writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  1254. writecmd->pad = 0;
  1255. writecmd->flags = 0;
  1256. ret = aac_build_sg64(cmd, &writecmd->sg);
  1257. if (ret < 0)
  1258. return ret;
  1259. fibsize = sizeof(struct aac_write64) +
  1260. ((le32_to_cpu(writecmd->sg.count) - 1) *
  1261. sizeof (struct sgentry64));
  1262. BUG_ON (fibsize > (fib->dev->max_fib_size -
  1263. sizeof(struct aac_fibhdr)));
  1264. /*
  1265. * Now send the Fib to the adapter
  1266. */
  1267. return aac_fib_send(ContainerCommand64,
  1268. fib,
  1269. fibsize,
  1270. FsaNormal,
  1271. 0, 1,
  1272. (fib_callback) io_callback,
  1273. (void *) cmd);
  1274. }
  1275. static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count, int fua)
  1276. {
  1277. u16 fibsize;
  1278. struct aac_write *writecmd;
  1279. struct aac_dev *dev = fib->dev;
  1280. long ret;
  1281. aac_fib_init(fib);
  1282. writecmd = (struct aac_write *) fib_data(fib);
  1283. writecmd->command = cpu_to_le32(VM_CtBlockWrite);
  1284. writecmd->cid = cpu_to_le32(scmd_id(cmd));
  1285. writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
  1286. writecmd->count = cpu_to_le32(count *
  1287. dev->fsa_dev[scmd_id(cmd)].block_size);
  1288. writecmd->sg.count = cpu_to_le32(1);
  1289. /* ->stable is not used - it did mean which type of write */
  1290. ret = aac_build_sg(cmd, &writecmd->sg);
  1291. if (ret < 0)
  1292. return ret;
  1293. fibsize = sizeof(struct aac_write) +
  1294. ((le32_to_cpu(writecmd->sg.count) - 1) *
  1295. sizeof (struct sgentry));
  1296. BUG_ON (fibsize > (fib->dev->max_fib_size -
  1297. sizeof(struct aac_fibhdr)));
  1298. /*
  1299. * Now send the Fib to the adapter
  1300. */
  1301. return aac_fib_send(ContainerCommand,
  1302. fib,
  1303. fibsize,
  1304. FsaNormal,
  1305. 0, 1,
  1306. (fib_callback) io_callback,
  1307. (void *) cmd);
  1308. }
  1309. static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
  1310. {
  1311. struct aac_srb * srbcmd;
  1312. u32 flag;
  1313. u32 timeout;
  1314. struct aac_dev *dev = fib->dev;
  1315. aac_fib_init(fib);
  1316. switch(cmd->sc_data_direction){
  1317. case DMA_TO_DEVICE:
  1318. flag = SRB_DataOut;
  1319. break;
  1320. case DMA_BIDIRECTIONAL:
  1321. flag = SRB_DataIn | SRB_DataOut;
  1322. break;
  1323. case DMA_FROM_DEVICE:
  1324. flag = SRB_DataIn;
  1325. break;
  1326. case DMA_NONE:
  1327. default: /* shuts up some versions of gcc */
  1328. flag = SRB_NoDataXfer;
  1329. break;
  1330. }
  1331. srbcmd = (struct aac_srb*) fib_data(fib);
  1332. srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
  1333. srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
  1334. srbcmd->id = cpu_to_le32(scmd_id(cmd));
  1335. srbcmd->lun = cpu_to_le32(cmd->device->lun);
  1336. srbcmd->flags = cpu_to_le32(flag);
  1337. timeout = scsi_cmd_to_rq(cmd)->timeout / HZ;
  1338. if (timeout == 0)
  1339. timeout = (dev->sa_firmware ? AAC_SA_TIMEOUT : AAC_ARC_TIMEOUT);
  1340. srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
  1341. srbcmd->retry_limit = 0; /* Obsolete parameter */
  1342. srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
  1343. return srbcmd;
  1344. }
  1345. static struct aac_hba_cmd_req *aac_construct_hbacmd(struct fib *fib,
  1346. struct scsi_cmnd *cmd)
  1347. {
  1348. struct aac_hba_cmd_req *hbacmd;
  1349. struct aac_dev *dev;
  1350. int bus, target;
  1351. u64 address;
  1352. dev = (struct aac_dev *)cmd->device->host->hostdata;
  1353. hbacmd = (struct aac_hba_cmd_req *)fib->hw_fib_va;
  1354. memset(hbacmd, 0, 96); /* sizeof(*hbacmd) is not necessary */
  1355. /* iu_type is a parameter of aac_hba_send */
  1356. switch (cmd->sc_data_direction) {
  1357. case DMA_TO_DEVICE:
  1358. hbacmd->byte1 = 2;
  1359. break;
  1360. case DMA_FROM_DEVICE:
  1361. case DMA_BIDIRECTIONAL:
  1362. hbacmd->byte1 = 1;
  1363. break;
  1364. case DMA_NONE:
  1365. default:
  1366. break;
  1367. }
  1368. hbacmd->lun[1] = cpu_to_le32(cmd->device->lun);
  1369. bus = aac_logical_to_phys(scmd_channel(cmd));
  1370. target = scmd_id(cmd);
  1371. hbacmd->it_nexus = dev->hba_map[bus][target].rmw_nexus;
  1372. /* we fill in reply_qid later in aac_src_deliver_message */
  1373. /* we fill in iu_type, request_id later in aac_hba_send */
  1374. /* we fill in emb_data_desc_count later in aac_build_sghba */
  1375. memcpy(hbacmd->cdb, cmd->cmnd, cmd->cmd_len);
  1376. hbacmd->data_length = cpu_to_le32(scsi_bufflen(cmd));
  1377. address = (u64)fib->hw_error_pa;
  1378. hbacmd->error_ptr_hi = cpu_to_le32((u32)(address >> 32));
  1379. hbacmd->error_ptr_lo = cpu_to_le32((u32)(address & 0xffffffff));
  1380. hbacmd->error_length = cpu_to_le32(FW_ERROR_BUFFER_SIZE);
  1381. return hbacmd;
  1382. }
  1383. static void aac_srb_callback(void *context, struct fib * fibptr);
  1384. static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
  1385. {
  1386. u16 fibsize;
  1387. struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
  1388. long ret;
  1389. ret = aac_build_sg64(cmd, (struct sgmap64 *) &srbcmd->sg);
  1390. if (ret < 0)
  1391. return ret;
  1392. srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
  1393. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  1394. memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
  1395. /*
  1396. * Build Scatter/Gather list
  1397. */
  1398. fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
  1399. ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
  1400. sizeof (struct sgentry64));
  1401. BUG_ON (fibsize > (fib->dev->max_fib_size -
  1402. sizeof(struct aac_fibhdr)));
  1403. /*
  1404. * Now send the Fib to the adapter
  1405. */
  1406. return aac_fib_send(ScsiPortCommand64, fib,
  1407. fibsize, FsaNormal, 0, 1,
  1408. (fib_callback) aac_srb_callback,
  1409. (void *) cmd);
  1410. }
  1411. static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
  1412. {
  1413. u16 fibsize;
  1414. struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
  1415. long ret;
  1416. ret = aac_build_sg(cmd, (struct sgmap *)&srbcmd->sg);
  1417. if (ret < 0)
  1418. return ret;
  1419. srbcmd->count = cpu_to_le32(scsi_bufflen(cmd));
  1420. memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
  1421. memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
  1422. /*
  1423. * Build Scatter/Gather list
  1424. */
  1425. fibsize = sizeof (struct aac_srb) +
  1426. (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
  1427. sizeof (struct sgentry));
  1428. BUG_ON (fibsize > (fib->dev->max_fib_size -
  1429. sizeof(struct aac_fibhdr)));
  1430. /*
  1431. * Now send the Fib to the adapter
  1432. */
  1433. return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
  1434. (fib_callback) aac_srb_callback, (void *) cmd);
  1435. }
  1436. static int aac_scsi_32_64(struct fib * fib, struct scsi_cmnd * cmd)
  1437. {
  1438. if ((sizeof(dma_addr_t) > 4) && fib->dev->needs_dac &&
  1439. (fib->dev->adapter_info.options & AAC_OPT_SGMAP_HOST64))
  1440. return FAILED;
  1441. return aac_scsi_32(fib, cmd);
  1442. }
  1443. static int aac_adapter_hba(struct fib *fib, struct scsi_cmnd *cmd)
  1444. {
  1445. struct aac_hba_cmd_req *hbacmd = aac_construct_hbacmd(fib, cmd);
  1446. struct aac_dev *dev;
  1447. long ret;
  1448. dev = (struct aac_dev *)cmd->device->host->hostdata;
  1449. ret = aac_build_sghba(cmd, hbacmd,
  1450. dev->scsi_host_ptr->sg_tablesize, (u64)fib->hw_sgl_pa);
  1451. if (ret < 0)
  1452. return ret;
  1453. /*
  1454. * Now send the HBA command to the adapter
  1455. */
  1456. fib->hbacmd_size = 64 + le32_to_cpu(hbacmd->emb_data_desc_count) *
  1457. sizeof(struct aac_hba_sgl);
  1458. return aac_hba_send(HBA_IU_TYPE_SCSI_CMD_REQ, fib,
  1459. (fib_callback) aac_hba_callback,
  1460. (void *) cmd);
  1461. }
  1462. static int aac_send_safw_bmic_cmd(struct aac_dev *dev,
  1463. struct aac_srb_unit *srbu, void *xfer_buf, int xfer_len)
  1464. {
  1465. struct fib *fibptr;
  1466. dma_addr_t addr;
  1467. int rcode;
  1468. int fibsize;
  1469. struct aac_srb *srb;
  1470. struct aac_srb_reply *srb_reply;
  1471. struct sgmap64 *sg64;
  1472. u32 vbus;
  1473. u32 vid;
  1474. if (!dev->sa_firmware)
  1475. return 0;
  1476. /* allocate FIB */
  1477. fibptr = aac_fib_alloc(dev);
  1478. if (!fibptr)
  1479. return -ENOMEM;
  1480. aac_fib_init(fibptr);
  1481. fibptr->hw_fib_va->header.XferState &=
  1482. ~cpu_to_le32(FastResponseCapable);
  1483. fibsize = sizeof(struct aac_srb) - sizeof(struct sgentry) +
  1484. sizeof(struct sgentry64);
  1485. /* allocate DMA buffer for response */
  1486. addr = dma_map_single(&dev->pdev->dev, xfer_buf, xfer_len,
  1487. DMA_BIDIRECTIONAL);
  1488. if (dma_mapping_error(&dev->pdev->dev, addr)) {
  1489. rcode = -ENOMEM;
  1490. goto fib_error;
  1491. }
  1492. srb = fib_data(fibptr);
  1493. memcpy(srb, &srbu->srb, sizeof(struct aac_srb));
  1494. vbus = (u32)le16_to_cpu(
  1495. dev->supplement_adapter_info.virt_device_bus);
  1496. vid = (u32)le16_to_cpu(
  1497. dev->supplement_adapter_info.virt_device_target);
  1498. /* set the common request fields */
  1499. srb->channel = cpu_to_le32(vbus);
  1500. srb->id = cpu_to_le32(vid);
  1501. srb->lun = 0;
  1502. srb->function = cpu_to_le32(SRBF_ExecuteScsi);
  1503. srb->timeout = 0;
  1504. srb->retry_limit = 0;
  1505. srb->cdb_size = cpu_to_le32(16);
  1506. srb->count = cpu_to_le32(xfer_len);
  1507. sg64 = (struct sgmap64 *)&srb->sg;
  1508. sg64->count = cpu_to_le32(1);
  1509. sg64->sg[0].addr[1] = cpu_to_le32(upper_32_bits(addr));
  1510. sg64->sg[0].addr[0] = cpu_to_le32(lower_32_bits(addr));
  1511. sg64->sg[0].count = cpu_to_le32(xfer_len);
  1512. /*
  1513. * Copy the updated data for other dumping or other usage if needed
  1514. */
  1515. memcpy(&srbu->srb, srb, sizeof(struct aac_srb));
  1516. /* issue request to the controller */
  1517. rcode = aac_fib_send(ScsiPortCommand64, fibptr, fibsize, FsaNormal,
  1518. 1, 1, NULL, NULL);
  1519. if (rcode == -ERESTARTSYS)
  1520. rcode = -ERESTART;
  1521. if (unlikely(rcode < 0))
  1522. goto bmic_error;
  1523. srb_reply = (struct aac_srb_reply *)fib_data(fibptr);
  1524. memcpy(&srbu->srb_reply, srb_reply, sizeof(struct aac_srb_reply));
  1525. bmic_error:
  1526. dma_unmap_single(&dev->pdev->dev, addr, xfer_len, DMA_BIDIRECTIONAL);
  1527. fib_error:
  1528. aac_fib_complete(fibptr);
  1529. aac_fib_free(fibptr);
  1530. return rcode;
  1531. }
  1532. static void aac_set_safw_target_qd(struct aac_dev *dev, int bus, int target)
  1533. {
  1534. struct aac_ciss_identify_pd *identify_resp;
  1535. if (dev->hba_map[bus][target].devtype != AAC_DEVTYPE_NATIVE_RAW)
  1536. return;
  1537. identify_resp = dev->hba_map[bus][target].safw_identify_resp;
  1538. if (identify_resp == NULL) {
  1539. dev->hba_map[bus][target].qd_limit = 32;
  1540. return;
  1541. }
  1542. if (identify_resp->current_queue_depth_limit <= 0 ||
  1543. identify_resp->current_queue_depth_limit > 255)
  1544. dev->hba_map[bus][target].qd_limit = 32;
  1545. else
  1546. dev->hba_map[bus][target].qd_limit =
  1547. identify_resp->current_queue_depth_limit;
  1548. }
  1549. static int aac_issue_safw_bmic_identify(struct aac_dev *dev,
  1550. struct aac_ciss_identify_pd **identify_resp, u32 bus, u32 target)
  1551. {
  1552. int rcode = -ENOMEM;
  1553. int datasize;
  1554. struct aac_srb_unit srbu;
  1555. struct aac_srb *srbcmd;
  1556. struct aac_ciss_identify_pd *identify_reply;
  1557. datasize = sizeof(struct aac_ciss_identify_pd);
  1558. identify_reply = kmalloc(datasize, GFP_KERNEL);
  1559. if (!identify_reply)
  1560. goto out;
  1561. memset(&srbu, 0, sizeof(struct aac_srb_unit));
  1562. srbcmd = &srbu.srb;
  1563. srbcmd->flags = cpu_to_le32(SRB_DataIn);
  1564. srbcmd->cdb[0] = 0x26;
  1565. srbcmd->cdb[2] = (u8)((AAC_MAX_LUN + target) & 0x00FF);
  1566. srbcmd->cdb[6] = CISS_IDENTIFY_PHYSICAL_DEVICE;
  1567. rcode = aac_send_safw_bmic_cmd(dev, &srbu, identify_reply, datasize);
  1568. if (unlikely(rcode < 0))
  1569. goto mem_free_all;
  1570. *identify_resp = identify_reply;
  1571. out:
  1572. return rcode;
  1573. mem_free_all:
  1574. kfree(identify_reply);
  1575. goto out;
  1576. }
  1577. static inline void aac_free_safw_ciss_luns(struct aac_dev *dev)
  1578. {
  1579. kfree(dev->safw_phys_luns);
  1580. dev->safw_phys_luns = NULL;
  1581. }
  1582. /**
  1583. * aac_get_safw_ciss_luns() - Process topology change
  1584. * @dev: aac_dev structure
  1585. *
  1586. * Execute a CISS REPORT PHYS LUNS and process the results into
  1587. * the current hba_map.
  1588. */
  1589. static int aac_get_safw_ciss_luns(struct aac_dev *dev)
  1590. {
  1591. int rcode = -ENOMEM;
  1592. int datasize;
  1593. struct aac_srb *srbcmd;
  1594. struct aac_srb_unit srbu;
  1595. struct aac_ciss_phys_luns_resp *phys_luns;
  1596. datasize = sizeof(struct aac_ciss_phys_luns_resp) +
  1597. (AAC_MAX_TARGETS - 1) * sizeof(struct _ciss_lun);
  1598. phys_luns = kmalloc(datasize, GFP_KERNEL);
  1599. if (phys_luns == NULL)
  1600. goto out;
  1601. memset(&srbu, 0, sizeof(struct aac_srb_unit));
  1602. srbcmd = &srbu.srb;
  1603. srbcmd->flags = cpu_to_le32(SRB_DataIn);
  1604. srbcmd->cdb[0] = CISS_REPORT_PHYSICAL_LUNS;
  1605. srbcmd->cdb[1] = 2; /* extended reporting */
  1606. srbcmd->cdb[8] = (u8)(datasize >> 8);
  1607. srbcmd->cdb[9] = (u8)(datasize);
  1608. rcode = aac_send_safw_bmic_cmd(dev, &srbu, phys_luns, datasize);
  1609. if (unlikely(rcode < 0))
  1610. goto mem_free_all;
  1611. if (phys_luns->resp_flag != 2) {
  1612. rcode = -ENOMSG;
  1613. goto mem_free_all;
  1614. }
  1615. dev->safw_phys_luns = phys_luns;
  1616. out:
  1617. return rcode;
  1618. mem_free_all:
  1619. kfree(phys_luns);
  1620. goto out;
  1621. }
  1622. static inline u32 aac_get_safw_phys_lun_count(struct aac_dev *dev)
  1623. {
  1624. return get_unaligned_be32(&dev->safw_phys_luns->list_length[0])/24;
  1625. }
  1626. static inline u32 aac_get_safw_phys_bus(struct aac_dev *dev, int lun)
  1627. {
  1628. return dev->safw_phys_luns->lun[lun].level2[1] & 0x3f;
  1629. }
  1630. static inline u32 aac_get_safw_phys_target(struct aac_dev *dev, int lun)
  1631. {
  1632. return dev->safw_phys_luns->lun[lun].level2[0];
  1633. }
  1634. static inline u32 aac_get_safw_phys_expose_flag(struct aac_dev *dev, int lun)
  1635. {
  1636. return dev->safw_phys_luns->lun[lun].bus >> 6;
  1637. }
  1638. static inline u32 aac_get_safw_phys_attribs(struct aac_dev *dev, int lun)
  1639. {
  1640. return dev->safw_phys_luns->lun[lun].node_ident[9];
  1641. }
  1642. static inline u32 aac_get_safw_phys_nexus(struct aac_dev *dev, int lun)
  1643. {
  1644. return *((u32 *)&dev->safw_phys_luns->lun[lun].node_ident[12]);
  1645. }
  1646. static inline void aac_free_safw_identify_resp(struct aac_dev *dev,
  1647. int bus, int target)
  1648. {
  1649. kfree(dev->hba_map[bus][target].safw_identify_resp);
  1650. dev->hba_map[bus][target].safw_identify_resp = NULL;
  1651. }
  1652. static inline void aac_free_safw_all_identify_resp(struct aac_dev *dev,
  1653. int lun_count)
  1654. {
  1655. int luns;
  1656. int i;
  1657. u32 bus;
  1658. u32 target;
  1659. luns = aac_get_safw_phys_lun_count(dev);
  1660. if (luns < lun_count)
  1661. lun_count = luns;
  1662. else if (lun_count < 0)
  1663. lun_count = luns;
  1664. for (i = 0; i < lun_count; i++) {
  1665. bus = aac_get_safw_phys_bus(dev, i);
  1666. target = aac_get_safw_phys_target(dev, i);
  1667. aac_free_safw_identify_resp(dev, bus, target);
  1668. }
  1669. }
  1670. static int aac_get_safw_attr_all_targets(struct aac_dev *dev)
  1671. {
  1672. int i;
  1673. int rcode = 0;
  1674. u32 lun_count;
  1675. u32 bus;
  1676. u32 target;
  1677. struct aac_ciss_identify_pd *identify_resp = NULL;
  1678. lun_count = aac_get_safw_phys_lun_count(dev);
  1679. for (i = 0; i < lun_count; ++i) {
  1680. bus = aac_get_safw_phys_bus(dev, i);
  1681. target = aac_get_safw_phys_target(dev, i);
  1682. rcode = aac_issue_safw_bmic_identify(dev,
  1683. &identify_resp, bus, target);
  1684. if (unlikely(rcode < 0))
  1685. goto free_identify_resp;
  1686. dev->hba_map[bus][target].safw_identify_resp = identify_resp;
  1687. }
  1688. out:
  1689. return rcode;
  1690. free_identify_resp:
  1691. aac_free_safw_all_identify_resp(dev, i);
  1692. goto out;
  1693. }
  1694. /**
  1695. * aac_set_safw_attr_all_targets- update current hba map with data from FW
  1696. * @dev: aac_dev structure
  1697. *
  1698. * Update our hba map with the information gathered from the FW
  1699. */
  1700. static void aac_set_safw_attr_all_targets(struct aac_dev *dev)
  1701. {
  1702. /* ok and extended reporting */
  1703. u32 lun_count, nexus;
  1704. u32 i, bus, target;
  1705. u8 expose_flag, attribs;
  1706. lun_count = aac_get_safw_phys_lun_count(dev);
  1707. dev->scan_counter++;
  1708. for (i = 0; i < lun_count; ++i) {
  1709. bus = aac_get_safw_phys_bus(dev, i);
  1710. target = aac_get_safw_phys_target(dev, i);
  1711. expose_flag = aac_get_safw_phys_expose_flag(dev, i);
  1712. attribs = aac_get_safw_phys_attribs(dev, i);
  1713. nexus = aac_get_safw_phys_nexus(dev, i);
  1714. if (bus >= AAC_MAX_BUSES || target >= AAC_MAX_TARGETS)
  1715. continue;
  1716. if (expose_flag != 0) {
  1717. dev->hba_map[bus][target].devtype =
  1718. AAC_DEVTYPE_RAID_MEMBER;
  1719. continue;
  1720. }
  1721. if (nexus != 0 && (attribs & 8)) {
  1722. dev->hba_map[bus][target].devtype =
  1723. AAC_DEVTYPE_NATIVE_RAW;
  1724. dev->hba_map[bus][target].rmw_nexus =
  1725. nexus;
  1726. } else
  1727. dev->hba_map[bus][target].devtype =
  1728. AAC_DEVTYPE_ARC_RAW;
  1729. dev->hba_map[bus][target].scan_counter = dev->scan_counter;
  1730. aac_set_safw_target_qd(dev, bus, target);
  1731. }
  1732. }
  1733. static int aac_setup_safw_targets(struct aac_dev *dev)
  1734. {
  1735. int rcode = 0;
  1736. rcode = aac_get_containers(dev);
  1737. if (unlikely(rcode < 0))
  1738. goto out;
  1739. rcode = aac_get_safw_ciss_luns(dev);
  1740. if (unlikely(rcode < 0))
  1741. goto out;
  1742. rcode = aac_get_safw_attr_all_targets(dev);
  1743. if (unlikely(rcode < 0))
  1744. goto free_ciss_luns;
  1745. aac_set_safw_attr_all_targets(dev);
  1746. aac_free_safw_all_identify_resp(dev, -1);
  1747. free_ciss_luns:
  1748. aac_free_safw_ciss_luns(dev);
  1749. out:
  1750. return rcode;
  1751. }
  1752. int aac_setup_safw_adapter(struct aac_dev *dev)
  1753. {
  1754. return aac_setup_safw_targets(dev);
  1755. }
  1756. int aac_get_adapter_info(struct aac_dev* dev)
  1757. {
  1758. struct fib* fibptr;
  1759. int rcode;
  1760. u32 tmp, bus, target;
  1761. struct aac_adapter_info *info;
  1762. struct aac_bus_info *command;
  1763. struct aac_bus_info_response *bus_info;
  1764. if (!(fibptr = aac_fib_alloc(dev)))
  1765. return -ENOMEM;
  1766. aac_fib_init(fibptr);
  1767. info = (struct aac_adapter_info *) fib_data(fibptr);
  1768. memset(info,0,sizeof(*info));
  1769. rcode = aac_fib_send(RequestAdapterInfo,
  1770. fibptr,
  1771. sizeof(*info),
  1772. FsaNormal,
  1773. -1, 1, /* First `interrupt' command uses special wait */
  1774. NULL,
  1775. NULL);
  1776. if (rcode < 0) {
  1777. /* FIB should be freed only after
  1778. * getting the response from the F/W */
  1779. if (rcode != -ERESTARTSYS) {
  1780. aac_fib_complete(fibptr);
  1781. aac_fib_free(fibptr);
  1782. }
  1783. return rcode;
  1784. }
  1785. memcpy(&dev->adapter_info, info, sizeof(*info));
  1786. dev->supplement_adapter_info.virt_device_bus = 0xffff;
  1787. if (dev->adapter_info.options & AAC_OPT_SUPPLEMENT_ADAPTER_INFO) {
  1788. struct aac_supplement_adapter_info * sinfo;
  1789. aac_fib_init(fibptr);
  1790. sinfo = (struct aac_supplement_adapter_info *) fib_data(fibptr);
  1791. memset(sinfo,0,sizeof(*sinfo));
  1792. rcode = aac_fib_send(RequestSupplementAdapterInfo,
  1793. fibptr,
  1794. sizeof(*sinfo),
  1795. FsaNormal,
  1796. 1, 1,
  1797. NULL,
  1798. NULL);
  1799. if (rcode >= 0)
  1800. memcpy(&dev->supplement_adapter_info, sinfo, sizeof(*sinfo));
  1801. if (rcode == -ERESTARTSYS) {
  1802. fibptr = aac_fib_alloc(dev);
  1803. if (!fibptr)
  1804. return -ENOMEM;
  1805. }
  1806. }
  1807. /* reset all previous mapped devices (i.e. for init. after IOP_RESET) */
  1808. for (bus = 0; bus < AAC_MAX_BUSES; bus++) {
  1809. for (target = 0; target < AAC_MAX_TARGETS; target++) {
  1810. dev->hba_map[bus][target].devtype = 0;
  1811. dev->hba_map[bus][target].qd_limit = 0;
  1812. }
  1813. }
  1814. /*
  1815. * GetBusInfo
  1816. */
  1817. aac_fib_init(fibptr);
  1818. bus_info = (struct aac_bus_info_response *) fib_data(fibptr);
  1819. memset(bus_info, 0, sizeof(*bus_info));
  1820. command = (struct aac_bus_info *)bus_info;
  1821. command->Command = cpu_to_le32(VM_Ioctl);
  1822. command->ObjType = cpu_to_le32(FT_DRIVE);
  1823. command->MethodId = cpu_to_le32(1);
  1824. command->CtlCmd = cpu_to_le32(GetBusInfo);
  1825. rcode = aac_fib_send(ContainerCommand,
  1826. fibptr,
  1827. sizeof (*bus_info),
  1828. FsaNormal,
  1829. 1, 1,
  1830. NULL, NULL);
  1831. /* reasoned default */
  1832. dev->maximum_num_physicals = 16;
  1833. if (rcode >= 0 && le32_to_cpu(bus_info->Status) == ST_OK) {
  1834. dev->maximum_num_physicals = le32_to_cpu(bus_info->TargetsPerBus);
  1835. dev->maximum_num_channels = le32_to_cpu(bus_info->BusCount);
  1836. }
  1837. if (!dev->in_reset) {
  1838. char buffer[16];
  1839. tmp = le32_to_cpu(dev->adapter_info.kernelrev);
  1840. printk(KERN_INFO "%s%d: kernel %d.%d-%d[%d] %.*s\n",
  1841. dev->name,
  1842. dev->id,
  1843. tmp>>24,
  1844. (tmp>>16)&0xff,
  1845. tmp&0xff,
  1846. le32_to_cpu(dev->adapter_info.kernelbuild),
  1847. (int)sizeof(dev->supplement_adapter_info.build_date),
  1848. dev->supplement_adapter_info.build_date);
  1849. tmp = le32_to_cpu(dev->adapter_info.monitorrev);
  1850. printk(KERN_INFO "%s%d: monitor %d.%d-%d[%d]\n",
  1851. dev->name, dev->id,
  1852. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  1853. le32_to_cpu(dev->adapter_info.monitorbuild));
  1854. tmp = le32_to_cpu(dev->adapter_info.biosrev);
  1855. printk(KERN_INFO "%s%d: bios %d.%d-%d[%d]\n",
  1856. dev->name, dev->id,
  1857. tmp>>24,(tmp>>16)&0xff,tmp&0xff,
  1858. le32_to_cpu(dev->adapter_info.biosbuild));
  1859. buffer[0] = '\0';
  1860. if (aac_get_serial_number(
  1861. shost_to_class(dev->scsi_host_ptr), buffer))
  1862. printk(KERN_INFO "%s%d: serial %s",
  1863. dev->name, dev->id, buffer);
  1864. if (dev->supplement_adapter_info.vpd_info.tsid[0]) {
  1865. printk(KERN_INFO "%s%d: TSID %.*s\n",
  1866. dev->name, dev->id,
  1867. (int)sizeof(dev->supplement_adapter_info
  1868. .vpd_info.tsid),
  1869. dev->supplement_adapter_info.vpd_info.tsid);
  1870. }
  1871. if (!aac_check_reset || ((aac_check_reset == 1) &&
  1872. (dev->supplement_adapter_info.supported_options2 &
  1873. AAC_OPTION_IGNORE_RESET))) {
  1874. printk(KERN_INFO "%s%d: Reset Adapter Ignored\n",
  1875. dev->name, dev->id);
  1876. }
  1877. }
  1878. dev->cache_protected = 0;
  1879. dev->jbod = ((dev->supplement_adapter_info.feature_bits &
  1880. AAC_FEATURE_JBOD) != 0);
  1881. dev->nondasd_support = 0;
  1882. dev->raid_scsi_mode = 0;
  1883. if(dev->adapter_info.options & AAC_OPT_NONDASD)
  1884. dev->nondasd_support = 1;
  1885. /*
  1886. * If the firmware supports ROMB RAID/SCSI mode and we are currently
  1887. * in RAID/SCSI mode, set the flag. For now if in this mode we will
  1888. * force nondasd support on. If we decide to allow the non-dasd flag
  1889. * additional changes changes will have to be made to support
  1890. * RAID/SCSI. the function aac_scsi_cmd in this module will have to be
  1891. * changed to support the new dev->raid_scsi_mode flag instead of
  1892. * leaching off of the dev->nondasd_support flag. Also in linit.c the
  1893. * function aac_detect will have to be modified where it sets up the
  1894. * max number of channels based on the aac->nondasd_support flag only.
  1895. */
  1896. if ((dev->adapter_info.options & AAC_OPT_SCSI_MANAGED) &&
  1897. (dev->adapter_info.options & AAC_OPT_RAID_SCSI_MODE)) {
  1898. dev->nondasd_support = 1;
  1899. dev->raid_scsi_mode = 1;
  1900. }
  1901. if (dev->raid_scsi_mode != 0)
  1902. printk(KERN_INFO "%s%d: ROMB RAID/SCSI mode enabled\n",
  1903. dev->name, dev->id);
  1904. if (nondasd != -1)
  1905. dev->nondasd_support = (nondasd!=0);
  1906. if (dev->nondasd_support && !dev->in_reset)
  1907. printk(KERN_INFO "%s%d: Non-DASD support enabled.\n",dev->name, dev->id);
  1908. if (dma_get_required_mask(&dev->pdev->dev) > DMA_BIT_MASK(32))
  1909. dev->needs_dac = 1;
  1910. dev->dac_support = 0;
  1911. if ((sizeof(dma_addr_t) > 4) && dev->needs_dac &&
  1912. (dev->adapter_info.options & AAC_OPT_SGMAP_HOST64)) {
  1913. if (!dev->in_reset)
  1914. printk(KERN_INFO "%s%d: 64bit support enabled.\n",
  1915. dev->name, dev->id);
  1916. dev->dac_support = 1;
  1917. }
  1918. if(dacmode != -1) {
  1919. dev->dac_support = (dacmode!=0);
  1920. }
  1921. /* avoid problems with AAC_QUIRK_SCSI_32 controllers */
  1922. if (dev->dac_support && (aac_get_driver_ident(dev->cardtype)->quirks
  1923. & AAC_QUIRK_SCSI_32)) {
  1924. dev->nondasd_support = 0;
  1925. dev->jbod = 0;
  1926. expose_physicals = 0;
  1927. }
  1928. if (dev->dac_support) {
  1929. if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(64))) {
  1930. if (!dev->in_reset)
  1931. dev_info(&dev->pdev->dev, "64 Bit DAC enabled\n");
  1932. } else if (!dma_set_mask(&dev->pdev->dev, DMA_BIT_MASK(32))) {
  1933. dev_info(&dev->pdev->dev, "DMA mask set failed, 64 Bit DAC disabled\n");
  1934. dev->dac_support = 0;
  1935. } else {
  1936. dev_info(&dev->pdev->dev, "No suitable DMA available\n");
  1937. rcode = -ENOMEM;
  1938. }
  1939. }
  1940. /*
  1941. * Deal with configuring for the individualized limits of each packet
  1942. * interface.
  1943. */
  1944. dev->a_ops.adapter_scsi = (dev->dac_support)
  1945. ? ((aac_get_driver_ident(dev->cardtype)->quirks & AAC_QUIRK_SCSI_32)
  1946. ? aac_scsi_32_64
  1947. : aac_scsi_64)
  1948. : aac_scsi_32;
  1949. if (dev->raw_io_interface) {
  1950. dev->a_ops.adapter_bounds = (dev->raw_io_64)
  1951. ? aac_bounds_64
  1952. : aac_bounds_32;
  1953. dev->a_ops.adapter_read = aac_read_raw_io;
  1954. dev->a_ops.adapter_write = aac_write_raw_io;
  1955. } else {
  1956. dev->a_ops.adapter_bounds = aac_bounds_32;
  1957. dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
  1958. sizeof(struct aac_fibhdr) -
  1959. sizeof(struct aac_write) + sizeof(struct sgentry)) /
  1960. sizeof(struct sgentry);
  1961. if (dev->dac_support) {
  1962. dev->a_ops.adapter_read = aac_read_block64;
  1963. dev->a_ops.adapter_write = aac_write_block64;
  1964. /*
  1965. * 38 scatter gather elements
  1966. */
  1967. dev->scsi_host_ptr->sg_tablesize =
  1968. (dev->max_fib_size -
  1969. sizeof(struct aac_fibhdr) -
  1970. sizeof(struct aac_write64) +
  1971. sizeof(struct sgentry64)) /
  1972. sizeof(struct sgentry64);
  1973. } else {
  1974. dev->a_ops.adapter_read = aac_read_block;
  1975. dev->a_ops.adapter_write = aac_write_block;
  1976. }
  1977. dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
  1978. if (!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
  1979. /*
  1980. * Worst case size that could cause sg overflow when
  1981. * we break up SG elements that are larger than 64KB.
  1982. * Would be nice if we could tell the SCSI layer what
  1983. * the maximum SG element size can be. Worst case is
  1984. * (sg_tablesize-1) 4KB elements with one 64KB
  1985. * element.
  1986. * 32bit -> 468 or 238KB 64bit -> 424 or 212KB
  1987. */
  1988. dev->scsi_host_ptr->max_sectors =
  1989. (dev->scsi_host_ptr->sg_tablesize * 8) + 112;
  1990. }
  1991. }
  1992. if (!dev->sync_mode && dev->sa_firmware &&
  1993. dev->scsi_host_ptr->sg_tablesize > HBA_MAX_SG_SEPARATE)
  1994. dev->scsi_host_ptr->sg_tablesize = dev->sg_tablesize =
  1995. HBA_MAX_SG_SEPARATE;
  1996. /* FIB should be freed only after getting the response from the F/W */
  1997. if (rcode != -ERESTARTSYS) {
  1998. aac_fib_complete(fibptr);
  1999. aac_fib_free(fibptr);
  2000. }
  2001. return rcode;
  2002. }
  2003. static void io_callback(void *context, struct fib * fibptr)
  2004. {
  2005. struct aac_dev *dev;
  2006. struct aac_read_reply *readreply;
  2007. struct scsi_cmnd *scsicmd;
  2008. u32 cid;
  2009. scsicmd = (struct scsi_cmnd *) context;
  2010. if (!aac_valid_context(scsicmd, fibptr))
  2011. return;
  2012. dev = fibptr->dev;
  2013. cid = scmd_id(scsicmd);
  2014. if (nblank(dprintk(x))) {
  2015. u64 lba;
  2016. switch (scsicmd->cmnd[0]) {
  2017. case WRITE_6:
  2018. case READ_6:
  2019. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
  2020. (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  2021. break;
  2022. case WRITE_16:
  2023. case READ_16:
  2024. lba = ((u64)scsicmd->cmnd[2] << 56) |
  2025. ((u64)scsicmd->cmnd[3] << 48) |
  2026. ((u64)scsicmd->cmnd[4] << 40) |
  2027. ((u64)scsicmd->cmnd[5] << 32) |
  2028. ((u64)scsicmd->cmnd[6] << 24) |
  2029. (scsicmd->cmnd[7] << 16) |
  2030. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  2031. break;
  2032. case WRITE_12:
  2033. case READ_12:
  2034. lba = ((u64)scsicmd->cmnd[2] << 24) |
  2035. (scsicmd->cmnd[3] << 16) |
  2036. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  2037. break;
  2038. default:
  2039. lba = ((u64)scsicmd->cmnd[2] << 24) |
  2040. (scsicmd->cmnd[3] << 16) |
  2041. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  2042. break;
  2043. }
  2044. printk(KERN_DEBUG
  2045. "io_callback[cpu %d]: lba = %llu, t = %ld.\n",
  2046. smp_processor_id(), (unsigned long long)lba, jiffies);
  2047. }
  2048. BUG_ON(fibptr == NULL);
  2049. scsi_dma_unmap(scsicmd);
  2050. readreply = (struct aac_read_reply *)fib_data(fibptr);
  2051. switch (le32_to_cpu(readreply->status)) {
  2052. case ST_OK:
  2053. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2054. dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
  2055. break;
  2056. case ST_NOT_READY:
  2057. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2058. set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
  2059. SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
  2060. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2061. min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
  2062. SCSI_SENSE_BUFFERSIZE));
  2063. break;
  2064. case ST_MEDERR:
  2065. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2066. set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
  2067. SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
  2068. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2069. min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
  2070. SCSI_SENSE_BUFFERSIZE));
  2071. break;
  2072. default:
  2073. #ifdef AAC_DETAILED_STATUS_INFO
  2074. printk(KERN_WARNING "io_callback: io failed, status = %d\n",
  2075. le32_to_cpu(readreply->status));
  2076. #endif
  2077. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2078. set_sense(&dev->fsa_dev[cid].sense_data,
  2079. HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
  2080. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
  2081. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2082. min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
  2083. SCSI_SENSE_BUFFERSIZE));
  2084. break;
  2085. }
  2086. aac_fib_complete(fibptr);
  2087. aac_scsi_done(scsicmd);
  2088. }
  2089. static int aac_read(struct scsi_cmnd * scsicmd)
  2090. {
  2091. u64 lba;
  2092. u32 count;
  2093. int status;
  2094. struct aac_dev *dev;
  2095. struct fib * cmd_fibcontext;
  2096. int cid;
  2097. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2098. /*
  2099. * Get block address and transfer length
  2100. */
  2101. switch (scsicmd->cmnd[0]) {
  2102. case READ_6:
  2103. dprintk((KERN_DEBUG "aachba: received a read(6) command on id %d.\n", scmd_id(scsicmd)));
  2104. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) |
  2105. (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  2106. count = scsicmd->cmnd[4];
  2107. if (count == 0)
  2108. count = 256;
  2109. break;
  2110. case READ_16:
  2111. dprintk((KERN_DEBUG "aachba: received a read(16) command on id %d.\n", scmd_id(scsicmd)));
  2112. lba = ((u64)scsicmd->cmnd[2] << 56) |
  2113. ((u64)scsicmd->cmnd[3] << 48) |
  2114. ((u64)scsicmd->cmnd[4] << 40) |
  2115. ((u64)scsicmd->cmnd[5] << 32) |
  2116. ((u64)scsicmd->cmnd[6] << 24) |
  2117. (scsicmd->cmnd[7] << 16) |
  2118. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  2119. count = (scsicmd->cmnd[10] << 24) |
  2120. (scsicmd->cmnd[11] << 16) |
  2121. (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
  2122. break;
  2123. case READ_12:
  2124. dprintk((KERN_DEBUG "aachba: received a read(12) command on id %d.\n", scmd_id(scsicmd)));
  2125. lba = ((u64)scsicmd->cmnd[2] << 24) |
  2126. (scsicmd->cmnd[3] << 16) |
  2127. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  2128. count = (scsicmd->cmnd[6] << 24) |
  2129. (scsicmd->cmnd[7] << 16) |
  2130. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  2131. break;
  2132. default:
  2133. dprintk((KERN_DEBUG "aachba: received a read(10) command on id %d.\n", scmd_id(scsicmd)));
  2134. lba = ((u64)scsicmd->cmnd[2] << 24) |
  2135. (scsicmd->cmnd[3] << 16) |
  2136. (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  2137. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  2138. break;
  2139. }
  2140. if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
  2141. cid = scmd_id(scsicmd);
  2142. dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
  2143. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2144. set_sense(&dev->fsa_dev[cid].sense_data,
  2145. ILLEGAL_REQUEST, SENCODE_LBA_OUT_OF_RANGE,
  2146. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
  2147. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2148. min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
  2149. SCSI_SENSE_BUFFERSIZE));
  2150. aac_scsi_done(scsicmd);
  2151. return 0;
  2152. }
  2153. dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
  2154. smp_processor_id(), (unsigned long long)lba, jiffies));
  2155. if (aac_adapter_bounds(dev,scsicmd,lba))
  2156. return 0;
  2157. /*
  2158. * Alocate and initialize a Fib
  2159. */
  2160. cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
  2161. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  2162. status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
  2163. /*
  2164. * Check that the command queued to the controller
  2165. */
  2166. if (status == -EINPROGRESS)
  2167. return 0;
  2168. printk(KERN_WARNING "aac_read: aac_fib_send failed with status: %d.\n", status);
  2169. /*
  2170. * For some reason, the Fib didn't queue, return QUEUE_FULL
  2171. */
  2172. scsicmd->result = DID_OK << 16 | SAM_STAT_TASK_SET_FULL;
  2173. aac_scsi_done(scsicmd);
  2174. aac_fib_complete(cmd_fibcontext);
  2175. aac_fib_free(cmd_fibcontext);
  2176. return 0;
  2177. }
  2178. static int aac_write(struct scsi_cmnd * scsicmd)
  2179. {
  2180. u64 lba;
  2181. u32 count;
  2182. int fua;
  2183. int status;
  2184. struct aac_dev *dev;
  2185. struct fib * cmd_fibcontext;
  2186. int cid;
  2187. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  2188. /*
  2189. * Get block address and transfer length
  2190. */
  2191. if (scsicmd->cmnd[0] == WRITE_6) /* 6 byte command */
  2192. {
  2193. lba = ((scsicmd->cmnd[1] & 0x1F) << 16) | (scsicmd->cmnd[2] << 8) | scsicmd->cmnd[3];
  2194. count = scsicmd->cmnd[4];
  2195. if (count == 0)
  2196. count = 256;
  2197. fua = 0;
  2198. } else if (scsicmd->cmnd[0] == WRITE_16) { /* 16 byte command */
  2199. dprintk((KERN_DEBUG "aachba: received a write(16) command on id %d.\n", scmd_id(scsicmd)));
  2200. lba = ((u64)scsicmd->cmnd[2] << 56) |
  2201. ((u64)scsicmd->cmnd[3] << 48) |
  2202. ((u64)scsicmd->cmnd[4] << 40) |
  2203. ((u64)scsicmd->cmnd[5] << 32) |
  2204. ((u64)scsicmd->cmnd[6] << 24) |
  2205. (scsicmd->cmnd[7] << 16) |
  2206. (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  2207. count = (scsicmd->cmnd[10] << 24) | (scsicmd->cmnd[11] << 16) |
  2208. (scsicmd->cmnd[12] << 8) | scsicmd->cmnd[13];
  2209. fua = scsicmd->cmnd[1] & 0x8;
  2210. } else if (scsicmd->cmnd[0] == WRITE_12) { /* 12 byte command */
  2211. dprintk((KERN_DEBUG "aachba: received a write(12) command on id %d.\n", scmd_id(scsicmd)));
  2212. lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16)
  2213. | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  2214. count = (scsicmd->cmnd[6] << 24) | (scsicmd->cmnd[7] << 16)
  2215. | (scsicmd->cmnd[8] << 8) | scsicmd->cmnd[9];
  2216. fua = scsicmd->cmnd[1] & 0x8;
  2217. } else {
  2218. dprintk((KERN_DEBUG "aachba: received a write(10) command on id %d.\n", scmd_id(scsicmd)));
  2219. lba = ((u64)scsicmd->cmnd[2] << 24) | (scsicmd->cmnd[3] << 16) | (scsicmd->cmnd[4] << 8) | scsicmd->cmnd[5];
  2220. count = (scsicmd->cmnd[7] << 8) | scsicmd->cmnd[8];
  2221. fua = scsicmd->cmnd[1] & 0x8;
  2222. }
  2223. if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
  2224. cid = scmd_id(scsicmd);
  2225. dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
  2226. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2227. set_sense(&dev->fsa_dev[cid].sense_data,
  2228. ILLEGAL_REQUEST, SENCODE_LBA_OUT_OF_RANGE,
  2229. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
  2230. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2231. min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
  2232. SCSI_SENSE_BUFFERSIZE));
  2233. aac_scsi_done(scsicmd);
  2234. return 0;
  2235. }
  2236. dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
  2237. smp_processor_id(), (unsigned long long)lba, jiffies));
  2238. if (aac_adapter_bounds(dev,scsicmd,lba))
  2239. return 0;
  2240. /*
  2241. * Allocate and initialize a Fib then setup a BlockWrite command
  2242. */
  2243. cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
  2244. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  2245. status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count, fua);
  2246. /*
  2247. * Check that the command queued to the controller
  2248. */
  2249. if (status == -EINPROGRESS)
  2250. return 0;
  2251. printk(KERN_WARNING "aac_write: aac_fib_send failed with status: %d\n", status);
  2252. /*
  2253. * For some reason, the Fib didn't queue, return QUEUE_FULL
  2254. */
  2255. scsicmd->result = DID_OK << 16 | SAM_STAT_TASK_SET_FULL;
  2256. aac_scsi_done(scsicmd);
  2257. aac_fib_complete(cmd_fibcontext);
  2258. aac_fib_free(cmd_fibcontext);
  2259. return 0;
  2260. }
  2261. static void synchronize_callback(void *context, struct fib *fibptr)
  2262. {
  2263. struct aac_synchronize_reply *synchronizereply;
  2264. struct scsi_cmnd *cmd = context;
  2265. if (!aac_valid_context(cmd, fibptr))
  2266. return;
  2267. dprintk((KERN_DEBUG "synchronize_callback[cpu %d]: t = %ld.\n",
  2268. smp_processor_id(), jiffies));
  2269. BUG_ON(fibptr == NULL);
  2270. synchronizereply = fib_data(fibptr);
  2271. if (le32_to_cpu(synchronizereply->status) == CT_OK)
  2272. cmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2273. else {
  2274. struct scsi_device *sdev = cmd->device;
  2275. struct aac_dev *dev = fibptr->dev;
  2276. u32 cid = sdev_id(sdev);
  2277. printk(KERN_WARNING
  2278. "synchronize_callback: synchronize failed, status = %d\n",
  2279. le32_to_cpu(synchronizereply->status));
  2280. cmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2281. set_sense(&dev->fsa_dev[cid].sense_data,
  2282. HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
  2283. ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
  2284. memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2285. min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
  2286. SCSI_SENSE_BUFFERSIZE));
  2287. }
  2288. aac_fib_complete(fibptr);
  2289. aac_fib_free(fibptr);
  2290. aac_scsi_done(cmd);
  2291. }
  2292. static int aac_synchronize(struct scsi_cmnd *scsicmd)
  2293. {
  2294. int status;
  2295. struct fib *cmd_fibcontext;
  2296. struct aac_synchronize *synchronizecmd;
  2297. struct scsi_device *sdev = scsicmd->device;
  2298. struct aac_dev *aac;
  2299. aac = (struct aac_dev *)sdev->host->hostdata;
  2300. if (aac->in_reset)
  2301. return SCSI_MLQUEUE_HOST_BUSY;
  2302. /*
  2303. * Allocate and initialize a Fib
  2304. */
  2305. cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
  2306. aac_fib_init(cmd_fibcontext);
  2307. synchronizecmd = fib_data(cmd_fibcontext);
  2308. synchronizecmd->command = cpu_to_le32(VM_ContainerConfig);
  2309. synchronizecmd->type = cpu_to_le32(CT_FLUSH_CACHE);
  2310. synchronizecmd->cid = cpu_to_le32(scmd_id(scsicmd));
  2311. synchronizecmd->count =
  2312. cpu_to_le32(sizeof(((struct aac_synchronize_reply *)NULL)->data));
  2313. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  2314. /*
  2315. * Now send the Fib to the adapter
  2316. */
  2317. status = aac_fib_send(ContainerCommand,
  2318. cmd_fibcontext,
  2319. sizeof(struct aac_synchronize),
  2320. FsaNormal,
  2321. 0, 1,
  2322. (fib_callback)synchronize_callback,
  2323. (void *)scsicmd);
  2324. /*
  2325. * Check that the command queued to the controller
  2326. */
  2327. if (status == -EINPROGRESS)
  2328. return 0;
  2329. printk(KERN_WARNING
  2330. "aac_synchronize: aac_fib_send failed with status: %d.\n", status);
  2331. aac_fib_complete(cmd_fibcontext);
  2332. aac_fib_free(cmd_fibcontext);
  2333. return SCSI_MLQUEUE_HOST_BUSY;
  2334. }
  2335. static void aac_start_stop_callback(void *context, struct fib *fibptr)
  2336. {
  2337. struct scsi_cmnd *scsicmd = context;
  2338. if (!aac_valid_context(scsicmd, fibptr))
  2339. return;
  2340. BUG_ON(fibptr == NULL);
  2341. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2342. aac_fib_complete(fibptr);
  2343. aac_fib_free(fibptr);
  2344. aac_scsi_done(scsicmd);
  2345. }
  2346. static int aac_start_stop(struct scsi_cmnd *scsicmd)
  2347. {
  2348. int status;
  2349. struct fib *cmd_fibcontext;
  2350. struct aac_power_management *pmcmd;
  2351. struct scsi_device *sdev = scsicmd->device;
  2352. struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata;
  2353. if (!(aac->supplement_adapter_info.supported_options2 &
  2354. AAC_OPTION_POWER_MANAGEMENT)) {
  2355. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2356. aac_scsi_done(scsicmd);
  2357. return 0;
  2358. }
  2359. if (aac->in_reset)
  2360. return SCSI_MLQUEUE_HOST_BUSY;
  2361. /*
  2362. * Allocate and initialize a Fib
  2363. */
  2364. cmd_fibcontext = aac_fib_alloc_tag(aac, scsicmd);
  2365. aac_fib_init(cmd_fibcontext);
  2366. pmcmd = fib_data(cmd_fibcontext);
  2367. pmcmd->command = cpu_to_le32(VM_ContainerConfig);
  2368. pmcmd->type = cpu_to_le32(CT_POWER_MANAGEMENT);
  2369. /* Eject bit ignored, not relevant */
  2370. pmcmd->sub = (scsicmd->cmnd[4] & 1) ?
  2371. cpu_to_le32(CT_PM_START_UNIT) : cpu_to_le32(CT_PM_STOP_UNIT);
  2372. pmcmd->cid = cpu_to_le32(sdev_id(sdev));
  2373. pmcmd->parm = (scsicmd->cmnd[1] & 1) ?
  2374. cpu_to_le32(CT_PM_UNIT_IMMEDIATE) : 0;
  2375. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  2376. /*
  2377. * Now send the Fib to the adapter
  2378. */
  2379. status = aac_fib_send(ContainerCommand,
  2380. cmd_fibcontext,
  2381. sizeof(struct aac_power_management),
  2382. FsaNormal,
  2383. 0, 1,
  2384. (fib_callback)aac_start_stop_callback,
  2385. (void *)scsicmd);
  2386. /*
  2387. * Check that the command queued to the controller
  2388. */
  2389. if (status == -EINPROGRESS)
  2390. return 0;
  2391. aac_fib_complete(cmd_fibcontext);
  2392. aac_fib_free(cmd_fibcontext);
  2393. return SCSI_MLQUEUE_HOST_BUSY;
  2394. }
  2395. /**
  2396. * aac_scsi_cmd() - Process SCSI command
  2397. * @scsicmd: SCSI command block
  2398. *
  2399. * Emulate a SCSI command and queue the required request for the
  2400. * aacraid firmware.
  2401. */
  2402. int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
  2403. {
  2404. u32 cid, bus;
  2405. struct Scsi_Host *host = scsicmd->device->host;
  2406. struct aac_dev *dev = (struct aac_dev *)host->hostdata;
  2407. struct fsa_dev_info *fsa_dev_ptr = dev->fsa_dev;
  2408. if (fsa_dev_ptr == NULL)
  2409. return -1;
  2410. /*
  2411. * If the bus, id or lun is out of range, return fail
  2412. * Test does not apply to ID 16, the pseudo id for the controller
  2413. * itself.
  2414. */
  2415. cid = scmd_id(scsicmd);
  2416. if (cid != host->this_id) {
  2417. if (scmd_channel(scsicmd) == CONTAINER_CHANNEL) {
  2418. if((cid >= dev->maximum_num_containers) ||
  2419. (scsicmd->device->lun != 0)) {
  2420. scsicmd->result = DID_NO_CONNECT << 16;
  2421. goto scsi_done_ret;
  2422. }
  2423. /*
  2424. * If the target container doesn't exist, it may have
  2425. * been newly created
  2426. */
  2427. if (((fsa_dev_ptr[cid].valid & 1) == 0) ||
  2428. (fsa_dev_ptr[cid].sense_data.sense_key ==
  2429. NOT_READY)) {
  2430. switch (scsicmd->cmnd[0]) {
  2431. case SERVICE_ACTION_IN_16:
  2432. if (!(dev->raw_io_interface) ||
  2433. !(dev->raw_io_64) ||
  2434. ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
  2435. break;
  2436. fallthrough;
  2437. case INQUIRY:
  2438. case READ_CAPACITY:
  2439. case TEST_UNIT_READY:
  2440. if (dev->in_reset)
  2441. return -1;
  2442. return _aac_probe_container(scsicmd,
  2443. aac_probe_container_callback2);
  2444. default:
  2445. break;
  2446. }
  2447. }
  2448. } else { /* check for physical non-dasd devices */
  2449. bus = aac_logical_to_phys(scmd_channel(scsicmd));
  2450. if (bus < AAC_MAX_BUSES && cid < AAC_MAX_TARGETS &&
  2451. dev->hba_map[bus][cid].devtype
  2452. == AAC_DEVTYPE_NATIVE_RAW) {
  2453. if (dev->in_reset)
  2454. return -1;
  2455. return aac_send_hba_fib(scsicmd);
  2456. } else if (dev->nondasd_support || expose_physicals ||
  2457. dev->jbod) {
  2458. if (dev->in_reset)
  2459. return -1;
  2460. return aac_send_srb_fib(scsicmd);
  2461. } else {
  2462. scsicmd->result = DID_NO_CONNECT << 16;
  2463. goto scsi_done_ret;
  2464. }
  2465. }
  2466. }
  2467. /*
  2468. * else Command for the controller itself
  2469. */
  2470. else if ((scsicmd->cmnd[0] != INQUIRY) && /* only INQUIRY & TUR cmnd supported for controller */
  2471. (scsicmd->cmnd[0] != TEST_UNIT_READY))
  2472. {
  2473. dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
  2474. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2475. set_sense(&dev->fsa_dev[cid].sense_data,
  2476. ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
  2477. ASENCODE_INVALID_COMMAND, 0, 0);
  2478. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2479. min_t(size_t, sizeof(dev->fsa_dev[cid].sense_data),
  2480. SCSI_SENSE_BUFFERSIZE));
  2481. goto scsi_done_ret;
  2482. }
  2483. switch (scsicmd->cmnd[0]) {
  2484. case READ_6:
  2485. case READ_10:
  2486. case READ_12:
  2487. case READ_16:
  2488. if (dev->in_reset)
  2489. return -1;
  2490. return aac_read(scsicmd);
  2491. case WRITE_6:
  2492. case WRITE_10:
  2493. case WRITE_12:
  2494. case WRITE_16:
  2495. if (dev->in_reset)
  2496. return -1;
  2497. return aac_write(scsicmd);
  2498. case SYNCHRONIZE_CACHE:
  2499. if (((aac_cache & 6) == 6) && dev->cache_protected) {
  2500. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2501. break;
  2502. }
  2503. /* Issue FIB to tell Firmware to flush it's cache */
  2504. if ((aac_cache & 6) != 2)
  2505. return aac_synchronize(scsicmd);
  2506. fallthrough;
  2507. case INQUIRY:
  2508. {
  2509. struct inquiry_data inq_data;
  2510. dprintk((KERN_DEBUG "INQUIRY command, ID: %d.\n", cid));
  2511. memset(&inq_data, 0, sizeof (struct inquiry_data));
  2512. if ((scsicmd->cmnd[1] & 0x1) && aac_wwn) {
  2513. char *arr = (char *)&inq_data;
  2514. /* EVPD bit set */
  2515. arr[0] = (scmd_id(scsicmd) == host->this_id) ?
  2516. INQD_PDT_PROC : INQD_PDT_DA;
  2517. if (scsicmd->cmnd[2] == 0) {
  2518. /* supported vital product data pages */
  2519. arr[3] = 3;
  2520. arr[4] = 0x0;
  2521. arr[5] = 0x80;
  2522. arr[6] = 0x83;
  2523. arr[1] = scsicmd->cmnd[2];
  2524. scsi_sg_copy_from_buffer(scsicmd, &inq_data,
  2525. sizeof(inq_data));
  2526. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2527. } else if (scsicmd->cmnd[2] == 0x80) {
  2528. /* unit serial number page */
  2529. arr[3] = setinqserial(dev, &arr[4],
  2530. scmd_id(scsicmd));
  2531. arr[1] = scsicmd->cmnd[2];
  2532. scsi_sg_copy_from_buffer(scsicmd, &inq_data,
  2533. sizeof(inq_data));
  2534. if (aac_wwn != 2)
  2535. return aac_get_container_serial(
  2536. scsicmd);
  2537. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2538. } else if (scsicmd->cmnd[2] == 0x83) {
  2539. /* vpd page 0x83 - Device Identification Page */
  2540. char *sno = (char *)&inq_data;
  2541. sno[3] = setinqserial(dev, &sno[4],
  2542. scmd_id(scsicmd));
  2543. if (aac_wwn != 2)
  2544. return aac_get_container_serial(
  2545. scsicmd);
  2546. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2547. } else {
  2548. /* vpd page not implemented */
  2549. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2550. set_sense(&dev->fsa_dev[cid].sense_data,
  2551. ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
  2552. ASENCODE_NO_SENSE, 7, 2);
  2553. memcpy(scsicmd->sense_buffer,
  2554. &dev->fsa_dev[cid].sense_data,
  2555. min_t(size_t,
  2556. sizeof(dev->fsa_dev[cid].sense_data),
  2557. SCSI_SENSE_BUFFERSIZE));
  2558. }
  2559. break;
  2560. }
  2561. inq_data.inqd_ver = 2; /* claim compliance to SCSI-2 */
  2562. inq_data.inqd_rdf = 2; /* A response data format value of two indicates that the data shall be in the format specified in SCSI-2 */
  2563. inq_data.inqd_len = 31;
  2564. /*Format for "pad2" is RelAdr | WBus32 | WBus16 | Sync | Linked |Reserved| CmdQue | SftRe */
  2565. inq_data.inqd_pad2= 0x32 ; /*WBus16|Sync|CmdQue */
  2566. /*
  2567. * Set the Vendor, Product, and Revision Level
  2568. * see: <vendor>.c i.e. aac.c
  2569. */
  2570. if (cid == host->this_id) {
  2571. setinqstr(dev, (void *) (inq_data.inqd_vid), ARRAY_SIZE(container_types));
  2572. inq_data.inqd_pdt = INQD_PDT_PROC; /* Processor device */
  2573. scsi_sg_copy_from_buffer(scsicmd, &inq_data,
  2574. sizeof(inq_data));
  2575. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2576. break;
  2577. }
  2578. if (dev->in_reset)
  2579. return -1;
  2580. setinqstr(dev, (void *) (inq_data.inqd_vid), fsa_dev_ptr[cid].type);
  2581. inq_data.inqd_pdt = INQD_PDT_DA; /* Direct/random access device */
  2582. scsi_sg_copy_from_buffer(scsicmd, &inq_data, sizeof(inq_data));
  2583. return aac_get_container_name(scsicmd);
  2584. }
  2585. case SERVICE_ACTION_IN_16:
  2586. if (!(dev->raw_io_interface) ||
  2587. !(dev->raw_io_64) ||
  2588. ((scsicmd->cmnd[1] & 0x1f) != SAI_READ_CAPACITY_16))
  2589. break;
  2590. {
  2591. u64 capacity;
  2592. char cp[13];
  2593. unsigned int alloc_len;
  2594. dprintk((KERN_DEBUG "READ CAPACITY_16 command.\n"));
  2595. capacity = fsa_dev_ptr[cid].size - 1;
  2596. cp[0] = (capacity >> 56) & 0xff;
  2597. cp[1] = (capacity >> 48) & 0xff;
  2598. cp[2] = (capacity >> 40) & 0xff;
  2599. cp[3] = (capacity >> 32) & 0xff;
  2600. cp[4] = (capacity >> 24) & 0xff;
  2601. cp[5] = (capacity >> 16) & 0xff;
  2602. cp[6] = (capacity >> 8) & 0xff;
  2603. cp[7] = (capacity >> 0) & 0xff;
  2604. cp[8] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
  2605. cp[9] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
  2606. cp[10] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
  2607. cp[11] = (fsa_dev_ptr[cid].block_size) & 0xff;
  2608. cp[12] = 0;
  2609. alloc_len = ((scsicmd->cmnd[10] << 24)
  2610. + (scsicmd->cmnd[11] << 16)
  2611. + (scsicmd->cmnd[12] << 8) + scsicmd->cmnd[13]);
  2612. alloc_len = min_t(size_t, alloc_len, sizeof(cp));
  2613. scsi_sg_copy_from_buffer(scsicmd, cp, alloc_len);
  2614. if (alloc_len < scsi_bufflen(scsicmd))
  2615. scsi_set_resid(scsicmd,
  2616. scsi_bufflen(scsicmd) - alloc_len);
  2617. /* Do not cache partition table for arrays */
  2618. scsicmd->device->removable = 1;
  2619. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2620. break;
  2621. }
  2622. case READ_CAPACITY:
  2623. {
  2624. u32 capacity;
  2625. char cp[8];
  2626. dprintk((KERN_DEBUG "READ CAPACITY command.\n"));
  2627. if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
  2628. capacity = fsa_dev_ptr[cid].size - 1;
  2629. else
  2630. capacity = (u32)-1;
  2631. cp[0] = (capacity >> 24) & 0xff;
  2632. cp[1] = (capacity >> 16) & 0xff;
  2633. cp[2] = (capacity >> 8) & 0xff;
  2634. cp[3] = (capacity >> 0) & 0xff;
  2635. cp[4] = (fsa_dev_ptr[cid].block_size >> 24) & 0xff;
  2636. cp[5] = (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
  2637. cp[6] = (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
  2638. cp[7] = (fsa_dev_ptr[cid].block_size) & 0xff;
  2639. scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
  2640. /* Do not cache partition table for arrays */
  2641. scsicmd->device->removable = 1;
  2642. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2643. break;
  2644. }
  2645. case MODE_SENSE:
  2646. {
  2647. int mode_buf_length = 4;
  2648. u32 capacity;
  2649. aac_modep_data mpd;
  2650. if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
  2651. capacity = fsa_dev_ptr[cid].size - 1;
  2652. else
  2653. capacity = (u32)-1;
  2654. dprintk((KERN_DEBUG "MODE SENSE command.\n"));
  2655. memset((char *)&mpd, 0, sizeof(aac_modep_data));
  2656. /* Mode data length */
  2657. mpd.hd.data_length = sizeof(mpd.hd) - 1;
  2658. /* Medium type - default */
  2659. mpd.hd.med_type = 0;
  2660. /* Device-specific param,
  2661. bit 8: 0/1 = write enabled/protected
  2662. bit 4: 0/1 = FUA enabled */
  2663. mpd.hd.dev_par = 0;
  2664. if (dev->raw_io_interface && ((aac_cache & 5) != 1))
  2665. mpd.hd.dev_par = 0x10;
  2666. if (scsicmd->cmnd[1] & 0x8)
  2667. mpd.hd.bd_length = 0; /* Block descriptor length */
  2668. else {
  2669. mpd.hd.bd_length = sizeof(mpd.bd);
  2670. mpd.hd.data_length += mpd.hd.bd_length;
  2671. mpd.bd.block_length[0] =
  2672. (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
  2673. mpd.bd.block_length[1] =
  2674. (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
  2675. mpd.bd.block_length[2] =
  2676. fsa_dev_ptr[cid].block_size & 0xff;
  2677. mpd.mpc_buf[0] = scsicmd->cmnd[2];
  2678. if (scsicmd->cmnd[2] == 0x1C) {
  2679. /* page length */
  2680. mpd.mpc_buf[1] = 0xa;
  2681. /* Mode data length */
  2682. mpd.hd.data_length = 23;
  2683. } else {
  2684. /* Mode data length */
  2685. mpd.hd.data_length = 15;
  2686. }
  2687. if (capacity > 0xffffff) {
  2688. mpd.bd.block_count[0] = 0xff;
  2689. mpd.bd.block_count[1] = 0xff;
  2690. mpd.bd.block_count[2] = 0xff;
  2691. } else {
  2692. mpd.bd.block_count[0] = (capacity >> 16) & 0xff;
  2693. mpd.bd.block_count[1] = (capacity >> 8) & 0xff;
  2694. mpd.bd.block_count[2] = capacity & 0xff;
  2695. }
  2696. }
  2697. if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
  2698. ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
  2699. mpd.hd.data_length += 3;
  2700. mpd.mpc_buf[0] = 8;
  2701. mpd.mpc_buf[1] = 1;
  2702. mpd.mpc_buf[2] = ((aac_cache & 6) == 2)
  2703. ? 0 : 0x04; /* WCE */
  2704. mode_buf_length = sizeof(mpd);
  2705. }
  2706. if (mode_buf_length > scsicmd->cmnd[4])
  2707. mode_buf_length = scsicmd->cmnd[4];
  2708. else
  2709. mode_buf_length = sizeof(mpd);
  2710. scsi_sg_copy_from_buffer(scsicmd,
  2711. (char *)&mpd,
  2712. mode_buf_length);
  2713. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2714. break;
  2715. }
  2716. case MODE_SENSE_10:
  2717. {
  2718. u32 capacity;
  2719. int mode_buf_length = 8;
  2720. aac_modep10_data mpd10;
  2721. if (fsa_dev_ptr[cid].size <= 0x100000000ULL)
  2722. capacity = fsa_dev_ptr[cid].size - 1;
  2723. else
  2724. capacity = (u32)-1;
  2725. dprintk((KERN_DEBUG "MODE SENSE 10 byte command.\n"));
  2726. memset((char *)&mpd10, 0, sizeof(aac_modep10_data));
  2727. /* Mode data length (MSB) */
  2728. mpd10.hd.data_length[0] = 0;
  2729. /* Mode data length (LSB) */
  2730. mpd10.hd.data_length[1] = sizeof(mpd10.hd) - 1;
  2731. /* Medium type - default */
  2732. mpd10.hd.med_type = 0;
  2733. /* Device-specific param,
  2734. bit 8: 0/1 = write enabled/protected
  2735. bit 4: 0/1 = FUA enabled */
  2736. mpd10.hd.dev_par = 0;
  2737. if (dev->raw_io_interface && ((aac_cache & 5) != 1))
  2738. mpd10.hd.dev_par = 0x10;
  2739. mpd10.hd.rsrvd[0] = 0; /* reserved */
  2740. mpd10.hd.rsrvd[1] = 0; /* reserved */
  2741. if (scsicmd->cmnd[1] & 0x8) {
  2742. /* Block descriptor length (MSB) */
  2743. mpd10.hd.bd_length[0] = 0;
  2744. /* Block descriptor length (LSB) */
  2745. mpd10.hd.bd_length[1] = 0;
  2746. } else {
  2747. mpd10.hd.bd_length[0] = 0;
  2748. mpd10.hd.bd_length[1] = sizeof(mpd10.bd);
  2749. mpd10.hd.data_length[1] += mpd10.hd.bd_length[1];
  2750. mpd10.bd.block_length[0] =
  2751. (fsa_dev_ptr[cid].block_size >> 16) & 0xff;
  2752. mpd10.bd.block_length[1] =
  2753. (fsa_dev_ptr[cid].block_size >> 8) & 0xff;
  2754. mpd10.bd.block_length[2] =
  2755. fsa_dev_ptr[cid].block_size & 0xff;
  2756. if (capacity > 0xffffff) {
  2757. mpd10.bd.block_count[0] = 0xff;
  2758. mpd10.bd.block_count[1] = 0xff;
  2759. mpd10.bd.block_count[2] = 0xff;
  2760. } else {
  2761. mpd10.bd.block_count[0] =
  2762. (capacity >> 16) & 0xff;
  2763. mpd10.bd.block_count[1] =
  2764. (capacity >> 8) & 0xff;
  2765. mpd10.bd.block_count[2] =
  2766. capacity & 0xff;
  2767. }
  2768. }
  2769. if (((scsicmd->cmnd[2] & 0x3f) == 8) ||
  2770. ((scsicmd->cmnd[2] & 0x3f) == 0x3f)) {
  2771. mpd10.hd.data_length[1] += 3;
  2772. mpd10.mpc_buf[0] = 8;
  2773. mpd10.mpc_buf[1] = 1;
  2774. mpd10.mpc_buf[2] = ((aac_cache & 6) == 2)
  2775. ? 0 : 0x04; /* WCE */
  2776. mode_buf_length = sizeof(mpd10);
  2777. if (mode_buf_length > scsicmd->cmnd[8])
  2778. mode_buf_length = scsicmd->cmnd[8];
  2779. }
  2780. scsi_sg_copy_from_buffer(scsicmd,
  2781. (char *)&mpd10,
  2782. mode_buf_length);
  2783. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2784. break;
  2785. }
  2786. case REQUEST_SENSE:
  2787. dprintk((KERN_DEBUG "REQUEST SENSE command.\n"));
  2788. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2789. sizeof(struct sense_data));
  2790. memset(&dev->fsa_dev[cid].sense_data, 0,
  2791. sizeof(struct sense_data));
  2792. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2793. break;
  2794. case ALLOW_MEDIUM_REMOVAL:
  2795. dprintk((KERN_DEBUG "LOCK command.\n"));
  2796. if (scsicmd->cmnd[4])
  2797. fsa_dev_ptr[cid].locked = 1;
  2798. else
  2799. fsa_dev_ptr[cid].locked = 0;
  2800. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2801. break;
  2802. /*
  2803. * These commands are all No-Ops
  2804. */
  2805. case TEST_UNIT_READY:
  2806. if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
  2807. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2808. set_sense(&dev->fsa_dev[cid].sense_data,
  2809. NOT_READY, SENCODE_BECOMING_READY,
  2810. ASENCODE_BECOMING_READY, 0, 0);
  2811. memcpy(scsicmd->sense_buffer,
  2812. &dev->fsa_dev[cid].sense_data,
  2813. min_t(size_t,
  2814. sizeof(dev->fsa_dev[cid].sense_data),
  2815. SCSI_SENSE_BUFFERSIZE));
  2816. break;
  2817. }
  2818. fallthrough;
  2819. case RESERVE:
  2820. case RELEASE:
  2821. case REZERO_UNIT:
  2822. case REASSIGN_BLOCKS:
  2823. case SEEK_10:
  2824. scsicmd->result = DID_OK << 16 | SAM_STAT_GOOD;
  2825. break;
  2826. case START_STOP:
  2827. return aac_start_stop(scsicmd);
  2828. default:
  2829. /*
  2830. * Unhandled commands
  2831. */
  2832. dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
  2833. scsicmd->cmnd[0]));
  2834. scsicmd->result = DID_OK << 16 | SAM_STAT_CHECK_CONDITION;
  2835. set_sense(&dev->fsa_dev[cid].sense_data,
  2836. ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
  2837. ASENCODE_INVALID_COMMAND, 0, 0);
  2838. memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
  2839. min_t(size_t,
  2840. sizeof(dev->fsa_dev[cid].sense_data),
  2841. SCSI_SENSE_BUFFERSIZE));
  2842. }
  2843. scsi_done_ret:
  2844. aac_scsi_done(scsicmd);
  2845. return 0;
  2846. }
  2847. static int query_disk(struct aac_dev *dev, void __user *arg)
  2848. {
  2849. struct aac_query_disk qd;
  2850. struct fsa_dev_info *fsa_dev_ptr;
  2851. fsa_dev_ptr = dev->fsa_dev;
  2852. if (!fsa_dev_ptr)
  2853. return -EBUSY;
  2854. if (copy_from_user(&qd, arg, sizeof (struct aac_query_disk)))
  2855. return -EFAULT;
  2856. if (qd.cnum == -1) {
  2857. if (qd.id < 0 || qd.id >= dev->maximum_num_containers)
  2858. return -EINVAL;
  2859. qd.cnum = qd.id;
  2860. } else if ((qd.bus == -1) && (qd.id == -1) && (qd.lun == -1)) {
  2861. if (qd.cnum < 0 || qd.cnum >= dev->maximum_num_containers)
  2862. return -EINVAL;
  2863. qd.instance = dev->scsi_host_ptr->host_no;
  2864. qd.bus = 0;
  2865. qd.id = CONTAINER_TO_ID(qd.cnum);
  2866. qd.lun = CONTAINER_TO_LUN(qd.cnum);
  2867. }
  2868. else return -EINVAL;
  2869. qd.valid = fsa_dev_ptr[qd.cnum].valid != 0;
  2870. qd.locked = fsa_dev_ptr[qd.cnum].locked;
  2871. qd.deleted = fsa_dev_ptr[qd.cnum].deleted;
  2872. if (fsa_dev_ptr[qd.cnum].devname[0] == '\0')
  2873. qd.unmapped = 1;
  2874. else
  2875. qd.unmapped = 0;
  2876. strlcpy(qd.name, fsa_dev_ptr[qd.cnum].devname,
  2877. min(sizeof(qd.name), sizeof(fsa_dev_ptr[qd.cnum].devname) + 1));
  2878. if (copy_to_user(arg, &qd, sizeof (struct aac_query_disk)))
  2879. return -EFAULT;
  2880. return 0;
  2881. }
  2882. static int force_delete_disk(struct aac_dev *dev, void __user *arg)
  2883. {
  2884. struct aac_delete_disk dd;
  2885. struct fsa_dev_info *fsa_dev_ptr;
  2886. fsa_dev_ptr = dev->fsa_dev;
  2887. if (!fsa_dev_ptr)
  2888. return -EBUSY;
  2889. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  2890. return -EFAULT;
  2891. if (dd.cnum >= dev->maximum_num_containers)
  2892. return -EINVAL;
  2893. /*
  2894. * Mark this container as being deleted.
  2895. */
  2896. fsa_dev_ptr[dd.cnum].deleted = 1;
  2897. /*
  2898. * Mark the container as no longer valid
  2899. */
  2900. fsa_dev_ptr[dd.cnum].valid = 0;
  2901. return 0;
  2902. }
  2903. static int delete_disk(struct aac_dev *dev, void __user *arg)
  2904. {
  2905. struct aac_delete_disk dd;
  2906. struct fsa_dev_info *fsa_dev_ptr;
  2907. fsa_dev_ptr = dev->fsa_dev;
  2908. if (!fsa_dev_ptr)
  2909. return -EBUSY;
  2910. if (copy_from_user(&dd, arg, sizeof (struct aac_delete_disk)))
  2911. return -EFAULT;
  2912. if (dd.cnum >= dev->maximum_num_containers)
  2913. return -EINVAL;
  2914. /*
  2915. * If the container is locked, it can not be deleted by the API.
  2916. */
  2917. if (fsa_dev_ptr[dd.cnum].locked)
  2918. return -EBUSY;
  2919. else {
  2920. /*
  2921. * Mark the container as no longer being valid.
  2922. */
  2923. fsa_dev_ptr[dd.cnum].valid = 0;
  2924. fsa_dev_ptr[dd.cnum].devname[0] = '\0';
  2925. return 0;
  2926. }
  2927. }
  2928. int aac_dev_ioctl(struct aac_dev *dev, unsigned int cmd, void __user *arg)
  2929. {
  2930. switch (cmd) {
  2931. case FSACTL_QUERY_DISK:
  2932. return query_disk(dev, arg);
  2933. case FSACTL_DELETE_DISK:
  2934. return delete_disk(dev, arg);
  2935. case FSACTL_FORCE_DELETE_DISK:
  2936. return force_delete_disk(dev, arg);
  2937. case FSACTL_GET_CONTAINERS:
  2938. return aac_get_containers(dev);
  2939. default:
  2940. return -ENOTTY;
  2941. }
  2942. }
  2943. /**
  2944. * aac_srb_callback
  2945. * @context: the context set in the fib - here it is scsi cmd
  2946. * @fibptr: pointer to the fib
  2947. *
  2948. * Handles the completion of a scsi command to a non dasd device
  2949. */
  2950. static void aac_srb_callback(void *context, struct fib * fibptr)
  2951. {
  2952. struct aac_srb_reply *srbreply;
  2953. struct scsi_cmnd *scsicmd;
  2954. scsicmd = (struct scsi_cmnd *) context;
  2955. if (!aac_valid_context(scsicmd, fibptr))
  2956. return;
  2957. BUG_ON(fibptr == NULL);
  2958. srbreply = (struct aac_srb_reply *) fib_data(fibptr);
  2959. scsicmd->sense_buffer[0] = '\0'; /* Initialize sense valid flag to false */
  2960. if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
  2961. /* fast response */
  2962. srbreply->srb_status = cpu_to_le32(SRB_STATUS_SUCCESS);
  2963. srbreply->scsi_status = cpu_to_le32(SAM_STAT_GOOD);
  2964. } else {
  2965. /*
  2966. * Calculate resid for sg
  2967. */
  2968. scsi_set_resid(scsicmd, scsi_bufflen(scsicmd)
  2969. - le32_to_cpu(srbreply->data_xfer_length));
  2970. }
  2971. scsi_dma_unmap(scsicmd);
  2972. /* expose physical device if expose_physicald flag is on */
  2973. if (scsicmd->cmnd[0] == INQUIRY && !(scsicmd->cmnd[1] & 0x01)
  2974. && expose_physicals > 0)
  2975. aac_expose_phy_device(scsicmd);
  2976. /*
  2977. * First check the fib status
  2978. */
  2979. if (le32_to_cpu(srbreply->status) != ST_OK) {
  2980. int len;
  2981. pr_warn("aac_srb_callback: srb failed, status = %d\n",
  2982. le32_to_cpu(srbreply->status));
  2983. len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
  2984. SCSI_SENSE_BUFFERSIZE);
  2985. scsicmd->result = DID_ERROR << 16 | SAM_STAT_CHECK_CONDITION;
  2986. memcpy(scsicmd->sense_buffer,
  2987. srbreply->sense_data, len);
  2988. }
  2989. /*
  2990. * Next check the srb status
  2991. */
  2992. switch ((le32_to_cpu(srbreply->srb_status))&0x3f) {
  2993. case SRB_STATUS_ERROR_RECOVERY:
  2994. case SRB_STATUS_PENDING:
  2995. case SRB_STATUS_SUCCESS:
  2996. scsicmd->result = DID_OK << 16;
  2997. break;
  2998. case SRB_STATUS_DATA_OVERRUN:
  2999. switch (scsicmd->cmnd[0]) {
  3000. case READ_6:
  3001. case WRITE_6:
  3002. case READ_10:
  3003. case WRITE_10:
  3004. case READ_12:
  3005. case WRITE_12:
  3006. case READ_16:
  3007. case WRITE_16:
  3008. if (le32_to_cpu(srbreply->data_xfer_length)
  3009. < scsicmd->underflow)
  3010. pr_warn("aacraid: SCSI CMD underflow\n");
  3011. else
  3012. pr_warn("aacraid: SCSI CMD Data Overrun\n");
  3013. scsicmd->result = DID_ERROR << 16;
  3014. break;
  3015. case INQUIRY:
  3016. scsicmd->result = DID_OK << 16;
  3017. break;
  3018. default:
  3019. scsicmd->result = DID_OK << 16;
  3020. break;
  3021. }
  3022. break;
  3023. case SRB_STATUS_ABORTED:
  3024. scsicmd->result = DID_ABORT << 16;
  3025. break;
  3026. case SRB_STATUS_ABORT_FAILED:
  3027. /*
  3028. * Not sure about this one - but assuming the
  3029. * hba was trying to abort for some reason
  3030. */
  3031. scsicmd->result = DID_ERROR << 16;
  3032. break;
  3033. case SRB_STATUS_PARITY_ERROR:
  3034. scsicmd->result = DID_PARITY << 16;
  3035. break;
  3036. case SRB_STATUS_NO_DEVICE:
  3037. case SRB_STATUS_INVALID_PATH_ID:
  3038. case SRB_STATUS_INVALID_TARGET_ID:
  3039. case SRB_STATUS_INVALID_LUN:
  3040. case SRB_STATUS_SELECTION_TIMEOUT:
  3041. scsicmd->result = DID_NO_CONNECT << 16;
  3042. break;
  3043. case SRB_STATUS_COMMAND_TIMEOUT:
  3044. case SRB_STATUS_TIMEOUT:
  3045. scsicmd->result = DID_TIME_OUT << 16;
  3046. break;
  3047. case SRB_STATUS_BUSY:
  3048. scsicmd->result = DID_BUS_BUSY << 16;
  3049. break;
  3050. case SRB_STATUS_BUS_RESET:
  3051. scsicmd->result = DID_RESET << 16;
  3052. break;
  3053. case SRB_STATUS_MESSAGE_REJECTED:
  3054. scsicmd->result = DID_ERROR << 16;
  3055. break;
  3056. case SRB_STATUS_REQUEST_FLUSHED:
  3057. case SRB_STATUS_ERROR:
  3058. case SRB_STATUS_INVALID_REQUEST:
  3059. case SRB_STATUS_REQUEST_SENSE_FAILED:
  3060. case SRB_STATUS_NO_HBA:
  3061. case SRB_STATUS_UNEXPECTED_BUS_FREE:
  3062. case SRB_STATUS_PHASE_SEQUENCE_FAILURE:
  3063. case SRB_STATUS_BAD_SRB_BLOCK_LENGTH:
  3064. case SRB_STATUS_DELAYED_RETRY:
  3065. case SRB_STATUS_BAD_FUNCTION:
  3066. case SRB_STATUS_NOT_STARTED:
  3067. case SRB_STATUS_NOT_IN_USE:
  3068. case SRB_STATUS_FORCE_ABORT:
  3069. case SRB_STATUS_DOMAIN_VALIDATION_FAIL:
  3070. default:
  3071. #ifdef AAC_DETAILED_STATUS_INFO
  3072. pr_info("aacraid: SRB ERROR(%u) %s scsi cmd 0x%x -scsi status 0x%x\n",
  3073. le32_to_cpu(srbreply->srb_status) & 0x3F,
  3074. aac_get_status_string(
  3075. le32_to_cpu(srbreply->srb_status) & 0x3F),
  3076. scsicmd->cmnd[0],
  3077. le32_to_cpu(srbreply->scsi_status));
  3078. #endif
  3079. /*
  3080. * When the CC bit is SET by the host in ATA pass thru CDB,
  3081. * driver is supposed to return DID_OK
  3082. *
  3083. * When the CC bit is RESET by the host, driver should
  3084. * return DID_ERROR
  3085. */
  3086. if ((scsicmd->cmnd[0] == ATA_12)
  3087. || (scsicmd->cmnd[0] == ATA_16)) {
  3088. if (scsicmd->cmnd[2] & (0x01 << 5)) {
  3089. scsicmd->result = DID_OK << 16;
  3090. } else {
  3091. scsicmd->result = DID_ERROR << 16;
  3092. }
  3093. } else {
  3094. scsicmd->result = DID_ERROR << 16;
  3095. }
  3096. break;
  3097. }
  3098. if (le32_to_cpu(srbreply->scsi_status)
  3099. == SAM_STAT_CHECK_CONDITION) {
  3100. int len;
  3101. scsicmd->result |= SAM_STAT_CHECK_CONDITION;
  3102. len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
  3103. SCSI_SENSE_BUFFERSIZE);
  3104. #ifdef AAC_DETAILED_STATUS_INFO
  3105. pr_warn("aac_srb_callback: check condition, status = %d len=%d\n",
  3106. le32_to_cpu(srbreply->status), len);
  3107. #endif
  3108. memcpy(scsicmd->sense_buffer,
  3109. srbreply->sense_data, len);
  3110. }
  3111. /*
  3112. * OR in the scsi status (already shifted up a bit)
  3113. */
  3114. scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
  3115. aac_fib_complete(fibptr);
  3116. aac_scsi_done(scsicmd);
  3117. }
  3118. static void hba_resp_task_complete(struct aac_dev *dev,
  3119. struct scsi_cmnd *scsicmd,
  3120. struct aac_hba_resp *err) {
  3121. scsicmd->result = err->status;
  3122. /* set residual count */
  3123. scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
  3124. switch (err->status) {
  3125. case SAM_STAT_GOOD:
  3126. scsicmd->result |= DID_OK << 16;
  3127. break;
  3128. case SAM_STAT_CHECK_CONDITION:
  3129. {
  3130. int len;
  3131. len = min_t(u8, err->sense_response_data_len,
  3132. SCSI_SENSE_BUFFERSIZE);
  3133. if (len)
  3134. memcpy(scsicmd->sense_buffer,
  3135. err->sense_response_buf, len);
  3136. scsicmd->result |= DID_OK << 16;
  3137. break;
  3138. }
  3139. case SAM_STAT_BUSY:
  3140. scsicmd->result |= DID_BUS_BUSY << 16;
  3141. break;
  3142. case SAM_STAT_TASK_ABORTED:
  3143. scsicmd->result |= DID_ABORT << 16;
  3144. break;
  3145. case SAM_STAT_RESERVATION_CONFLICT:
  3146. case SAM_STAT_TASK_SET_FULL:
  3147. default:
  3148. scsicmd->result |= DID_ERROR << 16;
  3149. break;
  3150. }
  3151. }
  3152. static void hba_resp_task_failure(struct aac_dev *dev,
  3153. struct scsi_cmnd *scsicmd,
  3154. struct aac_hba_resp *err)
  3155. {
  3156. switch (err->status) {
  3157. case HBA_RESP_STAT_HBAMODE_DISABLED:
  3158. {
  3159. u32 bus, cid;
  3160. bus = aac_logical_to_phys(scmd_channel(scsicmd));
  3161. cid = scmd_id(scsicmd);
  3162. if (dev->hba_map[bus][cid].devtype == AAC_DEVTYPE_NATIVE_RAW) {
  3163. dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
  3164. dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
  3165. }
  3166. scsicmd->result = DID_NO_CONNECT << 16;
  3167. break;
  3168. }
  3169. case HBA_RESP_STAT_IO_ERROR:
  3170. case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
  3171. scsicmd->result = DID_OK << 16 | SAM_STAT_BUSY;
  3172. break;
  3173. case HBA_RESP_STAT_IO_ABORTED:
  3174. scsicmd->result = DID_ABORT << 16;
  3175. break;
  3176. case HBA_RESP_STAT_INVALID_DEVICE:
  3177. scsicmd->result = DID_NO_CONNECT << 16;
  3178. break;
  3179. case HBA_RESP_STAT_UNDERRUN:
  3180. /* UNDERRUN is OK */
  3181. scsicmd->result = DID_OK << 16;
  3182. break;
  3183. case HBA_RESP_STAT_OVERRUN:
  3184. default:
  3185. scsicmd->result = DID_ERROR << 16;
  3186. break;
  3187. }
  3188. }
  3189. /**
  3190. * aac_hba_callback
  3191. * @context: the context set in the fib - here it is scsi cmd
  3192. * @fibptr: pointer to the fib
  3193. *
  3194. * Handles the completion of a native HBA scsi command
  3195. */
  3196. void aac_hba_callback(void *context, struct fib *fibptr)
  3197. {
  3198. struct aac_dev *dev;
  3199. struct scsi_cmnd *scsicmd;
  3200. struct aac_hba_resp *err =
  3201. &((struct aac_native_hba *)fibptr->hw_fib_va)->resp.err;
  3202. scsicmd = (struct scsi_cmnd *) context;
  3203. if (!aac_valid_context(scsicmd, fibptr))
  3204. return;
  3205. WARN_ON(fibptr == NULL);
  3206. dev = fibptr->dev;
  3207. if (!(fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF))
  3208. scsi_dma_unmap(scsicmd);
  3209. if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
  3210. /* fast response */
  3211. scsicmd->result = DID_OK << 16;
  3212. goto out;
  3213. }
  3214. switch (err->service_response) {
  3215. case HBA_RESP_SVCRES_TASK_COMPLETE:
  3216. hba_resp_task_complete(dev, scsicmd, err);
  3217. break;
  3218. case HBA_RESP_SVCRES_FAILURE:
  3219. hba_resp_task_failure(dev, scsicmd, err);
  3220. break;
  3221. case HBA_RESP_SVCRES_TMF_REJECTED:
  3222. scsicmd->result = DID_ERROR << 16;
  3223. break;
  3224. case HBA_RESP_SVCRES_TMF_LUN_INVALID:
  3225. scsicmd->result = DID_NO_CONNECT << 16;
  3226. break;
  3227. case HBA_RESP_SVCRES_TMF_COMPLETE:
  3228. case HBA_RESP_SVCRES_TMF_SUCCEEDED:
  3229. scsicmd->result = DID_OK << 16;
  3230. break;
  3231. default:
  3232. scsicmd->result = DID_ERROR << 16;
  3233. break;
  3234. }
  3235. out:
  3236. aac_fib_complete(fibptr);
  3237. if (fibptr->flags & FIB_CONTEXT_FLAG_NATIVE_HBA_TMF)
  3238. aac_priv(scsicmd)->sent_command = 1;
  3239. else
  3240. aac_scsi_done(scsicmd);
  3241. }
  3242. /**
  3243. * aac_send_srb_fib
  3244. * @scsicmd: the scsi command block
  3245. *
  3246. * This routine will form a FIB and fill in the aac_srb from the
  3247. * scsicmd passed in.
  3248. */
  3249. static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
  3250. {
  3251. struct fib* cmd_fibcontext;
  3252. struct aac_dev* dev;
  3253. int status;
  3254. dev = (struct aac_dev *)scsicmd->device->host->hostdata;
  3255. if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
  3256. scsicmd->device->lun > 7) {
  3257. scsicmd->result = DID_NO_CONNECT << 16;
  3258. aac_scsi_done(scsicmd);
  3259. return 0;
  3260. }
  3261. /*
  3262. * Allocate and initialize a Fib then setup a BlockWrite command
  3263. */
  3264. cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
  3265. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  3266. status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
  3267. /*
  3268. * Check that the command queued to the controller
  3269. */
  3270. if (status == -EINPROGRESS)
  3271. return 0;
  3272. printk(KERN_WARNING "aac_srb: aac_fib_send failed with status: %d\n", status);
  3273. aac_fib_complete(cmd_fibcontext);
  3274. aac_fib_free(cmd_fibcontext);
  3275. return -1;
  3276. }
  3277. /**
  3278. * aac_send_hba_fib
  3279. * @scsicmd: the scsi command block
  3280. *
  3281. * This routine will form a FIB and fill in the aac_hba_cmd_req from the
  3282. * scsicmd passed in.
  3283. */
  3284. static int aac_send_hba_fib(struct scsi_cmnd *scsicmd)
  3285. {
  3286. struct fib *cmd_fibcontext;
  3287. struct aac_dev *dev;
  3288. int status;
  3289. dev = shost_priv(scsicmd->device->host);
  3290. if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
  3291. scsicmd->device->lun > AAC_MAX_LUN - 1) {
  3292. scsicmd->result = DID_NO_CONNECT << 16;
  3293. aac_scsi_done(scsicmd);
  3294. return 0;
  3295. }
  3296. /*
  3297. * Allocate and initialize a Fib then setup a BlockWrite command
  3298. */
  3299. cmd_fibcontext = aac_fib_alloc_tag(dev, scsicmd);
  3300. if (!cmd_fibcontext)
  3301. return -1;
  3302. aac_priv(scsicmd)->owner = AAC_OWNER_FIRMWARE;
  3303. status = aac_adapter_hba(cmd_fibcontext, scsicmd);
  3304. /*
  3305. * Check that the command queued to the controller
  3306. */
  3307. if (status == -EINPROGRESS)
  3308. return 0;
  3309. pr_warn("aac_hba_cmd_req: aac_fib_send failed with status: %d\n",
  3310. status);
  3311. aac_fib_complete(cmd_fibcontext);
  3312. aac_fib_free(cmd_fibcontext);
  3313. return -1;
  3314. }
  3315. static long aac_build_sg(struct scsi_cmnd *scsicmd, struct sgmap *psg)
  3316. {
  3317. unsigned long byte_count = 0;
  3318. int nseg;
  3319. struct scatterlist *sg;
  3320. int i;
  3321. // Get rid of old data
  3322. psg->count = 0;
  3323. psg->sg[0].addr = 0;
  3324. psg->sg[0].count = 0;
  3325. nseg = scsi_dma_map(scsicmd);
  3326. if (nseg <= 0)
  3327. return nseg;
  3328. psg->count = cpu_to_le32(nseg);
  3329. scsi_for_each_sg(scsicmd, sg, nseg, i) {
  3330. psg->sg[i].addr = cpu_to_le32(sg_dma_address(sg));
  3331. psg->sg[i].count = cpu_to_le32(sg_dma_len(sg));
  3332. byte_count += sg_dma_len(sg);
  3333. }
  3334. /* hba wants the size to be exact */
  3335. if (byte_count > scsi_bufflen(scsicmd)) {
  3336. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  3337. (byte_count - scsi_bufflen(scsicmd));
  3338. psg->sg[i-1].count = cpu_to_le32(temp);
  3339. byte_count = scsi_bufflen(scsicmd);
  3340. }
  3341. /* Check for command underflow */
  3342. if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
  3343. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  3344. byte_count, scsicmd->underflow);
  3345. }
  3346. return byte_count;
  3347. }
  3348. static long aac_build_sg64(struct scsi_cmnd *scsicmd, struct sgmap64 *psg)
  3349. {
  3350. unsigned long byte_count = 0;
  3351. u64 addr;
  3352. int nseg;
  3353. struct scatterlist *sg;
  3354. int i;
  3355. // Get rid of old data
  3356. psg->count = 0;
  3357. psg->sg[0].addr[0] = 0;
  3358. psg->sg[0].addr[1] = 0;
  3359. psg->sg[0].count = 0;
  3360. nseg = scsi_dma_map(scsicmd);
  3361. if (nseg <= 0)
  3362. return nseg;
  3363. scsi_for_each_sg(scsicmd, sg, nseg, i) {
  3364. int count = sg_dma_len(sg);
  3365. addr = sg_dma_address(sg);
  3366. psg->sg[i].addr[0] = cpu_to_le32(addr & 0xffffffff);
  3367. psg->sg[i].addr[1] = cpu_to_le32(addr>>32);
  3368. psg->sg[i].count = cpu_to_le32(count);
  3369. byte_count += count;
  3370. }
  3371. psg->count = cpu_to_le32(nseg);
  3372. /* hba wants the size to be exact */
  3373. if (byte_count > scsi_bufflen(scsicmd)) {
  3374. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  3375. (byte_count - scsi_bufflen(scsicmd));
  3376. psg->sg[i-1].count = cpu_to_le32(temp);
  3377. byte_count = scsi_bufflen(scsicmd);
  3378. }
  3379. /* Check for command underflow */
  3380. if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
  3381. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  3382. byte_count, scsicmd->underflow);
  3383. }
  3384. return byte_count;
  3385. }
  3386. static long aac_build_sgraw(struct scsi_cmnd *scsicmd, struct sgmapraw *psg)
  3387. {
  3388. unsigned long byte_count = 0;
  3389. int nseg;
  3390. struct scatterlist *sg;
  3391. int i;
  3392. // Get rid of old data
  3393. psg->count = 0;
  3394. psg->sg[0].next = 0;
  3395. psg->sg[0].prev = 0;
  3396. psg->sg[0].addr[0] = 0;
  3397. psg->sg[0].addr[1] = 0;
  3398. psg->sg[0].count = 0;
  3399. psg->sg[0].flags = 0;
  3400. nseg = scsi_dma_map(scsicmd);
  3401. if (nseg <= 0)
  3402. return nseg;
  3403. scsi_for_each_sg(scsicmd, sg, nseg, i) {
  3404. int count = sg_dma_len(sg);
  3405. u64 addr = sg_dma_address(sg);
  3406. psg->sg[i].next = 0;
  3407. psg->sg[i].prev = 0;
  3408. psg->sg[i].addr[1] = cpu_to_le32((u32)(addr>>32));
  3409. psg->sg[i].addr[0] = cpu_to_le32((u32)(addr & 0xffffffff));
  3410. psg->sg[i].count = cpu_to_le32(count);
  3411. psg->sg[i].flags = 0;
  3412. byte_count += count;
  3413. }
  3414. psg->count = cpu_to_le32(nseg);
  3415. /* hba wants the size to be exact */
  3416. if (byte_count > scsi_bufflen(scsicmd)) {
  3417. u32 temp = le32_to_cpu(psg->sg[i-1].count) -
  3418. (byte_count - scsi_bufflen(scsicmd));
  3419. psg->sg[i-1].count = cpu_to_le32(temp);
  3420. byte_count = scsi_bufflen(scsicmd);
  3421. }
  3422. /* Check for command underflow */
  3423. if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
  3424. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  3425. byte_count, scsicmd->underflow);
  3426. }
  3427. return byte_count;
  3428. }
  3429. static long aac_build_sgraw2(struct scsi_cmnd *scsicmd,
  3430. struct aac_raw_io2 *rio2, int sg_max)
  3431. {
  3432. unsigned long byte_count = 0;
  3433. int nseg;
  3434. struct scatterlist *sg;
  3435. int i, conformable = 0;
  3436. u32 min_size = PAGE_SIZE, cur_size;
  3437. nseg = scsi_dma_map(scsicmd);
  3438. if (nseg <= 0)
  3439. return nseg;
  3440. scsi_for_each_sg(scsicmd, sg, nseg, i) {
  3441. int count = sg_dma_len(sg);
  3442. u64 addr = sg_dma_address(sg);
  3443. BUG_ON(i >= sg_max);
  3444. rio2->sge[i].addrHigh = cpu_to_le32((u32)(addr>>32));
  3445. rio2->sge[i].addrLow = cpu_to_le32((u32)(addr & 0xffffffff));
  3446. cur_size = cpu_to_le32(count);
  3447. rio2->sge[i].length = cur_size;
  3448. rio2->sge[i].flags = 0;
  3449. if (i == 0) {
  3450. conformable = 1;
  3451. rio2->sgeFirstSize = cur_size;
  3452. } else if (i == 1) {
  3453. rio2->sgeNominalSize = cur_size;
  3454. min_size = cur_size;
  3455. } else if ((i+1) < nseg && cur_size != rio2->sgeNominalSize) {
  3456. conformable = 0;
  3457. if (cur_size < min_size)
  3458. min_size = cur_size;
  3459. }
  3460. byte_count += count;
  3461. }
  3462. /* hba wants the size to be exact */
  3463. if (byte_count > scsi_bufflen(scsicmd)) {
  3464. u32 temp = le32_to_cpu(rio2->sge[i-1].length) -
  3465. (byte_count - scsi_bufflen(scsicmd));
  3466. rio2->sge[i-1].length = cpu_to_le32(temp);
  3467. byte_count = scsi_bufflen(scsicmd);
  3468. }
  3469. rio2->sgeCnt = cpu_to_le32(nseg);
  3470. rio2->flags |= cpu_to_le16(RIO2_SG_FORMAT_IEEE1212);
  3471. /* not conformable: evaluate required sg elements */
  3472. if (!conformable) {
  3473. int j, nseg_new = nseg, err_found;
  3474. for (i = min_size / PAGE_SIZE; i >= 1; --i) {
  3475. err_found = 0;
  3476. nseg_new = 2;
  3477. for (j = 1; j < nseg - 1; ++j) {
  3478. if (rio2->sge[j].length % (i*PAGE_SIZE)) {
  3479. err_found = 1;
  3480. break;
  3481. }
  3482. nseg_new += (rio2->sge[j].length / (i*PAGE_SIZE));
  3483. }
  3484. if (!err_found)
  3485. break;
  3486. }
  3487. if (i > 0 && nseg_new <= sg_max) {
  3488. int ret = aac_convert_sgraw2(rio2, i, nseg, nseg_new);
  3489. if (ret < 0)
  3490. return ret;
  3491. }
  3492. } else
  3493. rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
  3494. /* Check for command underflow */
  3495. if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
  3496. printk(KERN_WARNING"aacraid: cmd len %08lX cmd underflow %08X\n",
  3497. byte_count, scsicmd->underflow);
  3498. }
  3499. return byte_count;
  3500. }
  3501. static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int nseg_new)
  3502. {
  3503. struct sge_ieee1212 *sge;
  3504. int i, j, pos;
  3505. u32 addr_low;
  3506. if (aac_convert_sgl == 0)
  3507. return 0;
  3508. sge = kmalloc_array(nseg_new, sizeof(*sge), GFP_ATOMIC);
  3509. if (sge == NULL)
  3510. return -ENOMEM;
  3511. for (i = 1, pos = 1; i < nseg-1; ++i) {
  3512. for (j = 0; j < rio2->sge[i].length / (pages * PAGE_SIZE); ++j) {
  3513. addr_low = rio2->sge[i].addrLow + j * pages * PAGE_SIZE;
  3514. sge[pos].addrLow = addr_low;
  3515. sge[pos].addrHigh = rio2->sge[i].addrHigh;
  3516. if (addr_low < rio2->sge[i].addrLow)
  3517. sge[pos].addrHigh++;
  3518. sge[pos].length = pages * PAGE_SIZE;
  3519. sge[pos].flags = 0;
  3520. pos++;
  3521. }
  3522. }
  3523. sge[pos] = rio2->sge[nseg-1];
  3524. memcpy(&rio2->sge[1], &sge[1], (nseg_new-1)*sizeof(struct sge_ieee1212));
  3525. kfree(sge);
  3526. rio2->sgeCnt = cpu_to_le32(nseg_new);
  3527. rio2->flags |= cpu_to_le16(RIO2_SGL_CONFORMANT);
  3528. rio2->sgeNominalSize = pages * PAGE_SIZE;
  3529. return 0;
  3530. }
  3531. static long aac_build_sghba(struct scsi_cmnd *scsicmd,
  3532. struct aac_hba_cmd_req *hbacmd,
  3533. int sg_max,
  3534. u64 sg_address)
  3535. {
  3536. unsigned long byte_count = 0;
  3537. int nseg;
  3538. struct scatterlist *sg;
  3539. int i;
  3540. u32 cur_size;
  3541. struct aac_hba_sgl *sge;
  3542. nseg = scsi_dma_map(scsicmd);
  3543. if (nseg <= 0) {
  3544. byte_count = nseg;
  3545. goto out;
  3546. }
  3547. if (nseg > HBA_MAX_SG_EMBEDDED)
  3548. sge = &hbacmd->sge[2];
  3549. else
  3550. sge = &hbacmd->sge[0];
  3551. scsi_for_each_sg(scsicmd, sg, nseg, i) {
  3552. int count = sg_dma_len(sg);
  3553. u64 addr = sg_dma_address(sg);
  3554. WARN_ON(i >= sg_max);
  3555. sge->addr_hi = cpu_to_le32((u32)(addr>>32));
  3556. sge->addr_lo = cpu_to_le32((u32)(addr & 0xffffffff));
  3557. cur_size = cpu_to_le32(count);
  3558. sge->len = cur_size;
  3559. sge->flags = 0;
  3560. byte_count += count;
  3561. sge++;
  3562. }
  3563. sge--;
  3564. /* hba wants the size to be exact */
  3565. if (byte_count > scsi_bufflen(scsicmd)) {
  3566. u32 temp;
  3567. temp = le32_to_cpu(sge->len) - byte_count
  3568. - scsi_bufflen(scsicmd);
  3569. sge->len = cpu_to_le32(temp);
  3570. byte_count = scsi_bufflen(scsicmd);
  3571. }
  3572. if (nseg <= HBA_MAX_SG_EMBEDDED) {
  3573. hbacmd->emb_data_desc_count = cpu_to_le32(nseg);
  3574. sge->flags = cpu_to_le32(0x40000000);
  3575. } else {
  3576. /* not embedded */
  3577. hbacmd->sge[0].flags = cpu_to_le32(0x80000000);
  3578. hbacmd->emb_data_desc_count = (u8)cpu_to_le32(1);
  3579. hbacmd->sge[0].addr_hi = (u32)cpu_to_le32(sg_address >> 32);
  3580. hbacmd->sge[0].addr_lo =
  3581. cpu_to_le32((u32)(sg_address & 0xffffffff));
  3582. }
  3583. /* Check for command underflow */
  3584. if (scsicmd->underflow && (byte_count < scsicmd->underflow)) {
  3585. pr_warn("aacraid: cmd len %08lX cmd underflow %08X\n",
  3586. byte_count, scsicmd->underflow);
  3587. }
  3588. out:
  3589. return byte_count;
  3590. }
  3591. #ifdef AAC_DETAILED_STATUS_INFO
  3592. struct aac_srb_status_info {
  3593. u32 status;
  3594. char *str;
  3595. };
  3596. static struct aac_srb_status_info srb_status_info[] = {
  3597. { SRB_STATUS_PENDING, "Pending Status"},
  3598. { SRB_STATUS_SUCCESS, "Success"},
  3599. { SRB_STATUS_ABORTED, "Aborted Command"},
  3600. { SRB_STATUS_ABORT_FAILED, "Abort Failed"},
  3601. { SRB_STATUS_ERROR, "Error Event"},
  3602. { SRB_STATUS_BUSY, "Device Busy"},
  3603. { SRB_STATUS_INVALID_REQUEST, "Invalid Request"},
  3604. { SRB_STATUS_INVALID_PATH_ID, "Invalid Path ID"},
  3605. { SRB_STATUS_NO_DEVICE, "No Device"},
  3606. { SRB_STATUS_TIMEOUT, "Timeout"},
  3607. { SRB_STATUS_SELECTION_TIMEOUT, "Selection Timeout"},
  3608. { SRB_STATUS_COMMAND_TIMEOUT, "Command Timeout"},
  3609. { SRB_STATUS_MESSAGE_REJECTED, "Message Rejected"},
  3610. { SRB_STATUS_BUS_RESET, "Bus Reset"},
  3611. { SRB_STATUS_PARITY_ERROR, "Parity Error"},
  3612. { SRB_STATUS_REQUEST_SENSE_FAILED,"Request Sense Failed"},
  3613. { SRB_STATUS_NO_HBA, "No HBA"},
  3614. { SRB_STATUS_DATA_OVERRUN, "Data Overrun/Data Underrun"},
  3615. { SRB_STATUS_UNEXPECTED_BUS_FREE,"Unexpected Bus Free"},
  3616. { SRB_STATUS_PHASE_SEQUENCE_FAILURE,"Phase Error"},
  3617. { SRB_STATUS_BAD_SRB_BLOCK_LENGTH,"Bad Srb Block Length"},
  3618. { SRB_STATUS_REQUEST_FLUSHED, "Request Flushed"},
  3619. { SRB_STATUS_DELAYED_RETRY, "Delayed Retry"},
  3620. { SRB_STATUS_INVALID_LUN, "Invalid LUN"},
  3621. { SRB_STATUS_INVALID_TARGET_ID, "Invalid TARGET ID"},
  3622. { SRB_STATUS_BAD_FUNCTION, "Bad Function"},
  3623. { SRB_STATUS_ERROR_RECOVERY, "Error Recovery"},
  3624. { SRB_STATUS_NOT_STARTED, "Not Started"},
  3625. { SRB_STATUS_NOT_IN_USE, "Not In Use"},
  3626. { SRB_STATUS_FORCE_ABORT, "Force Abort"},
  3627. { SRB_STATUS_DOMAIN_VALIDATION_FAIL,"Domain Validation Failure"},
  3628. { 0xff, "Unknown Error"}
  3629. };
  3630. char *aac_get_status_string(u32 status)
  3631. {
  3632. int i;
  3633. for (i = 0; i < ARRAY_SIZE(srb_status_info); i++)
  3634. if (srb_status_info[i].status == status)
  3635. return srb_status_info[i].str;
  3636. return "Bad Status Code";
  3637. }
  3638. #endif