qla_iocb.c 70 KB

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