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