qla_iocb.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/blkdev.h>
  9. #include <linux/delay.h>
  10. #include <scsi/scsi_tcq.h>
  11. static void qla25xx_set_que(srb_t *, struct rsp_que **);
  12. /**
  13. * qla2x00_get_cmd_direction() - Determine control_flag data direction.
  14. * @cmd: SCSI command
  15. *
  16. * Returns the proper CF_* direction based on CDB.
  17. */
  18. static inline uint16_t
  19. qla2x00_get_cmd_direction(srb_t *sp)
  20. {
  21. uint16_t cflags;
  22. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  23. cflags = 0;
  24. /* Set transfer direction */
  25. if (cmd->sc_data_direction == DMA_TO_DEVICE) {
  26. cflags = CF_WRITE;
  27. sp->fcport->vha->hw->qla_stats.output_bytes +=
  28. scsi_bufflen(cmd);
  29. } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
  30. cflags = CF_READ;
  31. sp->fcport->vha->hw->qla_stats.input_bytes +=
  32. scsi_bufflen(cmd);
  33. }
  34. return (cflags);
  35. }
  36. /**
  37. * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and
  38. * Continuation Type 0 IOCBs to allocate.
  39. *
  40. * @dsds: number of data segment decriptors needed
  41. *
  42. * Returns the number of IOCB entries needed to store @dsds.
  43. */
  44. uint16_t
  45. qla2x00_calc_iocbs_32(uint16_t dsds)
  46. {
  47. uint16_t iocbs;
  48. iocbs = 1;
  49. if (dsds > 3) {
  50. iocbs += (dsds - 3) / 7;
  51. if ((dsds - 3) % 7)
  52. iocbs++;
  53. }
  54. return (iocbs);
  55. }
  56. /**
  57. * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and
  58. * Continuation Type 1 IOCBs to allocate.
  59. *
  60. * @dsds: number of data segment decriptors needed
  61. *
  62. * Returns the number of IOCB entries needed to store @dsds.
  63. */
  64. uint16_t
  65. qla2x00_calc_iocbs_64(uint16_t dsds)
  66. {
  67. uint16_t iocbs;
  68. iocbs = 1;
  69. if (dsds > 2) {
  70. iocbs += (dsds - 2) / 5;
  71. if ((dsds - 2) % 5)
  72. iocbs++;
  73. }
  74. return (iocbs);
  75. }
  76. /**
  77. * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB.
  78. * @ha: HA context
  79. *
  80. * Returns a pointer to the Continuation Type 0 IOCB packet.
  81. */
  82. static inline cont_entry_t *
  83. qla2x00_prep_cont_type0_iocb(struct scsi_qla_host *vha)
  84. {
  85. cont_entry_t *cont_pkt;
  86. struct req_que *req = vha->req;
  87. /* Adjust ring index. */
  88. req->ring_index++;
  89. if (req->ring_index == req->length) {
  90. req->ring_index = 0;
  91. req->ring_ptr = req->ring;
  92. } else {
  93. req->ring_ptr++;
  94. }
  95. cont_pkt = (cont_entry_t *)req->ring_ptr;
  96. /* Load packet defaults. */
  97. *((uint32_t *)(&cont_pkt->entry_type)) =
  98. __constant_cpu_to_le32(CONTINUE_TYPE);
  99. return (cont_pkt);
  100. }
  101. /**
  102. * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB.
  103. * @ha: HA context
  104. *
  105. * Returns a pointer to the continuation type 1 IOCB packet.
  106. */
  107. static inline cont_a64_entry_t *
  108. qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *vha, struct req_que *req)
  109. {
  110. cont_a64_entry_t *cont_pkt;
  111. /* Adjust ring index. */
  112. req->ring_index++;
  113. if (req->ring_index == req->length) {
  114. req->ring_index = 0;
  115. req->ring_ptr = req->ring;
  116. } else {
  117. req->ring_ptr++;
  118. }
  119. cont_pkt = (cont_a64_entry_t *)req->ring_ptr;
  120. /* Load packet defaults. */
  121. *((uint32_t *)(&cont_pkt->entry_type)) =
  122. __constant_cpu_to_le32(CONTINUE_A64_TYPE);
  123. return (cont_pkt);
  124. }
  125. static inline int
  126. qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts)
  127. {
  128. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  129. uint8_t guard = scsi_host_get_guard(cmd->device->host);
  130. /* We only support T10 DIF right now */
  131. if (guard != SHOST_DIX_GUARD_CRC) {
  132. ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3007,
  133. "Unsupported guard: %d for cmd=%p.\n", guard, cmd);
  134. return 0;
  135. }
  136. /* We always use DIFF Bundling for best performance */
  137. *fw_prot_opts = 0;
  138. /* Translate SCSI opcode to a protection opcode */
  139. switch (scsi_get_prot_op(cmd)) {
  140. case SCSI_PROT_READ_STRIP:
  141. *fw_prot_opts |= PO_MODE_DIF_REMOVE;
  142. break;
  143. case SCSI_PROT_WRITE_INSERT:
  144. *fw_prot_opts |= PO_MODE_DIF_INSERT;
  145. break;
  146. case SCSI_PROT_READ_INSERT:
  147. *fw_prot_opts |= PO_MODE_DIF_INSERT;
  148. break;
  149. case SCSI_PROT_WRITE_STRIP:
  150. *fw_prot_opts |= PO_MODE_DIF_REMOVE;
  151. break;
  152. case SCSI_PROT_READ_PASS:
  153. *fw_prot_opts |= PO_MODE_DIF_PASS;
  154. break;
  155. case SCSI_PROT_WRITE_PASS:
  156. *fw_prot_opts |= PO_MODE_DIF_PASS;
  157. break;
  158. default: /* Normal Request */
  159. *fw_prot_opts |= PO_MODE_DIF_PASS;
  160. break;
  161. }
  162. return scsi_prot_sg_count(cmd);
  163. }
  164. /*
  165. * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit
  166. * capable IOCB types.
  167. *
  168. * @sp: SRB command to process
  169. * @cmd_pkt: Command type 2 IOCB
  170. * @tot_dsds: Total number of segments to transfer
  171. */
  172. void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt,
  173. uint16_t tot_dsds)
  174. {
  175. uint16_t avail_dsds;
  176. uint32_t *cur_dsd;
  177. scsi_qla_host_t *vha;
  178. struct scsi_cmnd *cmd;
  179. struct scatterlist *sg;
  180. int i;
  181. cmd = GET_CMD_SP(sp);
  182. /* Update entry type to indicate Command Type 2 IOCB */
  183. *((uint32_t *)(&cmd_pkt->entry_type)) =
  184. __constant_cpu_to_le32(COMMAND_TYPE);
  185. /* No data transfer */
  186. if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
  187. cmd_pkt->byte_count = __constant_cpu_to_le32(0);
  188. return;
  189. }
  190. vha = sp->fcport->vha;
  191. cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp));
  192. /* Three DSDs are available in the Command Type 2 IOCB */
  193. avail_dsds = 3;
  194. cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
  195. /* Load data segments */
  196. scsi_for_each_sg(cmd, sg, tot_dsds, i) {
  197. cont_entry_t *cont_pkt;
  198. /* Allocate additional continuation packets? */
  199. if (avail_dsds == 0) {
  200. /*
  201. * Seven DSDs are available in the Continuation
  202. * Type 0 IOCB.
  203. */
  204. cont_pkt = qla2x00_prep_cont_type0_iocb(vha);
  205. cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address;
  206. avail_dsds = 7;
  207. }
  208. *cur_dsd++ = cpu_to_le32(sg_dma_address(sg));
  209. *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
  210. avail_dsds--;
  211. }
  212. }
  213. /**
  214. * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit
  215. * capable IOCB types.
  216. *
  217. * @sp: SRB command to process
  218. * @cmd_pkt: Command type 3 IOCB
  219. * @tot_dsds: Total number of segments to transfer
  220. */
  221. void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt,
  222. uint16_t tot_dsds)
  223. {
  224. uint16_t avail_dsds;
  225. uint32_t *cur_dsd;
  226. scsi_qla_host_t *vha;
  227. struct scsi_cmnd *cmd;
  228. struct scatterlist *sg;
  229. int i;
  230. cmd = GET_CMD_SP(sp);
  231. /* Update entry type to indicate Command Type 3 IOCB */
  232. *((uint32_t *)(&cmd_pkt->entry_type)) =
  233. __constant_cpu_to_le32(COMMAND_A64_TYPE);
  234. /* No data transfer */
  235. if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
  236. cmd_pkt->byte_count = __constant_cpu_to_le32(0);
  237. return;
  238. }
  239. vha = sp->fcport->vha;
  240. cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp));
  241. /* Two DSDs are available in the Command Type 3 IOCB */
  242. avail_dsds = 2;
  243. cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
  244. /* Load data segments */
  245. scsi_for_each_sg(cmd, sg, tot_dsds, i) {
  246. dma_addr_t sle_dma;
  247. cont_a64_entry_t *cont_pkt;
  248. /* Allocate additional continuation packets? */
  249. if (avail_dsds == 0) {
  250. /*
  251. * Five DSDs are available in the Continuation
  252. * Type 1 IOCB.
  253. */
  254. cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req);
  255. cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
  256. avail_dsds = 5;
  257. }
  258. sle_dma = sg_dma_address(sg);
  259. *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
  260. *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
  261. *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
  262. avail_dsds--;
  263. }
  264. }
  265. /**
  266. * qla2x00_start_scsi() - Send a SCSI command to the ISP
  267. * @sp: command to send to the ISP
  268. *
  269. * Returns non-zero if a failure occurred, else zero.
  270. */
  271. int
  272. qla2x00_start_scsi(srb_t *sp)
  273. {
  274. int ret, nseg;
  275. unsigned long flags;
  276. scsi_qla_host_t *vha;
  277. struct scsi_cmnd *cmd;
  278. uint32_t *clr_ptr;
  279. uint32_t index;
  280. uint32_t handle;
  281. cmd_entry_t *cmd_pkt;
  282. uint16_t cnt;
  283. uint16_t req_cnt;
  284. uint16_t tot_dsds;
  285. struct device_reg_2xxx __iomem *reg;
  286. struct qla_hw_data *ha;
  287. struct req_que *req;
  288. struct rsp_que *rsp;
  289. char tag[2];
  290. /* Setup device pointers. */
  291. ret = 0;
  292. vha = sp->fcport->vha;
  293. ha = vha->hw;
  294. reg = &ha->iobase->isp;
  295. cmd = GET_CMD_SP(sp);
  296. req = ha->req_q_map[0];
  297. rsp = ha->rsp_q_map[0];
  298. /* So we know we haven't pci_map'ed anything yet */
  299. tot_dsds = 0;
  300. /* Send marker if required */
  301. if (vha->marker_needed != 0) {
  302. if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
  303. QLA_SUCCESS) {
  304. return (QLA_FUNCTION_FAILED);
  305. }
  306. vha->marker_needed = 0;
  307. }
  308. /* Acquire ring specific lock */
  309. spin_lock_irqsave(&ha->hardware_lock, flags);
  310. /* Check for room in outstanding command list. */
  311. handle = req->current_outstanding_cmd;
  312. for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
  313. handle++;
  314. if (handle == MAX_OUTSTANDING_COMMANDS)
  315. handle = 1;
  316. if (!req->outstanding_cmds[handle])
  317. break;
  318. }
  319. if (index == MAX_OUTSTANDING_COMMANDS)
  320. goto queuing_error;
  321. /* Map the sg table so we have an accurate count of sg entries needed */
  322. if (scsi_sg_count(cmd)) {
  323. nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
  324. scsi_sg_count(cmd), cmd->sc_data_direction);
  325. if (unlikely(!nseg))
  326. goto queuing_error;
  327. } else
  328. nseg = 0;
  329. tot_dsds = nseg;
  330. /* Calculate the number of request entries needed. */
  331. req_cnt = ha->isp_ops->calc_req_entries(tot_dsds);
  332. if (req->cnt < (req_cnt + 2)) {
  333. cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg));
  334. if (req->ring_index < cnt)
  335. req->cnt = cnt - req->ring_index;
  336. else
  337. req->cnt = req->length -
  338. (req->ring_index - cnt);
  339. }
  340. if (req->cnt < (req_cnt + 2))
  341. goto queuing_error;
  342. /* Build command packet */
  343. req->current_outstanding_cmd = handle;
  344. req->outstanding_cmds[handle] = sp;
  345. sp->handle = handle;
  346. cmd->host_scribble = (unsigned char *)(unsigned long)handle;
  347. req->cnt -= req_cnt;
  348. cmd_pkt = (cmd_entry_t *)req->ring_ptr;
  349. cmd_pkt->handle = handle;
  350. /* Zero out remaining portion of packet. */
  351. clr_ptr = (uint32_t *)cmd_pkt + 2;
  352. memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
  353. cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
  354. /* Set target ID and LUN number*/
  355. SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id);
  356. cmd_pkt->lun = cpu_to_le16(cmd->device->lun);
  357. /* Update tagged queuing modifier */
  358. if (scsi_populate_tag_msg(cmd, tag)) {
  359. switch (tag[0]) {
  360. case HEAD_OF_QUEUE_TAG:
  361. cmd_pkt->control_flags =
  362. __constant_cpu_to_le16(CF_HEAD_TAG);
  363. break;
  364. case ORDERED_QUEUE_TAG:
  365. cmd_pkt->control_flags =
  366. __constant_cpu_to_le16(CF_ORDERED_TAG);
  367. break;
  368. default:
  369. cmd_pkt->control_flags =
  370. __constant_cpu_to_le16(CF_SIMPLE_TAG);
  371. break;
  372. }
  373. }
  374. /* Load SCSI command packet. */
  375. memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len);
  376. cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
  377. /* Build IOCB segments */
  378. ha->isp_ops->build_iocbs(sp, cmd_pkt, tot_dsds);
  379. /* Set total data segment count. */
  380. cmd_pkt->entry_count = (uint8_t)req_cnt;
  381. wmb();
  382. /* Adjust ring index. */
  383. req->ring_index++;
  384. if (req->ring_index == req->length) {
  385. req->ring_index = 0;
  386. req->ring_ptr = req->ring;
  387. } else
  388. req->ring_ptr++;
  389. sp->flags |= SRB_DMA_VALID;
  390. /* Set chip new ring index. */
  391. WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), req->ring_index);
  392. RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */
  393. /* Manage unprocessed RIO/ZIO commands in response queue. */
  394. if (vha->flags.process_response_queue &&
  395. rsp->ring_ptr->signature != RESPONSE_PROCESSED)
  396. qla2x00_process_response_queue(rsp);
  397. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  398. return (QLA_SUCCESS);
  399. queuing_error:
  400. if (tot_dsds)
  401. scsi_dma_unmap(cmd);
  402. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  403. return (QLA_FUNCTION_FAILED);
  404. }
  405. /**
  406. * qla2x00_start_iocbs() - Execute the IOCB command
  407. */
  408. static void
  409. qla2x00_start_iocbs(struct scsi_qla_host *vha, struct req_que *req)
  410. {
  411. struct qla_hw_data *ha = vha->hw;
  412. device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
  413. if (IS_QLA82XX(ha)) {
  414. qla82xx_start_iocbs(vha);
  415. } else {
  416. /* Adjust ring index. */
  417. req->ring_index++;
  418. if (req->ring_index == req->length) {
  419. req->ring_index = 0;
  420. req->ring_ptr = req->ring;
  421. } else
  422. req->ring_ptr++;
  423. /* Set chip new ring index. */
  424. if (ha->mqenable || IS_QLA83XX(ha)) {
  425. WRT_REG_DWORD(req->req_q_in, req->ring_index);
  426. RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr);
  427. } else if (IS_FWI2_CAPABLE(ha)) {
  428. WRT_REG_DWORD(&reg->isp24.req_q_in, req->ring_index);
  429. RD_REG_DWORD_RELAXED(&reg->isp24.req_q_in);
  430. } else {
  431. WRT_REG_WORD(ISP_REQ_Q_IN(ha, &reg->isp),
  432. req->ring_index);
  433. RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, &reg->isp));
  434. }
  435. }
  436. }
  437. /**
  438. * qla2x00_marker() - Send a marker IOCB to the firmware.
  439. * @ha: HA context
  440. * @loop_id: loop ID
  441. * @lun: LUN
  442. * @type: marker modifier
  443. *
  444. * Can be called from both normal and interrupt context.
  445. *
  446. * Returns non-zero if a failure occurred, else zero.
  447. */
  448. static int
  449. __qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req,
  450. struct rsp_que *rsp, uint16_t loop_id,
  451. uint16_t lun, uint8_t type)
  452. {
  453. mrk_entry_t *mrk;
  454. struct mrk_entry_24xx *mrk24;
  455. struct qla_hw_data *ha = vha->hw;
  456. scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
  457. mrk24 = NULL;
  458. req = ha->req_q_map[0];
  459. mrk = (mrk_entry_t *)qla2x00_alloc_iocbs(vha, 0);
  460. if (mrk == NULL) {
  461. ql_log(ql_log_warn, base_vha, 0x3026,
  462. "Failed to allocate Marker IOCB.\n");
  463. return (QLA_FUNCTION_FAILED);
  464. }
  465. mrk->entry_type = MARKER_TYPE;
  466. mrk->modifier = type;
  467. if (type != MK_SYNC_ALL) {
  468. if (IS_FWI2_CAPABLE(ha)) {
  469. mrk24 = (struct mrk_entry_24xx *) mrk;
  470. mrk24->nport_handle = cpu_to_le16(loop_id);
  471. mrk24->lun[1] = LSB(lun);
  472. mrk24->lun[2] = MSB(lun);
  473. host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun));
  474. mrk24->vp_index = vha->vp_idx;
  475. mrk24->handle = MAKE_HANDLE(req->id, mrk24->handle);
  476. } else {
  477. SET_TARGET_ID(ha, mrk->target, loop_id);
  478. mrk->lun = cpu_to_le16(lun);
  479. }
  480. }
  481. wmb();
  482. qla2x00_start_iocbs(vha, req);
  483. return (QLA_SUCCESS);
  484. }
  485. int
  486. qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req,
  487. struct rsp_que *rsp, uint16_t loop_id, uint16_t lun,
  488. uint8_t type)
  489. {
  490. int ret;
  491. unsigned long flags = 0;
  492. spin_lock_irqsave(&vha->hw->hardware_lock, flags);
  493. ret = __qla2x00_marker(vha, req, rsp, loop_id, lun, type);
  494. spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
  495. return (ret);
  496. }
  497. /**
  498. * qla24xx_calc_iocbs() - Determine number of Command Type 3 and
  499. * Continuation Type 1 IOCBs to allocate.
  500. *
  501. * @dsds: number of data segment decriptors needed
  502. *
  503. * Returns the number of IOCB entries needed to store @dsds.
  504. */
  505. inline uint16_t
  506. qla24xx_calc_iocbs(scsi_qla_host_t *vha, uint16_t dsds)
  507. {
  508. uint16_t iocbs;
  509. iocbs = 1;
  510. if (dsds > 1) {
  511. iocbs += (dsds - 1) / 5;
  512. if ((dsds - 1) % 5)
  513. iocbs++;
  514. }
  515. return iocbs;
  516. }
  517. static inline int
  518. qla24xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt,
  519. uint16_t tot_dsds)
  520. {
  521. uint32_t *cur_dsd = NULL;
  522. scsi_qla_host_t *vha;
  523. struct qla_hw_data *ha;
  524. struct scsi_cmnd *cmd;
  525. struct scatterlist *cur_seg;
  526. uint32_t *dsd_seg;
  527. void *next_dsd;
  528. uint8_t avail_dsds;
  529. uint8_t first_iocb = 1;
  530. uint32_t dsd_list_len;
  531. struct dsd_dma *dsd_ptr;
  532. struct ct6_dsd *ctx;
  533. cmd = GET_CMD_SP(sp);
  534. /* Update entry type to indicate Command Type 3 IOCB */
  535. *((uint32_t *)(&cmd_pkt->entry_type)) =
  536. __constant_cpu_to_le32(COMMAND_TYPE_6);
  537. /* No data transfer */
  538. if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
  539. cmd_pkt->byte_count = __constant_cpu_to_le32(0);
  540. return 0;
  541. }
  542. vha = sp->fcport->vha;
  543. ha = vha->hw;
  544. /* Set transfer direction */
  545. if (cmd->sc_data_direction == DMA_TO_DEVICE) {
  546. cmd_pkt->control_flags =
  547. __constant_cpu_to_le16(CF_WRITE_DATA);
  548. ha->qla_stats.output_bytes += scsi_bufflen(cmd);
  549. } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
  550. cmd_pkt->control_flags =
  551. __constant_cpu_to_le16(CF_READ_DATA);
  552. ha->qla_stats.input_bytes += scsi_bufflen(cmd);
  553. }
  554. cur_seg = scsi_sglist(cmd);
  555. ctx = GET_CMD_CTX_SP(sp);
  556. while (tot_dsds) {
  557. avail_dsds = (tot_dsds > QLA_DSDS_PER_IOCB) ?
  558. QLA_DSDS_PER_IOCB : tot_dsds;
  559. tot_dsds -= avail_dsds;
  560. dsd_list_len = (avail_dsds + 1) * QLA_DSD_SIZE;
  561. dsd_ptr = list_first_entry(&ha->gbl_dsd_list,
  562. struct dsd_dma, list);
  563. next_dsd = dsd_ptr->dsd_addr;
  564. list_del(&dsd_ptr->list);
  565. ha->gbl_dsd_avail--;
  566. list_add_tail(&dsd_ptr->list, &ctx->dsd_list);
  567. ctx->dsd_use_cnt++;
  568. ha->gbl_dsd_inuse++;
  569. if (first_iocb) {
  570. first_iocb = 0;
  571. dsd_seg = (uint32_t *)&cmd_pkt->fcp_data_dseg_address;
  572. *dsd_seg++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
  573. *dsd_seg++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
  574. cmd_pkt->fcp_data_dseg_len = cpu_to_le32(dsd_list_len);
  575. } else {
  576. *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
  577. *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
  578. *cur_dsd++ = cpu_to_le32(dsd_list_len);
  579. }
  580. cur_dsd = (uint32_t *)next_dsd;
  581. while (avail_dsds) {
  582. dma_addr_t sle_dma;
  583. sle_dma = sg_dma_address(cur_seg);
  584. *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
  585. *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
  586. *cur_dsd++ = cpu_to_le32(sg_dma_len(cur_seg));
  587. cur_seg = sg_next(cur_seg);
  588. avail_dsds--;
  589. }
  590. }
  591. /* Null termination */
  592. *cur_dsd++ = 0;
  593. *cur_dsd++ = 0;
  594. *cur_dsd++ = 0;
  595. cmd_pkt->control_flags |= CF_DATA_SEG_DESCR_ENABLE;
  596. return 0;
  597. }
  598. /*
  599. * qla24xx_calc_dsd_lists() - Determine number of DSD list required
  600. * for Command Type 6.
  601. *
  602. * @dsds: number of data segment decriptors needed
  603. *
  604. * Returns the number of dsd list needed to store @dsds.
  605. */
  606. inline uint16_t
  607. qla24xx_calc_dsd_lists(uint16_t dsds)
  608. {
  609. uint16_t dsd_lists = 0;
  610. dsd_lists = (dsds/QLA_DSDS_PER_IOCB);
  611. if (dsds % QLA_DSDS_PER_IOCB)
  612. dsd_lists++;
  613. return dsd_lists;
  614. }
  615. /**
  616. * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7
  617. * IOCB types.
  618. *
  619. * @sp: SRB command to process
  620. * @cmd_pkt: Command type 3 IOCB
  621. * @tot_dsds: Total number of segments to transfer
  622. */
  623. inline void
  624. qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt,
  625. uint16_t tot_dsds)
  626. {
  627. uint16_t avail_dsds;
  628. uint32_t *cur_dsd;
  629. scsi_qla_host_t *vha;
  630. struct scsi_cmnd *cmd;
  631. struct scatterlist *sg;
  632. int i;
  633. struct req_que *req;
  634. cmd = GET_CMD_SP(sp);
  635. /* Update entry type to indicate Command Type 3 IOCB */
  636. *((uint32_t *)(&cmd_pkt->entry_type)) =
  637. __constant_cpu_to_le32(COMMAND_TYPE_7);
  638. /* No data transfer */
  639. if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) {
  640. cmd_pkt->byte_count = __constant_cpu_to_le32(0);
  641. return;
  642. }
  643. vha = sp->fcport->vha;
  644. req = vha->req;
  645. /* Set transfer direction */
  646. if (cmd->sc_data_direction == DMA_TO_DEVICE) {
  647. cmd_pkt->task_mgmt_flags =
  648. __constant_cpu_to_le16(TMF_WRITE_DATA);
  649. sp->fcport->vha->hw->qla_stats.output_bytes +=
  650. scsi_bufflen(cmd);
  651. } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
  652. cmd_pkt->task_mgmt_flags =
  653. __constant_cpu_to_le16(TMF_READ_DATA);
  654. sp->fcport->vha->hw->qla_stats.input_bytes +=
  655. scsi_bufflen(cmd);
  656. }
  657. /* One DSD is available in the Command Type 3 IOCB */
  658. avail_dsds = 1;
  659. cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address;
  660. /* Load data segments */
  661. scsi_for_each_sg(cmd, sg, tot_dsds, i) {
  662. dma_addr_t sle_dma;
  663. cont_a64_entry_t *cont_pkt;
  664. /* Allocate additional continuation packets? */
  665. if (avail_dsds == 0) {
  666. /*
  667. * Five DSDs are available in the Continuation
  668. * Type 1 IOCB.
  669. */
  670. cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req);
  671. cur_dsd = (uint32_t *)cont_pkt->dseg_0_address;
  672. avail_dsds = 5;
  673. }
  674. sle_dma = sg_dma_address(sg);
  675. *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
  676. *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
  677. *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
  678. avail_dsds--;
  679. }
  680. }
  681. struct fw_dif_context {
  682. uint32_t ref_tag;
  683. uint16_t app_tag;
  684. uint8_t ref_tag_mask[4]; /* Validation/Replacement Mask*/
  685. uint8_t app_tag_mask[2]; /* Validation/Replacement Mask*/
  686. };
  687. /*
  688. * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command
  689. *
  690. */
  691. static inline void
  692. qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt,
  693. unsigned int protcnt)
  694. {
  695. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  696. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  697. switch (scsi_get_prot_type(cmd)) {
  698. case SCSI_PROT_DIF_TYPE0:
  699. /*
  700. * No check for ql2xenablehba_err_chk, as it would be an
  701. * I/O error if hba tag generation is not done.
  702. */
  703. pkt->ref_tag = cpu_to_le32((uint32_t)
  704. (0xffffffff & scsi_get_lba(cmd)));
  705. if (!qla2x00_hba_err_chk_enabled(sp))
  706. break;
  707. pkt->ref_tag_mask[0] = 0xff;
  708. pkt->ref_tag_mask[1] = 0xff;
  709. pkt->ref_tag_mask[2] = 0xff;
  710. pkt->ref_tag_mask[3] = 0xff;
  711. break;
  712. /*
  713. * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to
  714. * match LBA in CDB + N
  715. */
  716. case SCSI_PROT_DIF_TYPE2:
  717. pkt->app_tag = __constant_cpu_to_le16(0);
  718. pkt->app_tag_mask[0] = 0x0;
  719. pkt->app_tag_mask[1] = 0x0;
  720. pkt->ref_tag = cpu_to_le32((uint32_t)
  721. (0xffffffff & scsi_get_lba(cmd)));
  722. if (!qla2x00_hba_err_chk_enabled(sp))
  723. break;
  724. /* enable ALL bytes of the ref tag */
  725. pkt->ref_tag_mask[0] = 0xff;
  726. pkt->ref_tag_mask[1] = 0xff;
  727. pkt->ref_tag_mask[2] = 0xff;
  728. pkt->ref_tag_mask[3] = 0xff;
  729. break;
  730. /* For Type 3 protection: 16 bit GUARD only */
  731. case SCSI_PROT_DIF_TYPE3:
  732. pkt->ref_tag_mask[0] = pkt->ref_tag_mask[1] =
  733. pkt->ref_tag_mask[2] = pkt->ref_tag_mask[3] =
  734. 0x00;
  735. break;
  736. /*
  737. * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and
  738. * 16 bit app tag.
  739. */
  740. case SCSI_PROT_DIF_TYPE1:
  741. pkt->ref_tag = cpu_to_le32((uint32_t)
  742. (0xffffffff & scsi_get_lba(cmd)));
  743. pkt->app_tag = __constant_cpu_to_le16(0);
  744. pkt->app_tag_mask[0] = 0x0;
  745. pkt->app_tag_mask[1] = 0x0;
  746. if (!qla2x00_hba_err_chk_enabled(sp))
  747. break;
  748. /* enable ALL bytes of the ref tag */
  749. pkt->ref_tag_mask[0] = 0xff;
  750. pkt->ref_tag_mask[1] = 0xff;
  751. pkt->ref_tag_mask[2] = 0xff;
  752. pkt->ref_tag_mask[3] = 0xff;
  753. break;
  754. }
  755. ql_dbg(ql_dbg_io, vha, 0x3009,
  756. "Setting protection Tags: (BIG) ref tag = 0x%x, app tag = 0x%x, "
  757. "prot SG count %d, cmd lba 0x%x, prot_type=%u cmd=%p.\n",
  758. pkt->ref_tag, pkt->app_tag, protcnt, (int)scsi_get_lba(cmd),
  759. scsi_get_prot_type(cmd), cmd);
  760. }
  761. struct qla2_sgx {
  762. dma_addr_t dma_addr; /* OUT */
  763. uint32_t dma_len; /* OUT */
  764. uint32_t tot_bytes; /* IN */
  765. struct scatterlist *cur_sg; /* IN */
  766. /* for book keeping, bzero on initial invocation */
  767. uint32_t bytes_consumed;
  768. uint32_t num_bytes;
  769. uint32_t tot_partial;
  770. /* for debugging */
  771. uint32_t num_sg;
  772. srb_t *sp;
  773. };
  774. static int
  775. qla24xx_get_one_block_sg(uint32_t blk_sz, struct qla2_sgx *sgx,
  776. uint32_t *partial)
  777. {
  778. struct scatterlist *sg;
  779. uint32_t cumulative_partial, sg_len;
  780. dma_addr_t sg_dma_addr;
  781. if (sgx->num_bytes == sgx->tot_bytes)
  782. return 0;
  783. sg = sgx->cur_sg;
  784. cumulative_partial = sgx->tot_partial;
  785. sg_dma_addr = sg_dma_address(sg);
  786. sg_len = sg_dma_len(sg);
  787. sgx->dma_addr = sg_dma_addr + sgx->bytes_consumed;
  788. if ((cumulative_partial + (sg_len - sgx->bytes_consumed)) >= blk_sz) {
  789. sgx->dma_len = (blk_sz - cumulative_partial);
  790. sgx->tot_partial = 0;
  791. sgx->num_bytes += blk_sz;
  792. *partial = 0;
  793. } else {
  794. sgx->dma_len = sg_len - sgx->bytes_consumed;
  795. sgx->tot_partial += sgx->dma_len;
  796. *partial = 1;
  797. }
  798. sgx->bytes_consumed += sgx->dma_len;
  799. if (sg_len == sgx->bytes_consumed) {
  800. sg = sg_next(sg);
  801. sgx->num_sg++;
  802. sgx->cur_sg = sg;
  803. sgx->bytes_consumed = 0;
  804. }
  805. return 1;
  806. }
  807. static int
  808. qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp,
  809. uint32_t *dsd, uint16_t tot_dsds)
  810. {
  811. void *next_dsd;
  812. uint8_t avail_dsds = 0;
  813. uint32_t dsd_list_len;
  814. struct dsd_dma *dsd_ptr;
  815. struct scatterlist *sg_prot;
  816. uint32_t *cur_dsd = dsd;
  817. uint16_t used_dsds = tot_dsds;
  818. uint32_t prot_int;
  819. uint32_t partial;
  820. struct qla2_sgx sgx;
  821. dma_addr_t sle_dma;
  822. uint32_t sle_dma_len, tot_prot_dma_len = 0;
  823. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  824. prot_int = cmd->device->sector_size;
  825. memset(&sgx, 0, sizeof(struct qla2_sgx));
  826. sgx.tot_bytes = scsi_bufflen(cmd);
  827. sgx.cur_sg = scsi_sglist(cmd);
  828. sgx.sp = sp;
  829. sg_prot = scsi_prot_sglist(cmd);
  830. while (qla24xx_get_one_block_sg(prot_int, &sgx, &partial)) {
  831. sle_dma = sgx.dma_addr;
  832. sle_dma_len = sgx.dma_len;
  833. alloc_and_fill:
  834. /* Allocate additional continuation packets? */
  835. if (avail_dsds == 0) {
  836. avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
  837. QLA_DSDS_PER_IOCB : used_dsds;
  838. dsd_list_len = (avail_dsds + 1) * 12;
  839. used_dsds -= avail_dsds;
  840. /* allocate tracking DS */
  841. dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
  842. if (!dsd_ptr)
  843. return 1;
  844. /* allocate new list */
  845. dsd_ptr->dsd_addr = next_dsd =
  846. dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
  847. &dsd_ptr->dsd_list_dma);
  848. if (!next_dsd) {
  849. /*
  850. * Need to cleanup only this dsd_ptr, rest
  851. * will be done by sp_free_dma()
  852. */
  853. kfree(dsd_ptr);
  854. return 1;
  855. }
  856. list_add_tail(&dsd_ptr->list,
  857. &((struct crc_context *)sp->u.scmd.ctx)->dsd_list);
  858. sp->flags |= SRB_CRC_CTX_DSD_VALID;
  859. /* add new list to cmd iocb or last list */
  860. *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
  861. *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
  862. *cur_dsd++ = dsd_list_len;
  863. cur_dsd = (uint32_t *)next_dsd;
  864. }
  865. *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
  866. *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
  867. *cur_dsd++ = cpu_to_le32(sle_dma_len);
  868. avail_dsds--;
  869. if (partial == 0) {
  870. /* Got a full protection interval */
  871. sle_dma = sg_dma_address(sg_prot) + tot_prot_dma_len;
  872. sle_dma_len = 8;
  873. tot_prot_dma_len += sle_dma_len;
  874. if (tot_prot_dma_len == sg_dma_len(sg_prot)) {
  875. tot_prot_dma_len = 0;
  876. sg_prot = sg_next(sg_prot);
  877. }
  878. partial = 1; /* So as to not re-enter this block */
  879. goto alloc_and_fill;
  880. }
  881. }
  882. /* Null termination */
  883. *cur_dsd++ = 0;
  884. *cur_dsd++ = 0;
  885. *cur_dsd++ = 0;
  886. return 0;
  887. }
  888. static int
  889. qla24xx_walk_and_build_sglist(struct qla_hw_data *ha, srb_t *sp, uint32_t *dsd,
  890. uint16_t tot_dsds)
  891. {
  892. void *next_dsd;
  893. uint8_t avail_dsds = 0;
  894. uint32_t dsd_list_len;
  895. struct dsd_dma *dsd_ptr;
  896. struct scatterlist *sg;
  897. uint32_t *cur_dsd = dsd;
  898. int i;
  899. uint16_t used_dsds = tot_dsds;
  900. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  901. scsi_qla_host_t *vha = shost_priv(cmd->device->host);
  902. uint8_t *cp;
  903. scsi_for_each_sg(cmd, sg, tot_dsds, i) {
  904. dma_addr_t sle_dma;
  905. /* Allocate additional continuation packets? */
  906. if (avail_dsds == 0) {
  907. avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
  908. QLA_DSDS_PER_IOCB : used_dsds;
  909. dsd_list_len = (avail_dsds + 1) * 12;
  910. used_dsds -= avail_dsds;
  911. /* allocate tracking DS */
  912. dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
  913. if (!dsd_ptr)
  914. return 1;
  915. /* allocate new list */
  916. dsd_ptr->dsd_addr = next_dsd =
  917. dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
  918. &dsd_ptr->dsd_list_dma);
  919. if (!next_dsd) {
  920. /*
  921. * Need to cleanup only this dsd_ptr, rest
  922. * will be done by sp_free_dma()
  923. */
  924. kfree(dsd_ptr);
  925. return 1;
  926. }
  927. list_add_tail(&dsd_ptr->list,
  928. &((struct crc_context *)sp->u.scmd.ctx)->dsd_list);
  929. sp->flags |= SRB_CRC_CTX_DSD_VALID;
  930. /* add new list to cmd iocb or last list */
  931. *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
  932. *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
  933. *cur_dsd++ = dsd_list_len;
  934. cur_dsd = (uint32_t *)next_dsd;
  935. }
  936. sle_dma = sg_dma_address(sg);
  937. ql_dbg(ql_dbg_io, vha, 0x300a,
  938. "sg entry %d - addr=0x%x 0x%x, " "len=%d for cmd=%p.\n",
  939. i, LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg), cmd);
  940. *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
  941. *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
  942. *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
  943. avail_dsds--;
  944. if (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_PASS) {
  945. cp = page_address(sg_page(sg)) + sg->offset;
  946. ql_dbg(ql_dbg_io, vha, 0x300b,
  947. "User data buffer=%p for cmd=%p.\n", cp, cmd);
  948. }
  949. }
  950. /* Null termination */
  951. *cur_dsd++ = 0;
  952. *cur_dsd++ = 0;
  953. *cur_dsd++ = 0;
  954. return 0;
  955. }
  956. static int
  957. qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp,
  958. uint32_t *dsd,
  959. uint16_t tot_dsds)
  960. {
  961. void *next_dsd;
  962. uint8_t avail_dsds = 0;
  963. uint32_t dsd_list_len;
  964. struct dsd_dma *dsd_ptr;
  965. struct scatterlist *sg;
  966. int i;
  967. struct scsi_cmnd *cmd;
  968. uint32_t *cur_dsd = dsd;
  969. uint16_t used_dsds = tot_dsds;
  970. scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
  971. uint8_t *cp;
  972. cmd = GET_CMD_SP(sp);
  973. scsi_for_each_prot_sg(cmd, sg, tot_dsds, i) {
  974. dma_addr_t sle_dma;
  975. /* Allocate additional continuation packets? */
  976. if (avail_dsds == 0) {
  977. avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ?
  978. QLA_DSDS_PER_IOCB : used_dsds;
  979. dsd_list_len = (avail_dsds + 1) * 12;
  980. used_dsds -= avail_dsds;
  981. /* allocate tracking DS */
  982. dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
  983. if (!dsd_ptr)
  984. return 1;
  985. /* allocate new list */
  986. dsd_ptr->dsd_addr = next_dsd =
  987. dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC,
  988. &dsd_ptr->dsd_list_dma);
  989. if (!next_dsd) {
  990. /*
  991. * Need to cleanup only this dsd_ptr, rest
  992. * will be done by sp_free_dma()
  993. */
  994. kfree(dsd_ptr);
  995. return 1;
  996. }
  997. list_add_tail(&dsd_ptr->list,
  998. &((struct crc_context *)sp->u.scmd.ctx)->dsd_list);
  999. sp->flags |= SRB_CRC_CTX_DSD_VALID;
  1000. /* add new list to cmd iocb or last list */
  1001. *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma));
  1002. *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma));
  1003. *cur_dsd++ = dsd_list_len;
  1004. cur_dsd = (uint32_t *)next_dsd;
  1005. }
  1006. sle_dma = sg_dma_address(sg);
  1007. if (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_PASS) {
  1008. ql_dbg(ql_dbg_io, vha, 0x3027,
  1009. "%s(): %p, sg_entry %d - "
  1010. "addr=0x%x0x%x, len=%d.\n",
  1011. __func__, cur_dsd, i,
  1012. LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg));
  1013. }
  1014. *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
  1015. *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
  1016. *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
  1017. if (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_PASS) {
  1018. cp = page_address(sg_page(sg)) + sg->offset;
  1019. ql_dbg(ql_dbg_io, vha, 0x3028,
  1020. "%s(): Protection Data buffer = %p.\n", __func__,
  1021. cp);
  1022. }
  1023. avail_dsds--;
  1024. }
  1025. /* Null termination */
  1026. *cur_dsd++ = 0;
  1027. *cur_dsd++ = 0;
  1028. *cur_dsd++ = 0;
  1029. return 0;
  1030. }
  1031. /**
  1032. * qla24xx_build_scsi_crc_2_iocbs() - Build IOCB command utilizing Command
  1033. * Type 6 IOCB types.
  1034. *
  1035. * @sp: SRB command to process
  1036. * @cmd_pkt: Command type 3 IOCB
  1037. * @tot_dsds: Total number of segments to transfer
  1038. */
  1039. static inline int
  1040. qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt,
  1041. uint16_t tot_dsds, uint16_t tot_prot_dsds, uint16_t fw_prot_opts)
  1042. {
  1043. uint32_t *cur_dsd, *fcp_dl;
  1044. scsi_qla_host_t *vha;
  1045. struct scsi_cmnd *cmd;
  1046. struct scatterlist *cur_seg;
  1047. int sgc;
  1048. uint32_t total_bytes = 0;
  1049. uint32_t data_bytes;
  1050. uint32_t dif_bytes;
  1051. uint8_t bundling = 1;
  1052. uint16_t blk_size;
  1053. uint8_t *clr_ptr;
  1054. struct crc_context *crc_ctx_pkt = NULL;
  1055. struct qla_hw_data *ha;
  1056. uint8_t additional_fcpcdb_len;
  1057. uint16_t fcp_cmnd_len;
  1058. struct fcp_cmnd *fcp_cmnd;
  1059. dma_addr_t crc_ctx_dma;
  1060. char tag[2];
  1061. cmd = GET_CMD_SP(sp);
  1062. sgc = 0;
  1063. /* Update entry type to indicate Command Type CRC_2 IOCB */
  1064. *((uint32_t *)(&cmd_pkt->entry_type)) =
  1065. __constant_cpu_to_le32(COMMAND_TYPE_CRC_2);
  1066. vha = sp->fcport->vha;
  1067. ha = vha->hw;
  1068. /* No data transfer */
  1069. data_bytes = scsi_bufflen(cmd);
  1070. if (!data_bytes || cmd->sc_data_direction == DMA_NONE) {
  1071. cmd_pkt->byte_count = __constant_cpu_to_le32(0);
  1072. return QLA_SUCCESS;
  1073. }
  1074. cmd_pkt->vp_index = sp->fcport->vp_idx;
  1075. /* Set transfer direction */
  1076. if (cmd->sc_data_direction == DMA_TO_DEVICE) {
  1077. cmd_pkt->control_flags =
  1078. __constant_cpu_to_le16(CF_WRITE_DATA);
  1079. } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) {
  1080. cmd_pkt->control_flags =
  1081. __constant_cpu_to_le16(CF_READ_DATA);
  1082. }
  1083. if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
  1084. (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP) ||
  1085. (scsi_get_prot_op(cmd) == SCSI_PROT_READ_STRIP) ||
  1086. (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_INSERT))
  1087. bundling = 0;
  1088. /* Allocate CRC context from global pool */
  1089. crc_ctx_pkt = sp->u.scmd.ctx =
  1090. dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma);
  1091. if (!crc_ctx_pkt)
  1092. goto crc_queuing_error;
  1093. /* Zero out CTX area. */
  1094. clr_ptr = (uint8_t *)crc_ctx_pkt;
  1095. memset(clr_ptr, 0, sizeof(*crc_ctx_pkt));
  1096. crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma;
  1097. sp->flags |= SRB_CRC_CTX_DMA_VALID;
  1098. /* Set handle */
  1099. crc_ctx_pkt->handle = cmd_pkt->handle;
  1100. INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list);
  1101. qla24xx_set_t10dif_tags(sp, (struct fw_dif_context *)
  1102. &crc_ctx_pkt->ref_tag, tot_prot_dsds);
  1103. cmd_pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma));
  1104. cmd_pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma));
  1105. cmd_pkt->crc_context_len = CRC_CONTEXT_LEN_FW;
  1106. /* Determine SCSI command length -- align to 4 byte boundary */
  1107. if (cmd->cmd_len > 16) {
  1108. additional_fcpcdb_len = cmd->cmd_len - 16;
  1109. if ((cmd->cmd_len % 4) != 0) {
  1110. /* SCSI cmd > 16 bytes must be multiple of 4 */
  1111. goto crc_queuing_error;
  1112. }
  1113. fcp_cmnd_len = 12 + cmd->cmd_len + 4;
  1114. } else {
  1115. additional_fcpcdb_len = 0;
  1116. fcp_cmnd_len = 12 + 16 + 4;
  1117. }
  1118. fcp_cmnd = &crc_ctx_pkt->fcp_cmnd;
  1119. fcp_cmnd->additional_cdb_len = additional_fcpcdb_len;
  1120. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  1121. fcp_cmnd->additional_cdb_len |= 1;
  1122. else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
  1123. fcp_cmnd->additional_cdb_len |= 2;
  1124. int_to_scsilun(cmd->device->lun, &fcp_cmnd->lun);
  1125. memcpy(fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len);
  1126. cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(fcp_cmnd_len);
  1127. cmd_pkt->fcp_cmnd_dseg_address[0] = cpu_to_le32(
  1128. LSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
  1129. cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32(
  1130. MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF));
  1131. fcp_cmnd->task_management = 0;
  1132. /*
  1133. * Update tagged queuing modifier if using command tag queuing
  1134. */
  1135. if (scsi_populate_tag_msg(cmd, tag)) {
  1136. switch (tag[0]) {
  1137. case HEAD_OF_QUEUE_TAG:
  1138. fcp_cmnd->task_attribute = TSK_HEAD_OF_QUEUE;
  1139. break;
  1140. case ORDERED_QUEUE_TAG:
  1141. fcp_cmnd->task_attribute = TSK_ORDERED;
  1142. break;
  1143. default:
  1144. fcp_cmnd->task_attribute = 0;
  1145. break;
  1146. }
  1147. } else {
  1148. fcp_cmnd->task_attribute = 0;
  1149. }
  1150. cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */
  1151. /* Compute dif len and adjust data len to incude protection */
  1152. dif_bytes = 0;
  1153. blk_size = cmd->device->sector_size;
  1154. dif_bytes = (data_bytes / blk_size) * 8;
  1155. switch (scsi_get_prot_op(GET_CMD_SP(sp))) {
  1156. case SCSI_PROT_READ_INSERT:
  1157. case SCSI_PROT_WRITE_STRIP:
  1158. total_bytes = data_bytes;
  1159. data_bytes += dif_bytes;
  1160. break;
  1161. case SCSI_PROT_READ_STRIP:
  1162. case SCSI_PROT_WRITE_INSERT:
  1163. case SCSI_PROT_READ_PASS:
  1164. case SCSI_PROT_WRITE_PASS:
  1165. total_bytes = data_bytes + dif_bytes;
  1166. break;
  1167. default:
  1168. BUG();
  1169. }
  1170. if (!qla2x00_hba_err_chk_enabled(sp))
  1171. fw_prot_opts |= 0x10; /* Disable Guard tag checking */
  1172. if (!bundling) {
  1173. cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address;
  1174. } else {
  1175. /*
  1176. * Configure Bundling if we need to fetch interlaving
  1177. * protection PCI accesses
  1178. */
  1179. fw_prot_opts |= PO_ENABLE_DIF_BUNDLING;
  1180. crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes);
  1181. crc_ctx_pkt->u.bundling.dseg_count = cpu_to_le16(tot_dsds -
  1182. tot_prot_dsds);
  1183. cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address;
  1184. }
  1185. /* Finish the common fields of CRC pkt */
  1186. crc_ctx_pkt->blk_size = cpu_to_le16(blk_size);
  1187. crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts);
  1188. crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes);
  1189. crc_ctx_pkt->guard_seed = __constant_cpu_to_le16(0);
  1190. /* Fibre channel byte count */
  1191. cmd_pkt->byte_count = cpu_to_le32(total_bytes);
  1192. fcp_dl = (uint32_t *)(crc_ctx_pkt->fcp_cmnd.cdb + 16 +
  1193. additional_fcpcdb_len);
  1194. *fcp_dl = htonl(total_bytes);
  1195. if (!data_bytes || cmd->sc_data_direction == DMA_NONE) {
  1196. cmd_pkt->byte_count = __constant_cpu_to_le32(0);
  1197. return QLA_SUCCESS;
  1198. }
  1199. /* Walks data segments */
  1200. cmd_pkt->control_flags |=
  1201. __constant_cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE);
  1202. if (!bundling && tot_prot_dsds) {
  1203. if (qla24xx_walk_and_build_sglist_no_difb(ha, sp,
  1204. cur_dsd, tot_dsds))
  1205. goto crc_queuing_error;
  1206. } else if (qla24xx_walk_and_build_sglist(ha, sp, cur_dsd,
  1207. (tot_dsds - tot_prot_dsds)))
  1208. goto crc_queuing_error;
  1209. if (bundling && tot_prot_dsds) {
  1210. /* Walks dif segments */
  1211. cur_seg = scsi_prot_sglist(cmd);
  1212. cmd_pkt->control_flags |=
  1213. __constant_cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE);
  1214. cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address;
  1215. if (qla24xx_walk_and_build_prot_sglist(ha, sp, cur_dsd,
  1216. tot_prot_dsds))
  1217. goto crc_queuing_error;
  1218. }
  1219. return QLA_SUCCESS;
  1220. crc_queuing_error:
  1221. /* Cleanup will be performed by the caller */
  1222. return QLA_FUNCTION_FAILED;
  1223. }
  1224. /**
  1225. * qla24xx_start_scsi() - Send a SCSI command to the ISP
  1226. * @sp: command to send to the ISP
  1227. *
  1228. * Returns non-zero if a failure occurred, else zero.
  1229. */
  1230. int
  1231. qla24xx_start_scsi(srb_t *sp)
  1232. {
  1233. int ret, nseg;
  1234. unsigned long flags;
  1235. uint32_t *clr_ptr;
  1236. uint32_t index;
  1237. uint32_t handle;
  1238. struct cmd_type_7 *cmd_pkt;
  1239. uint16_t cnt;
  1240. uint16_t req_cnt;
  1241. uint16_t tot_dsds;
  1242. struct req_que *req = NULL;
  1243. struct rsp_que *rsp = NULL;
  1244. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  1245. struct scsi_qla_host *vha = sp->fcport->vha;
  1246. struct qla_hw_data *ha = vha->hw;
  1247. char tag[2];
  1248. /* Setup device pointers. */
  1249. ret = 0;
  1250. qla25xx_set_que(sp, &rsp);
  1251. req = vha->req;
  1252. /* So we know we haven't pci_map'ed anything yet */
  1253. tot_dsds = 0;
  1254. /* Send marker if required */
  1255. if (vha->marker_needed != 0) {
  1256. if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
  1257. QLA_SUCCESS)
  1258. return QLA_FUNCTION_FAILED;
  1259. vha->marker_needed = 0;
  1260. }
  1261. /* Acquire ring specific lock */
  1262. spin_lock_irqsave(&ha->hardware_lock, flags);
  1263. /* Check for room in outstanding command list. */
  1264. handle = req->current_outstanding_cmd;
  1265. for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
  1266. handle++;
  1267. if (handle == MAX_OUTSTANDING_COMMANDS)
  1268. handle = 1;
  1269. if (!req->outstanding_cmds[handle])
  1270. break;
  1271. }
  1272. if (index == MAX_OUTSTANDING_COMMANDS) {
  1273. goto queuing_error;
  1274. }
  1275. /* Map the sg table so we have an accurate count of sg entries needed */
  1276. if (scsi_sg_count(cmd)) {
  1277. nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
  1278. scsi_sg_count(cmd), cmd->sc_data_direction);
  1279. if (unlikely(!nseg))
  1280. goto queuing_error;
  1281. } else
  1282. nseg = 0;
  1283. tot_dsds = nseg;
  1284. req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
  1285. if (req->cnt < (req_cnt + 2)) {
  1286. cnt = RD_REG_DWORD_RELAXED(req->req_q_out);
  1287. if (req->ring_index < cnt)
  1288. req->cnt = cnt - req->ring_index;
  1289. else
  1290. req->cnt = req->length -
  1291. (req->ring_index - cnt);
  1292. }
  1293. if (req->cnt < (req_cnt + 2))
  1294. goto queuing_error;
  1295. /* Build command packet. */
  1296. req->current_outstanding_cmd = handle;
  1297. req->outstanding_cmds[handle] = sp;
  1298. sp->handle = handle;
  1299. cmd->host_scribble = (unsigned char *)(unsigned long)handle;
  1300. req->cnt -= req_cnt;
  1301. cmd_pkt = (struct cmd_type_7 *)req->ring_ptr;
  1302. cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
  1303. /* Zero out remaining portion of packet. */
  1304. /* tagged queuing modifier -- default is TSK_SIMPLE (0). */
  1305. clr_ptr = (uint32_t *)cmd_pkt + 2;
  1306. memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
  1307. cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
  1308. /* Set NPORT-ID and LUN number*/
  1309. cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  1310. cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
  1311. cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
  1312. cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
  1313. cmd_pkt->vp_index = sp->fcport->vp_idx;
  1314. int_to_scsilun(cmd->device->lun, &cmd_pkt->lun);
  1315. host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
  1316. /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */
  1317. if (scsi_populate_tag_msg(cmd, tag)) {
  1318. switch (tag[0]) {
  1319. case HEAD_OF_QUEUE_TAG:
  1320. cmd_pkt->task = TSK_HEAD_OF_QUEUE;
  1321. break;
  1322. case ORDERED_QUEUE_TAG:
  1323. cmd_pkt->task = TSK_ORDERED;
  1324. break;
  1325. }
  1326. }
  1327. /* Load SCSI command packet. */
  1328. memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
  1329. host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb));
  1330. cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
  1331. /* Build IOCB segments */
  1332. qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds);
  1333. /* Set total data segment count. */
  1334. cmd_pkt->entry_count = (uint8_t)req_cnt;
  1335. /* Specify response queue number where completion should happen */
  1336. cmd_pkt->entry_status = (uint8_t) rsp->id;
  1337. wmb();
  1338. /* Adjust ring index. */
  1339. req->ring_index++;
  1340. if (req->ring_index == req->length) {
  1341. req->ring_index = 0;
  1342. req->ring_ptr = req->ring;
  1343. } else
  1344. req->ring_ptr++;
  1345. sp->flags |= SRB_DMA_VALID;
  1346. /* Set chip new ring index. */
  1347. WRT_REG_DWORD(req->req_q_in, req->ring_index);
  1348. RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr);
  1349. /* Manage unprocessed RIO/ZIO commands in response queue. */
  1350. if (vha->flags.process_response_queue &&
  1351. rsp->ring_ptr->signature != RESPONSE_PROCESSED)
  1352. qla24xx_process_response_queue(vha, rsp);
  1353. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1354. return QLA_SUCCESS;
  1355. queuing_error:
  1356. if (tot_dsds)
  1357. scsi_dma_unmap(cmd);
  1358. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1359. return QLA_FUNCTION_FAILED;
  1360. }
  1361. /**
  1362. * qla24xx_dif_start_scsi() - Send a SCSI command to the ISP
  1363. * @sp: command to send to the ISP
  1364. *
  1365. * Returns non-zero if a failure occurred, else zero.
  1366. */
  1367. int
  1368. qla24xx_dif_start_scsi(srb_t *sp)
  1369. {
  1370. int nseg;
  1371. unsigned long flags;
  1372. uint32_t *clr_ptr;
  1373. uint32_t index;
  1374. uint32_t handle;
  1375. uint16_t cnt;
  1376. uint16_t req_cnt = 0;
  1377. uint16_t tot_dsds;
  1378. uint16_t tot_prot_dsds;
  1379. uint16_t fw_prot_opts = 0;
  1380. struct req_que *req = NULL;
  1381. struct rsp_que *rsp = NULL;
  1382. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  1383. struct scsi_qla_host *vha = sp->fcport->vha;
  1384. struct qla_hw_data *ha = vha->hw;
  1385. struct cmd_type_crc_2 *cmd_pkt;
  1386. uint32_t status = 0;
  1387. #define QDSS_GOT_Q_SPACE BIT_0
  1388. /* Only process protection or >16 cdb in this routine */
  1389. if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL) {
  1390. if (cmd->cmd_len <= 16)
  1391. return qla24xx_start_scsi(sp);
  1392. }
  1393. /* Setup device pointers. */
  1394. qla25xx_set_que(sp, &rsp);
  1395. req = vha->req;
  1396. /* So we know we haven't pci_map'ed anything yet */
  1397. tot_dsds = 0;
  1398. /* Send marker if required */
  1399. if (vha->marker_needed != 0) {
  1400. if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) !=
  1401. QLA_SUCCESS)
  1402. return QLA_FUNCTION_FAILED;
  1403. vha->marker_needed = 0;
  1404. }
  1405. /* Acquire ring specific lock */
  1406. spin_lock_irqsave(&ha->hardware_lock, flags);
  1407. /* Check for room in outstanding command list. */
  1408. handle = req->current_outstanding_cmd;
  1409. for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
  1410. handle++;
  1411. if (handle == MAX_OUTSTANDING_COMMANDS)
  1412. handle = 1;
  1413. if (!req->outstanding_cmds[handle])
  1414. break;
  1415. }
  1416. if (index == MAX_OUTSTANDING_COMMANDS)
  1417. goto queuing_error;
  1418. /* Compute number of required data segments */
  1419. /* Map the sg table so we have an accurate count of sg entries needed */
  1420. if (scsi_sg_count(cmd)) {
  1421. nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
  1422. scsi_sg_count(cmd), cmd->sc_data_direction);
  1423. if (unlikely(!nseg))
  1424. goto queuing_error;
  1425. else
  1426. sp->flags |= SRB_DMA_VALID;
  1427. if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
  1428. (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) {
  1429. struct qla2_sgx sgx;
  1430. uint32_t partial;
  1431. memset(&sgx, 0, sizeof(struct qla2_sgx));
  1432. sgx.tot_bytes = scsi_bufflen(cmd);
  1433. sgx.cur_sg = scsi_sglist(cmd);
  1434. sgx.sp = sp;
  1435. nseg = 0;
  1436. while (qla24xx_get_one_block_sg(
  1437. cmd->device->sector_size, &sgx, &partial))
  1438. nseg++;
  1439. }
  1440. } else
  1441. nseg = 0;
  1442. /* number of required data segments */
  1443. tot_dsds = nseg;
  1444. /* Compute number of required protection segments */
  1445. if (qla24xx_configure_prot_mode(sp, &fw_prot_opts)) {
  1446. nseg = dma_map_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
  1447. scsi_prot_sg_count(cmd), cmd->sc_data_direction);
  1448. if (unlikely(!nseg))
  1449. goto queuing_error;
  1450. else
  1451. sp->flags |= SRB_CRC_PROT_DMA_VALID;
  1452. if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) ||
  1453. (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) {
  1454. nseg = scsi_bufflen(cmd) / cmd->device->sector_size;
  1455. }
  1456. } else {
  1457. nseg = 0;
  1458. }
  1459. req_cnt = 1;
  1460. /* Total Data and protection sg segment(s) */
  1461. tot_prot_dsds = nseg;
  1462. tot_dsds += nseg;
  1463. if (req->cnt < (req_cnt + 2)) {
  1464. cnt = RD_REG_DWORD_RELAXED(req->req_q_out);
  1465. if (req->ring_index < cnt)
  1466. req->cnt = cnt - req->ring_index;
  1467. else
  1468. req->cnt = req->length -
  1469. (req->ring_index - cnt);
  1470. }
  1471. if (req->cnt < (req_cnt + 2))
  1472. goto queuing_error;
  1473. status |= QDSS_GOT_Q_SPACE;
  1474. /* Build header part of command packet (excluding the OPCODE). */
  1475. req->current_outstanding_cmd = handle;
  1476. req->outstanding_cmds[handle] = sp;
  1477. sp->handle = handle;
  1478. cmd->host_scribble = (unsigned char *)(unsigned long)handle;
  1479. req->cnt -= req_cnt;
  1480. /* Fill-in common area */
  1481. cmd_pkt = (struct cmd_type_crc_2 *)req->ring_ptr;
  1482. cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
  1483. clr_ptr = (uint32_t *)cmd_pkt + 2;
  1484. memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
  1485. /* Set NPORT-ID and LUN number*/
  1486. cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  1487. cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
  1488. cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
  1489. cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
  1490. int_to_scsilun(cmd->device->lun, &cmd_pkt->lun);
  1491. host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
  1492. /* Total Data and protection segment(s) */
  1493. cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
  1494. /* Build IOCB segments and adjust for data protection segments */
  1495. if (qla24xx_build_scsi_crc_2_iocbs(sp, (struct cmd_type_crc_2 *)
  1496. req->ring_ptr, tot_dsds, tot_prot_dsds, fw_prot_opts) !=
  1497. QLA_SUCCESS)
  1498. goto queuing_error;
  1499. cmd_pkt->entry_count = (uint8_t)req_cnt;
  1500. /* Specify response queue number where completion should happen */
  1501. cmd_pkt->entry_status = (uint8_t) rsp->id;
  1502. cmd_pkt->timeout = __constant_cpu_to_le16(0);
  1503. wmb();
  1504. /* Adjust ring index. */
  1505. req->ring_index++;
  1506. if (req->ring_index == req->length) {
  1507. req->ring_index = 0;
  1508. req->ring_ptr = req->ring;
  1509. } else
  1510. req->ring_ptr++;
  1511. /* Set chip new ring index. */
  1512. WRT_REG_DWORD(req->req_q_in, req->ring_index);
  1513. RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr);
  1514. /* Manage unprocessed RIO/ZIO commands in response queue. */
  1515. if (vha->flags.process_response_queue &&
  1516. rsp->ring_ptr->signature != RESPONSE_PROCESSED)
  1517. qla24xx_process_response_queue(vha, rsp);
  1518. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1519. return QLA_SUCCESS;
  1520. queuing_error:
  1521. if (status & QDSS_GOT_Q_SPACE) {
  1522. req->outstanding_cmds[handle] = NULL;
  1523. req->cnt += req_cnt;
  1524. }
  1525. /* Cleanup will be performed by the caller (queuecommand) */
  1526. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1527. return QLA_FUNCTION_FAILED;
  1528. }
  1529. static void qla25xx_set_que(srb_t *sp, struct rsp_que **rsp)
  1530. {
  1531. struct scsi_cmnd *cmd = GET_CMD_SP(sp);
  1532. struct qla_hw_data *ha = sp->fcport->vha->hw;
  1533. int affinity = cmd->request->cpu;
  1534. if (ha->flags.cpu_affinity_enabled && affinity >= 0 &&
  1535. affinity < ha->max_rsp_queues - 1)
  1536. *rsp = ha->rsp_q_map[affinity + 1];
  1537. else
  1538. *rsp = ha->rsp_q_map[0];
  1539. }
  1540. /* Generic Control-SRB manipulation functions. */
  1541. void *
  1542. qla2x00_alloc_iocbs(scsi_qla_host_t *vha, srb_t *sp)
  1543. {
  1544. struct qla_hw_data *ha = vha->hw;
  1545. struct req_que *req = ha->req_q_map[0];
  1546. device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id);
  1547. uint32_t index, handle;
  1548. request_t *pkt;
  1549. uint16_t cnt, req_cnt;
  1550. pkt = NULL;
  1551. req_cnt = 1;
  1552. handle = 0;
  1553. if (!sp)
  1554. goto skip_cmd_array;
  1555. /* Check for room in outstanding command list. */
  1556. handle = req->current_outstanding_cmd;
  1557. for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
  1558. handle++;
  1559. if (handle == MAX_OUTSTANDING_COMMANDS)
  1560. handle = 1;
  1561. if (!req->outstanding_cmds[handle])
  1562. break;
  1563. }
  1564. if (index == MAX_OUTSTANDING_COMMANDS) {
  1565. ql_log(ql_log_warn, vha, 0x700b,
  1566. "No room on oustanding cmd array.\n");
  1567. goto queuing_error;
  1568. }
  1569. /* Prep command array. */
  1570. req->current_outstanding_cmd = handle;
  1571. req->outstanding_cmds[handle] = sp;
  1572. sp->handle = handle;
  1573. /* Adjust entry-counts as needed. */
  1574. if (sp->type != SRB_SCSI_CMD)
  1575. req_cnt = sp->iocbs;
  1576. skip_cmd_array:
  1577. /* Check for room on request queue. */
  1578. if (req->cnt < req_cnt) {
  1579. if (ha->mqenable || IS_QLA83XX(ha))
  1580. cnt = RD_REG_DWORD(&reg->isp25mq.req_q_out);
  1581. else if (IS_QLA82XX(ha))
  1582. cnt = RD_REG_DWORD(&reg->isp82.req_q_out);
  1583. else if (IS_FWI2_CAPABLE(ha))
  1584. cnt = RD_REG_DWORD(&reg->isp24.req_q_out);
  1585. else
  1586. cnt = qla2x00_debounce_register(
  1587. ISP_REQ_Q_OUT(ha, &reg->isp));
  1588. if (req->ring_index < cnt)
  1589. req->cnt = cnt - req->ring_index;
  1590. else
  1591. req->cnt = req->length -
  1592. (req->ring_index - cnt);
  1593. }
  1594. if (req->cnt < req_cnt)
  1595. goto queuing_error;
  1596. /* Prep packet */
  1597. req->cnt -= req_cnt;
  1598. pkt = req->ring_ptr;
  1599. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  1600. pkt->entry_count = req_cnt;
  1601. pkt->handle = handle;
  1602. queuing_error:
  1603. return pkt;
  1604. }
  1605. static void
  1606. qla24xx_login_iocb(srb_t *sp, struct logio_entry_24xx *logio)
  1607. {
  1608. struct srb_iocb *lio = &sp->u.iocb_cmd;
  1609. logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1610. logio->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
  1611. if (lio->u.logio.flags & SRB_LOGIN_COND_PLOGI)
  1612. logio->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
  1613. if (lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI)
  1614. logio->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
  1615. logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  1616. logio->port_id[0] = sp->fcport->d_id.b.al_pa;
  1617. logio->port_id[1] = sp->fcport->d_id.b.area;
  1618. logio->port_id[2] = sp->fcport->d_id.b.domain;
  1619. logio->vp_index = sp->fcport->vp_idx;
  1620. }
  1621. static void
  1622. qla2x00_login_iocb(srb_t *sp, struct mbx_entry *mbx)
  1623. {
  1624. struct qla_hw_data *ha = sp->fcport->vha->hw;
  1625. struct srb_iocb *lio = &sp->u.iocb_cmd;
  1626. uint16_t opts;
  1627. mbx->entry_type = MBX_IOCB_TYPE;
  1628. SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
  1629. mbx->mb0 = cpu_to_le16(MBC_LOGIN_FABRIC_PORT);
  1630. opts = lio->u.logio.flags & SRB_LOGIN_COND_PLOGI ? BIT_0 : 0;
  1631. opts |= lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI ? BIT_1 : 0;
  1632. if (HAS_EXTENDED_IDS(ha)) {
  1633. mbx->mb1 = cpu_to_le16(sp->fcport->loop_id);
  1634. mbx->mb10 = cpu_to_le16(opts);
  1635. } else {
  1636. mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | opts);
  1637. }
  1638. mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain);
  1639. mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 |
  1640. sp->fcport->d_id.b.al_pa);
  1641. mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
  1642. }
  1643. static void
  1644. qla24xx_logout_iocb(srb_t *sp, struct logio_entry_24xx *logio)
  1645. {
  1646. logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1647. logio->control_flags =
  1648. cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
  1649. logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  1650. logio->port_id[0] = sp->fcport->d_id.b.al_pa;
  1651. logio->port_id[1] = sp->fcport->d_id.b.area;
  1652. logio->port_id[2] = sp->fcport->d_id.b.domain;
  1653. logio->vp_index = sp->fcport->vp_idx;
  1654. }
  1655. static void
  1656. qla2x00_logout_iocb(srb_t *sp, struct mbx_entry *mbx)
  1657. {
  1658. struct qla_hw_data *ha = sp->fcport->vha->hw;
  1659. mbx->entry_type = MBX_IOCB_TYPE;
  1660. SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
  1661. mbx->mb0 = cpu_to_le16(MBC_LOGOUT_FABRIC_PORT);
  1662. mbx->mb1 = HAS_EXTENDED_IDS(ha) ?
  1663. cpu_to_le16(sp->fcport->loop_id):
  1664. cpu_to_le16(sp->fcport->loop_id << 8);
  1665. mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain);
  1666. mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 |
  1667. sp->fcport->d_id.b.al_pa);
  1668. mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
  1669. /* Implicit: mbx->mbx10 = 0. */
  1670. }
  1671. static void
  1672. qla24xx_adisc_iocb(srb_t *sp, struct logio_entry_24xx *logio)
  1673. {
  1674. logio->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1675. logio->control_flags = cpu_to_le16(LCF_COMMAND_ADISC);
  1676. logio->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  1677. logio->vp_index = sp->fcport->vp_idx;
  1678. }
  1679. static void
  1680. qla2x00_adisc_iocb(srb_t *sp, struct mbx_entry *mbx)
  1681. {
  1682. struct qla_hw_data *ha = sp->fcport->vha->hw;
  1683. mbx->entry_type = MBX_IOCB_TYPE;
  1684. SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id);
  1685. mbx->mb0 = cpu_to_le16(MBC_GET_PORT_DATABASE);
  1686. if (HAS_EXTENDED_IDS(ha)) {
  1687. mbx->mb1 = cpu_to_le16(sp->fcport->loop_id);
  1688. mbx->mb10 = cpu_to_le16(BIT_0);
  1689. } else {
  1690. mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | BIT_0);
  1691. }
  1692. mbx->mb2 = cpu_to_le16(MSW(ha->async_pd_dma));
  1693. mbx->mb3 = cpu_to_le16(LSW(ha->async_pd_dma));
  1694. mbx->mb6 = cpu_to_le16(MSW(MSD(ha->async_pd_dma)));
  1695. mbx->mb7 = cpu_to_le16(LSW(MSD(ha->async_pd_dma)));
  1696. mbx->mb9 = cpu_to_le16(sp->fcport->vp_idx);
  1697. }
  1698. static void
  1699. qla24xx_tm_iocb(srb_t *sp, struct tsk_mgmt_entry *tsk)
  1700. {
  1701. uint32_t flags;
  1702. unsigned int lun;
  1703. struct fc_port *fcport = sp->fcport;
  1704. scsi_qla_host_t *vha = fcport->vha;
  1705. struct qla_hw_data *ha = vha->hw;
  1706. struct srb_iocb *iocb = &sp->u.iocb_cmd;
  1707. struct req_que *req = vha->req;
  1708. flags = iocb->u.tmf.flags;
  1709. lun = iocb->u.tmf.lun;
  1710. tsk->entry_type = TSK_MGMT_IOCB_TYPE;
  1711. tsk->entry_count = 1;
  1712. tsk->handle = MAKE_HANDLE(req->id, tsk->handle);
  1713. tsk->nport_handle = cpu_to_le16(fcport->loop_id);
  1714. tsk->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
  1715. tsk->control_flags = cpu_to_le32(flags);
  1716. tsk->port_id[0] = fcport->d_id.b.al_pa;
  1717. tsk->port_id[1] = fcport->d_id.b.area;
  1718. tsk->port_id[2] = fcport->d_id.b.domain;
  1719. tsk->vp_index = fcport->vp_idx;
  1720. if (flags == TCF_LUN_RESET) {
  1721. int_to_scsilun(lun, &tsk->lun);
  1722. host_to_fcp_swap((uint8_t *)&tsk->lun,
  1723. sizeof(tsk->lun));
  1724. }
  1725. }
  1726. static void
  1727. qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb)
  1728. {
  1729. struct fc_bsg_job *bsg_job = sp->u.bsg_job;
  1730. els_iocb->entry_type = ELS_IOCB_TYPE;
  1731. els_iocb->entry_count = 1;
  1732. els_iocb->sys_define = 0;
  1733. els_iocb->entry_status = 0;
  1734. els_iocb->handle = sp->handle;
  1735. els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  1736. els_iocb->tx_dsd_count = __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
  1737. els_iocb->vp_index = sp->fcport->vp_idx;
  1738. els_iocb->sof_type = EST_SOFI3;
  1739. els_iocb->rx_dsd_count = __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
  1740. els_iocb->opcode =
  1741. sp->type == SRB_ELS_CMD_RPT ?
  1742. bsg_job->request->rqst_data.r_els.els_code :
  1743. bsg_job->request->rqst_data.h_els.command_code;
  1744. els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa;
  1745. els_iocb->port_id[1] = sp->fcport->d_id.b.area;
  1746. els_iocb->port_id[2] = sp->fcport->d_id.b.domain;
  1747. els_iocb->control_flags = 0;
  1748. els_iocb->rx_byte_count =
  1749. cpu_to_le32(bsg_job->reply_payload.payload_len);
  1750. els_iocb->tx_byte_count =
  1751. cpu_to_le32(bsg_job->request_payload.payload_len);
  1752. els_iocb->tx_address[0] = cpu_to_le32(LSD(sg_dma_address
  1753. (bsg_job->request_payload.sg_list)));
  1754. els_iocb->tx_address[1] = cpu_to_le32(MSD(sg_dma_address
  1755. (bsg_job->request_payload.sg_list)));
  1756. els_iocb->tx_len = cpu_to_le32(sg_dma_len
  1757. (bsg_job->request_payload.sg_list));
  1758. els_iocb->rx_address[0] = cpu_to_le32(LSD(sg_dma_address
  1759. (bsg_job->reply_payload.sg_list)));
  1760. els_iocb->rx_address[1] = cpu_to_le32(MSD(sg_dma_address
  1761. (bsg_job->reply_payload.sg_list)));
  1762. els_iocb->rx_len = cpu_to_le32(sg_dma_len
  1763. (bsg_job->reply_payload.sg_list));
  1764. }
  1765. static void
  1766. qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb)
  1767. {
  1768. uint16_t avail_dsds;
  1769. uint32_t *cur_dsd;
  1770. struct scatterlist *sg;
  1771. int index;
  1772. uint16_t tot_dsds;
  1773. scsi_qla_host_t *vha = sp->fcport->vha;
  1774. struct qla_hw_data *ha = vha->hw;
  1775. struct fc_bsg_job *bsg_job = sp->u.bsg_job;
  1776. int loop_iterartion = 0;
  1777. int cont_iocb_prsnt = 0;
  1778. int entry_count = 1;
  1779. memset(ct_iocb, 0, sizeof(ms_iocb_entry_t));
  1780. ct_iocb->entry_type = CT_IOCB_TYPE;
  1781. ct_iocb->entry_status = 0;
  1782. ct_iocb->handle1 = sp->handle;
  1783. SET_TARGET_ID(ha, ct_iocb->loop_id, sp->fcport->loop_id);
  1784. ct_iocb->status = __constant_cpu_to_le16(0);
  1785. ct_iocb->control_flags = __constant_cpu_to_le16(0);
  1786. ct_iocb->timeout = 0;
  1787. ct_iocb->cmd_dsd_count =
  1788. __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
  1789. ct_iocb->total_dsd_count =
  1790. __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt + 1);
  1791. ct_iocb->req_bytecount =
  1792. cpu_to_le32(bsg_job->request_payload.payload_len);
  1793. ct_iocb->rsp_bytecount =
  1794. cpu_to_le32(bsg_job->reply_payload.payload_len);
  1795. ct_iocb->dseg_req_address[0] = cpu_to_le32(LSD(sg_dma_address
  1796. (bsg_job->request_payload.sg_list)));
  1797. ct_iocb->dseg_req_address[1] = cpu_to_le32(MSD(sg_dma_address
  1798. (bsg_job->request_payload.sg_list)));
  1799. ct_iocb->dseg_req_length = ct_iocb->req_bytecount;
  1800. ct_iocb->dseg_rsp_address[0] = cpu_to_le32(LSD(sg_dma_address
  1801. (bsg_job->reply_payload.sg_list)));
  1802. ct_iocb->dseg_rsp_address[1] = cpu_to_le32(MSD(sg_dma_address
  1803. (bsg_job->reply_payload.sg_list)));
  1804. ct_iocb->dseg_rsp_length = ct_iocb->rsp_bytecount;
  1805. avail_dsds = 1;
  1806. cur_dsd = (uint32_t *)ct_iocb->dseg_rsp_address;
  1807. index = 0;
  1808. tot_dsds = bsg_job->reply_payload.sg_cnt;
  1809. for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
  1810. dma_addr_t sle_dma;
  1811. cont_a64_entry_t *cont_pkt;
  1812. /* Allocate additional continuation packets? */
  1813. if (avail_dsds == 0) {
  1814. /*
  1815. * Five DSDs are available in the Cont.
  1816. * Type 1 IOCB.
  1817. */
  1818. cont_pkt = qla2x00_prep_cont_type1_iocb(vha,
  1819. vha->hw->req_q_map[0]);
  1820. cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
  1821. avail_dsds = 5;
  1822. cont_iocb_prsnt = 1;
  1823. entry_count++;
  1824. }
  1825. sle_dma = sg_dma_address(sg);
  1826. *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
  1827. *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
  1828. *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
  1829. loop_iterartion++;
  1830. avail_dsds--;
  1831. }
  1832. ct_iocb->entry_count = entry_count;
  1833. }
  1834. static void
  1835. qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb)
  1836. {
  1837. uint16_t avail_dsds;
  1838. uint32_t *cur_dsd;
  1839. struct scatterlist *sg;
  1840. int index;
  1841. uint16_t tot_dsds;
  1842. scsi_qla_host_t *vha = sp->fcport->vha;
  1843. struct qla_hw_data *ha = vha->hw;
  1844. struct fc_bsg_job *bsg_job = sp->u.bsg_job;
  1845. int loop_iterartion = 0;
  1846. int cont_iocb_prsnt = 0;
  1847. int entry_count = 1;
  1848. ct_iocb->entry_type = CT_IOCB_TYPE;
  1849. ct_iocb->entry_status = 0;
  1850. ct_iocb->sys_define = 0;
  1851. ct_iocb->handle = sp->handle;
  1852. ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  1853. ct_iocb->vp_index = sp->fcport->vp_idx;
  1854. ct_iocb->comp_status = __constant_cpu_to_le16(0);
  1855. ct_iocb->cmd_dsd_count =
  1856. __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt);
  1857. ct_iocb->timeout = 0;
  1858. ct_iocb->rsp_dsd_count =
  1859. __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt);
  1860. ct_iocb->rsp_byte_count =
  1861. cpu_to_le32(bsg_job->reply_payload.payload_len);
  1862. ct_iocb->cmd_byte_count =
  1863. cpu_to_le32(bsg_job->request_payload.payload_len);
  1864. ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address
  1865. (bsg_job->request_payload.sg_list)));
  1866. ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address
  1867. (bsg_job->request_payload.sg_list)));
  1868. ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len
  1869. (bsg_job->request_payload.sg_list));
  1870. avail_dsds = 1;
  1871. cur_dsd = (uint32_t *)ct_iocb->dseg_1_address;
  1872. index = 0;
  1873. tot_dsds = bsg_job->reply_payload.sg_cnt;
  1874. for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) {
  1875. dma_addr_t sle_dma;
  1876. cont_a64_entry_t *cont_pkt;
  1877. /* Allocate additional continuation packets? */
  1878. if (avail_dsds == 0) {
  1879. /*
  1880. * Five DSDs are available in the Cont.
  1881. * Type 1 IOCB.
  1882. */
  1883. cont_pkt = qla2x00_prep_cont_type1_iocb(vha,
  1884. ha->req_q_map[0]);
  1885. cur_dsd = (uint32_t *) cont_pkt->dseg_0_address;
  1886. avail_dsds = 5;
  1887. cont_iocb_prsnt = 1;
  1888. entry_count++;
  1889. }
  1890. sle_dma = sg_dma_address(sg);
  1891. *cur_dsd++ = cpu_to_le32(LSD(sle_dma));
  1892. *cur_dsd++ = cpu_to_le32(MSD(sle_dma));
  1893. *cur_dsd++ = cpu_to_le32(sg_dma_len(sg));
  1894. loop_iterartion++;
  1895. avail_dsds--;
  1896. }
  1897. ct_iocb->entry_count = entry_count;
  1898. }
  1899. /*
  1900. * qla82xx_start_scsi() - Send a SCSI command to the ISP
  1901. * @sp: command to send to the ISP
  1902. *
  1903. * Returns non-zero if a failure occurred, else zero.
  1904. */
  1905. int
  1906. qla82xx_start_scsi(srb_t *sp)
  1907. {
  1908. int ret, nseg;
  1909. unsigned long flags;
  1910. struct scsi_cmnd *cmd;
  1911. uint32_t *clr_ptr;
  1912. uint32_t index;
  1913. uint32_t handle;
  1914. uint16_t cnt;
  1915. uint16_t req_cnt;
  1916. uint16_t tot_dsds;
  1917. struct device_reg_82xx __iomem *reg;
  1918. uint32_t dbval;
  1919. uint32_t *fcp_dl;
  1920. uint8_t additional_cdb_len;
  1921. struct ct6_dsd *ctx;
  1922. struct scsi_qla_host *vha = sp->fcport->vha;
  1923. struct qla_hw_data *ha = vha->hw;
  1924. struct req_que *req = NULL;
  1925. struct rsp_que *rsp = NULL;
  1926. char tag[2];
  1927. /* Setup device pointers. */
  1928. ret = 0;
  1929. reg = &ha->iobase->isp82;
  1930. cmd = GET_CMD_SP(sp);
  1931. req = vha->req;
  1932. rsp = ha->rsp_q_map[0];
  1933. /* So we know we haven't pci_map'ed anything yet */
  1934. tot_dsds = 0;
  1935. dbval = 0x04 | (ha->portnum << 5);
  1936. /* Send marker if required */
  1937. if (vha->marker_needed != 0) {
  1938. if (qla2x00_marker(vha, req,
  1939. rsp, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) {
  1940. ql_log(ql_log_warn, vha, 0x300c,
  1941. "qla2x00_marker failed for cmd=%p.\n", cmd);
  1942. return QLA_FUNCTION_FAILED;
  1943. }
  1944. vha->marker_needed = 0;
  1945. }
  1946. /* Acquire ring specific lock */
  1947. spin_lock_irqsave(&ha->hardware_lock, flags);
  1948. /* Check for room in outstanding command list. */
  1949. handle = req->current_outstanding_cmd;
  1950. for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) {
  1951. handle++;
  1952. if (handle == MAX_OUTSTANDING_COMMANDS)
  1953. handle = 1;
  1954. if (!req->outstanding_cmds[handle])
  1955. break;
  1956. }
  1957. if (index == MAX_OUTSTANDING_COMMANDS)
  1958. goto queuing_error;
  1959. /* Map the sg table so we have an accurate count of sg entries needed */
  1960. if (scsi_sg_count(cmd)) {
  1961. nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd),
  1962. scsi_sg_count(cmd), cmd->sc_data_direction);
  1963. if (unlikely(!nseg))
  1964. goto queuing_error;
  1965. } else
  1966. nseg = 0;
  1967. tot_dsds = nseg;
  1968. if (tot_dsds > ql2xshiftctondsd) {
  1969. struct cmd_type_6 *cmd_pkt;
  1970. uint16_t more_dsd_lists = 0;
  1971. struct dsd_dma *dsd_ptr;
  1972. uint16_t i;
  1973. more_dsd_lists = qla24xx_calc_dsd_lists(tot_dsds);
  1974. if ((more_dsd_lists + ha->gbl_dsd_inuse) >= NUM_DSD_CHAIN) {
  1975. ql_dbg(ql_dbg_io, vha, 0x300d,
  1976. "Num of DSD list %d is than %d for cmd=%p.\n",
  1977. more_dsd_lists + ha->gbl_dsd_inuse, NUM_DSD_CHAIN,
  1978. cmd);
  1979. goto queuing_error;
  1980. }
  1981. if (more_dsd_lists <= ha->gbl_dsd_avail)
  1982. goto sufficient_dsds;
  1983. else
  1984. more_dsd_lists -= ha->gbl_dsd_avail;
  1985. for (i = 0; i < more_dsd_lists; i++) {
  1986. dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC);
  1987. if (!dsd_ptr) {
  1988. ql_log(ql_log_fatal, vha, 0x300e,
  1989. "Failed to allocate memory for dsd_dma "
  1990. "for cmd=%p.\n", cmd);
  1991. goto queuing_error;
  1992. }
  1993. dsd_ptr->dsd_addr = dma_pool_alloc(ha->dl_dma_pool,
  1994. GFP_ATOMIC, &dsd_ptr->dsd_list_dma);
  1995. if (!dsd_ptr->dsd_addr) {
  1996. kfree(dsd_ptr);
  1997. ql_log(ql_log_fatal, vha, 0x300f,
  1998. "Failed to allocate memory for dsd_addr "
  1999. "for cmd=%p.\n", cmd);
  2000. goto queuing_error;
  2001. }
  2002. list_add_tail(&dsd_ptr->list, &ha->gbl_dsd_list);
  2003. ha->gbl_dsd_avail++;
  2004. }
  2005. sufficient_dsds:
  2006. req_cnt = 1;
  2007. if (req->cnt < (req_cnt + 2)) {
  2008. cnt = (uint16_t)RD_REG_DWORD_RELAXED(
  2009. &reg->req_q_out[0]);
  2010. if (req->ring_index < cnt)
  2011. req->cnt = cnt - req->ring_index;
  2012. else
  2013. req->cnt = req->length -
  2014. (req->ring_index - cnt);
  2015. }
  2016. if (req->cnt < (req_cnt + 2))
  2017. goto queuing_error;
  2018. ctx = sp->u.scmd.ctx =
  2019. mempool_alloc(ha->ctx_mempool, GFP_ATOMIC);
  2020. if (!ctx) {
  2021. ql_log(ql_log_fatal, vha, 0x3010,
  2022. "Failed to allocate ctx for cmd=%p.\n", cmd);
  2023. goto queuing_error;
  2024. }
  2025. memset(ctx, 0, sizeof(struct ct6_dsd));
  2026. ctx->fcp_cmnd = dma_pool_alloc(ha->fcp_cmnd_dma_pool,
  2027. GFP_ATOMIC, &ctx->fcp_cmnd_dma);
  2028. if (!ctx->fcp_cmnd) {
  2029. ql_log(ql_log_fatal, vha, 0x3011,
  2030. "Failed to allocate fcp_cmnd for cmd=%p.\n", cmd);
  2031. goto queuing_error_fcp_cmnd;
  2032. }
  2033. /* Initialize the DSD list and dma handle */
  2034. INIT_LIST_HEAD(&ctx->dsd_list);
  2035. ctx->dsd_use_cnt = 0;
  2036. if (cmd->cmd_len > 16) {
  2037. additional_cdb_len = cmd->cmd_len - 16;
  2038. if ((cmd->cmd_len % 4) != 0) {
  2039. /* SCSI command bigger than 16 bytes must be
  2040. * multiple of 4
  2041. */
  2042. ql_log(ql_log_warn, vha, 0x3012,
  2043. "scsi cmd len %d not multiple of 4 "
  2044. "for cmd=%p.\n", cmd->cmd_len, cmd);
  2045. goto queuing_error_fcp_cmnd;
  2046. }
  2047. ctx->fcp_cmnd_len = 12 + cmd->cmd_len + 4;
  2048. } else {
  2049. additional_cdb_len = 0;
  2050. ctx->fcp_cmnd_len = 12 + 16 + 4;
  2051. }
  2052. cmd_pkt = (struct cmd_type_6 *)req->ring_ptr;
  2053. cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
  2054. /* Zero out remaining portion of packet. */
  2055. /* tagged queuing modifier -- default is TSK_SIMPLE (0). */
  2056. clr_ptr = (uint32_t *)cmd_pkt + 2;
  2057. memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
  2058. cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
  2059. /* Set NPORT-ID and LUN number*/
  2060. cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  2061. cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
  2062. cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
  2063. cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
  2064. cmd_pkt->vp_index = sp->fcport->vp_idx;
  2065. /* Build IOCB segments */
  2066. if (qla24xx_build_scsi_type_6_iocbs(sp, cmd_pkt, tot_dsds))
  2067. goto queuing_error_fcp_cmnd;
  2068. int_to_scsilun(cmd->device->lun, &cmd_pkt->lun);
  2069. host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun));
  2070. /* build FCP_CMND IU */
  2071. memset(ctx->fcp_cmnd, 0, sizeof(struct fcp_cmnd));
  2072. int_to_scsilun(cmd->device->lun, &ctx->fcp_cmnd->lun);
  2073. ctx->fcp_cmnd->additional_cdb_len = additional_cdb_len;
  2074. if (cmd->sc_data_direction == DMA_TO_DEVICE)
  2075. ctx->fcp_cmnd->additional_cdb_len |= 1;
  2076. else if (cmd->sc_data_direction == DMA_FROM_DEVICE)
  2077. ctx->fcp_cmnd->additional_cdb_len |= 2;
  2078. /*
  2079. * Update tagged queuing modifier -- default is TSK_SIMPLE (0).
  2080. */
  2081. if (scsi_populate_tag_msg(cmd, tag)) {
  2082. switch (tag[0]) {
  2083. case HEAD_OF_QUEUE_TAG:
  2084. ctx->fcp_cmnd->task_attribute =
  2085. TSK_HEAD_OF_QUEUE;
  2086. break;
  2087. case ORDERED_QUEUE_TAG:
  2088. ctx->fcp_cmnd->task_attribute =
  2089. TSK_ORDERED;
  2090. break;
  2091. }
  2092. }
  2093. /* Populate the FCP_PRIO. */
  2094. if (ha->flags.fcp_prio_enabled)
  2095. ctx->fcp_cmnd->task_attribute |=
  2096. sp->fcport->fcp_prio << 3;
  2097. memcpy(ctx->fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len);
  2098. fcp_dl = (uint32_t *)(ctx->fcp_cmnd->cdb + 16 +
  2099. additional_cdb_len);
  2100. *fcp_dl = htonl((uint32_t)scsi_bufflen(cmd));
  2101. cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(ctx->fcp_cmnd_len);
  2102. cmd_pkt->fcp_cmnd_dseg_address[0] =
  2103. cpu_to_le32(LSD(ctx->fcp_cmnd_dma));
  2104. cmd_pkt->fcp_cmnd_dseg_address[1] =
  2105. cpu_to_le32(MSD(ctx->fcp_cmnd_dma));
  2106. sp->flags |= SRB_FCP_CMND_DMA_VALID;
  2107. cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
  2108. /* Set total data segment count. */
  2109. cmd_pkt->entry_count = (uint8_t)req_cnt;
  2110. /* Specify response queue number where
  2111. * completion should happen
  2112. */
  2113. cmd_pkt->entry_status = (uint8_t) rsp->id;
  2114. } else {
  2115. struct cmd_type_7 *cmd_pkt;
  2116. req_cnt = qla24xx_calc_iocbs(vha, tot_dsds);
  2117. if (req->cnt < (req_cnt + 2)) {
  2118. cnt = (uint16_t)RD_REG_DWORD_RELAXED(
  2119. &reg->req_q_out[0]);
  2120. if (req->ring_index < cnt)
  2121. req->cnt = cnt - req->ring_index;
  2122. else
  2123. req->cnt = req->length -
  2124. (req->ring_index - cnt);
  2125. }
  2126. if (req->cnt < (req_cnt + 2))
  2127. goto queuing_error;
  2128. cmd_pkt = (struct cmd_type_7 *)req->ring_ptr;
  2129. cmd_pkt->handle = MAKE_HANDLE(req->id, handle);
  2130. /* Zero out remaining portion of packet. */
  2131. /* tagged queuing modifier -- default is TSK_SIMPLE (0).*/
  2132. clr_ptr = (uint32_t *)cmd_pkt + 2;
  2133. memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8);
  2134. cmd_pkt->dseg_count = cpu_to_le16(tot_dsds);
  2135. /* Set NPORT-ID and LUN number*/
  2136. cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id);
  2137. cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa;
  2138. cmd_pkt->port_id[1] = sp->fcport->d_id.b.area;
  2139. cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain;
  2140. cmd_pkt->vp_index = sp->fcport->vp_idx;
  2141. int_to_scsilun(cmd->device->lun, &cmd_pkt->lun);
  2142. host_to_fcp_swap((uint8_t *)&cmd_pkt->lun,
  2143. sizeof(cmd_pkt->lun));
  2144. /*
  2145. * Update tagged queuing modifier -- default is TSK_SIMPLE (0).
  2146. */
  2147. if (scsi_populate_tag_msg(cmd, tag)) {
  2148. switch (tag[0]) {
  2149. case HEAD_OF_QUEUE_TAG:
  2150. cmd_pkt->task = TSK_HEAD_OF_QUEUE;
  2151. break;
  2152. case ORDERED_QUEUE_TAG:
  2153. cmd_pkt->task = TSK_ORDERED;
  2154. break;
  2155. }
  2156. }
  2157. /* Populate the FCP_PRIO. */
  2158. if (ha->flags.fcp_prio_enabled)
  2159. cmd_pkt->task |= sp->fcport->fcp_prio << 3;
  2160. /* Load SCSI command packet. */
  2161. memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len);
  2162. host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb));
  2163. cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd));
  2164. /* Build IOCB segments */
  2165. qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds);
  2166. /* Set total data segment count. */
  2167. cmd_pkt->entry_count = (uint8_t)req_cnt;
  2168. /* Specify response queue number where
  2169. * completion should happen.
  2170. */
  2171. cmd_pkt->entry_status = (uint8_t) rsp->id;
  2172. }
  2173. /* Build command packet. */
  2174. req->current_outstanding_cmd = handle;
  2175. req->outstanding_cmds[handle] = sp;
  2176. sp->handle = handle;
  2177. cmd->host_scribble = (unsigned char *)(unsigned long)handle;
  2178. req->cnt -= req_cnt;
  2179. wmb();
  2180. /* Adjust ring index. */
  2181. req->ring_index++;
  2182. if (req->ring_index == req->length) {
  2183. req->ring_index = 0;
  2184. req->ring_ptr = req->ring;
  2185. } else
  2186. req->ring_ptr++;
  2187. sp->flags |= SRB_DMA_VALID;
  2188. /* Set chip new ring index. */
  2189. /* write, read and verify logic */
  2190. dbval = dbval | (req->id << 8) | (req->ring_index << 16);
  2191. if (ql2xdbwr)
  2192. qla82xx_wr_32(ha, ha->nxdb_wr_ptr, dbval);
  2193. else {
  2194. WRT_REG_DWORD(
  2195. (unsigned long __iomem *)ha->nxdb_wr_ptr,
  2196. dbval);
  2197. wmb();
  2198. while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) {
  2199. WRT_REG_DWORD(
  2200. (unsigned long __iomem *)ha->nxdb_wr_ptr,
  2201. dbval);
  2202. wmb();
  2203. }
  2204. }
  2205. /* Manage unprocessed RIO/ZIO commands in response queue. */
  2206. if (vha->flags.process_response_queue &&
  2207. rsp->ring_ptr->signature != RESPONSE_PROCESSED)
  2208. qla24xx_process_response_queue(vha, rsp);
  2209. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2210. return QLA_SUCCESS;
  2211. queuing_error_fcp_cmnd:
  2212. dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd, ctx->fcp_cmnd_dma);
  2213. queuing_error:
  2214. if (tot_dsds)
  2215. scsi_dma_unmap(cmd);
  2216. if (sp->u.scmd.ctx) {
  2217. mempool_free(sp->u.scmd.ctx, ha->ctx_mempool);
  2218. sp->u.scmd.ctx = NULL;
  2219. }
  2220. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2221. return QLA_FUNCTION_FAILED;
  2222. }
  2223. int
  2224. qla2x00_start_sp(srb_t *sp)
  2225. {
  2226. int rval;
  2227. struct qla_hw_data *ha = sp->fcport->vha->hw;
  2228. void *pkt;
  2229. unsigned long flags;
  2230. rval = QLA_FUNCTION_FAILED;
  2231. spin_lock_irqsave(&ha->hardware_lock, flags);
  2232. pkt = qla2x00_alloc_iocbs(sp->fcport->vha, sp);
  2233. if (!pkt) {
  2234. ql_log(ql_log_warn, sp->fcport->vha, 0x700c,
  2235. "qla2x00_alloc_iocbs failed.\n");
  2236. goto done;
  2237. }
  2238. rval = QLA_SUCCESS;
  2239. switch (sp->type) {
  2240. case SRB_LOGIN_CMD:
  2241. IS_FWI2_CAPABLE(ha) ?
  2242. qla24xx_login_iocb(sp, pkt) :
  2243. qla2x00_login_iocb(sp, pkt);
  2244. break;
  2245. case SRB_LOGOUT_CMD:
  2246. IS_FWI2_CAPABLE(ha) ?
  2247. qla24xx_logout_iocb(sp, pkt) :
  2248. qla2x00_logout_iocb(sp, pkt);
  2249. break;
  2250. case SRB_ELS_CMD_RPT:
  2251. case SRB_ELS_CMD_HST:
  2252. qla24xx_els_iocb(sp, pkt);
  2253. break;
  2254. case SRB_CT_CMD:
  2255. IS_FWI2_CAPABLE(ha) ?
  2256. qla24xx_ct_iocb(sp, pkt) :
  2257. qla2x00_ct_iocb(sp, pkt);
  2258. break;
  2259. case SRB_ADISC_CMD:
  2260. IS_FWI2_CAPABLE(ha) ?
  2261. qla24xx_adisc_iocb(sp, pkt) :
  2262. qla2x00_adisc_iocb(sp, pkt);
  2263. break;
  2264. case SRB_TM_CMD:
  2265. qla24xx_tm_iocb(sp, pkt);
  2266. break;
  2267. default:
  2268. break;
  2269. }
  2270. wmb();
  2271. qla2x00_start_iocbs(sp->fcport->vha, ha->req_q_map[0]);
  2272. done:
  2273. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2274. return rval;
  2275. }