aachba.c 80 KB

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