aachba.c 99 KB

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