qla_iocb.c 70 KB

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