aachba.c 85 KB

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