aachba.c 113 KB

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