aachba.c 99 KB

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