qla_iocb.c 70 KB

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