qla_iocb.c 70 KB

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