aachba.c 118 KB

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