qla_iocb.c 70 KB

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