qla_iocb.c 70 KB

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