qla_mbx.c 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/delay.h>
  9. /*
  10. * qla2x00_mailbox_command
  11. * Issue mailbox command and waits for completion.
  12. *
  13. * Input:
  14. * ha = adapter block pointer.
  15. * mcp = driver internal mbx struct pointer.
  16. *
  17. * Output:
  18. * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
  19. *
  20. * Returns:
  21. * 0 : QLA_SUCCESS = cmd performed success
  22. * 1 : QLA_FUNCTION_FAILED (error encountered)
  23. * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
  24. *
  25. * Context:
  26. * Kernel context.
  27. */
  28. static int
  29. qla2x00_mailbox_command(scsi_qla_host_t *pvha, mbx_cmd_t *mcp)
  30. {
  31. int rval;
  32. unsigned long flags = 0;
  33. device_reg_t __iomem *reg;
  34. uint8_t abort_active;
  35. uint8_t io_lock_on;
  36. uint16_t command;
  37. uint16_t *iptr;
  38. uint16_t __iomem *optr;
  39. uint32_t cnt;
  40. uint32_t mboxes;
  41. unsigned long wait_time;
  42. scsi_qla_host_t *ha = to_qla_parent(pvha);
  43. reg = ha->iobase;
  44. io_lock_on = ha->flags.init_done;
  45. rval = QLA_SUCCESS;
  46. abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  47. DEBUG11(printk("%s(%ld): entered.\n", __func__, pvha->host_no));
  48. /*
  49. * Wait for active mailbox commands to finish by waiting at most tov
  50. * seconds. This is to serialize actual issuing of mailbox cmds during
  51. * non ISP abort time.
  52. */
  53. if (!abort_active) {
  54. if (!wait_for_completion_timeout(&ha->mbx_cmd_comp,
  55. mcp->tov * HZ)) {
  56. /* Timeout occurred. Return error. */
  57. DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
  58. "Exiting.\n", __func__, ha->host_no));
  59. return QLA_FUNCTION_TIMEOUT;
  60. }
  61. }
  62. ha->flags.mbox_busy = 1;
  63. /* Save mailbox command for debug */
  64. ha->mcp = mcp;
  65. DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
  66. ha->host_no, mcp->mb[0]));
  67. spin_lock_irqsave(&ha->hardware_lock, flags);
  68. /* Load mailbox registers. */
  69. if (IS_FWI2_CAPABLE(ha))
  70. optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
  71. else
  72. optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
  73. iptr = mcp->mb;
  74. command = mcp->mb[0];
  75. mboxes = mcp->out_mb;
  76. for (cnt = 0; cnt < ha->mbx_count; cnt++) {
  77. if (IS_QLA2200(ha) && cnt == 8)
  78. optr =
  79. (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
  80. if (mboxes & BIT_0)
  81. WRT_REG_WORD(optr, *iptr);
  82. mboxes >>= 1;
  83. optr++;
  84. iptr++;
  85. }
  86. #if defined(QL_DEBUG_LEVEL_1)
  87. printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
  88. __func__, ha->host_no);
  89. qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
  90. printk("\n");
  91. qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
  92. printk("\n");
  93. qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
  94. printk("\n");
  95. printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
  96. qla2x00_dump_regs(ha);
  97. #endif
  98. /* Issue set host interrupt command to send cmd out. */
  99. ha->flags.mbox_int = 0;
  100. clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  101. /* Unlock mbx registers and wait for interrupt */
  102. DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
  103. "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
  104. /* Wait for mbx cmd completion until timeout */
  105. if (!abort_active && io_lock_on) {
  106. set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
  107. if (IS_FWI2_CAPABLE(ha))
  108. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
  109. else
  110. WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
  111. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  112. wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
  113. clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
  114. } else {
  115. DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
  116. ha->host_no, command));
  117. if (IS_FWI2_CAPABLE(ha))
  118. WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
  119. else
  120. WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
  121. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  122. wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
  123. while (!ha->flags.mbox_int) {
  124. if (time_after(jiffies, wait_time))
  125. break;
  126. /* Check for pending interrupts. */
  127. qla2x00_poll(ha);
  128. if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
  129. !ha->flags.mbox_int)
  130. msleep(10);
  131. } /* while */
  132. }
  133. /* Check whether we timed out */
  134. if (ha->flags.mbox_int) {
  135. uint16_t *iptr2;
  136. DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
  137. ha->host_no, command));
  138. /* Got interrupt. Clear the flag. */
  139. ha->flags.mbox_int = 0;
  140. clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
  141. if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
  142. rval = QLA_FUNCTION_FAILED;
  143. /* Load return mailbox registers. */
  144. iptr2 = mcp->mb;
  145. iptr = (uint16_t *)&ha->mailbox_out[0];
  146. mboxes = mcp->in_mb;
  147. for (cnt = 0; cnt < ha->mbx_count; cnt++) {
  148. if (mboxes & BIT_0)
  149. *iptr2 = *iptr;
  150. mboxes >>= 1;
  151. iptr2++;
  152. iptr++;
  153. }
  154. } else {
  155. #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
  156. defined(QL_DEBUG_LEVEL_11)
  157. uint16_t mb0;
  158. uint32_t ictrl;
  159. if (IS_FWI2_CAPABLE(ha)) {
  160. mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
  161. ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
  162. } else {
  163. mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
  164. ictrl = RD_REG_WORD(&reg->isp.ictrl);
  165. }
  166. printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
  167. __func__, ha->host_no, command);
  168. printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
  169. ha->host_no, ictrl, jiffies);
  170. printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
  171. ha->host_no, mb0);
  172. qla2x00_dump_regs(ha);
  173. #endif
  174. rval = QLA_FUNCTION_TIMEOUT;
  175. }
  176. ha->flags.mbox_busy = 0;
  177. /* Clean up */
  178. ha->mcp = NULL;
  179. if (abort_active || !io_lock_on) {
  180. DEBUG11(printk("%s(%ld): checking for additional resp "
  181. "interrupt.\n", __func__, ha->host_no));
  182. /* polling mode for non isp_abort commands. */
  183. qla2x00_poll(ha);
  184. }
  185. if (rval == QLA_FUNCTION_TIMEOUT &&
  186. mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
  187. if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
  188. /* not in dpc. schedule it for dpc to take over. */
  189. DEBUG(printk("%s(%ld): timeout schedule "
  190. "isp_abort_needed.\n", __func__, ha->host_no));
  191. DEBUG2_3_11(printk("%s(%ld): timeout schedule "
  192. "isp_abort_needed.\n", __func__, ha->host_no));
  193. qla_printk(KERN_WARNING, ha,
  194. "Mailbox command timeout occured. Scheduling ISP "
  195. "abort.\n");
  196. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  197. qla2xxx_wake_dpc(ha);
  198. } else if (!abort_active) {
  199. /* call abort directly since we are in the DPC thread */
  200. DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
  201. __func__, ha->host_no));
  202. DEBUG2_3_11(printk("%s(%ld): timeout calling "
  203. "abort_isp\n", __func__, ha->host_no));
  204. qla_printk(KERN_WARNING, ha,
  205. "Mailbox command timeout occured. Issuing ISP "
  206. "abort.\n");
  207. set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  208. clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  209. if (qla2x00_abort_isp(ha)) {
  210. /* Failed. retry later. */
  211. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  212. }
  213. clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
  214. DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
  215. ha->host_no));
  216. DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
  217. __func__, ha->host_no));
  218. }
  219. }
  220. /* Allow next mbx cmd to come in. */
  221. if (!abort_active)
  222. complete(&ha->mbx_cmd_comp);
  223. if (rval) {
  224. DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
  225. "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
  226. mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
  227. } else {
  228. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  229. }
  230. return rval;
  231. }
  232. int
  233. qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
  234. uint32_t risc_code_size)
  235. {
  236. int rval;
  237. mbx_cmd_t mc;
  238. mbx_cmd_t *mcp = &mc;
  239. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  240. if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
  241. mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
  242. mcp->mb[8] = MSW(risc_addr);
  243. mcp->out_mb = MBX_8|MBX_0;
  244. } else {
  245. mcp->mb[0] = MBC_LOAD_RISC_RAM;
  246. mcp->out_mb = MBX_0;
  247. }
  248. mcp->mb[1] = LSW(risc_addr);
  249. mcp->mb[2] = MSW(req_dma);
  250. mcp->mb[3] = LSW(req_dma);
  251. mcp->mb[6] = MSW(MSD(req_dma));
  252. mcp->mb[7] = LSW(MSD(req_dma));
  253. mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
  254. if (IS_FWI2_CAPABLE(ha)) {
  255. mcp->mb[4] = MSW(risc_code_size);
  256. mcp->mb[5] = LSW(risc_code_size);
  257. mcp->out_mb |= MBX_5|MBX_4;
  258. } else {
  259. mcp->mb[4] = LSW(risc_code_size);
  260. mcp->out_mb |= MBX_4;
  261. }
  262. mcp->in_mb = MBX_0;
  263. mcp->tov = 30;
  264. mcp->flags = 0;
  265. rval = qla2x00_mailbox_command(ha, mcp);
  266. if (rval != QLA_SUCCESS) {
  267. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  268. ha->host_no, rval, mcp->mb[0]));
  269. } else {
  270. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  271. }
  272. return rval;
  273. }
  274. /*
  275. * qla2x00_execute_fw
  276. * Start adapter firmware.
  277. *
  278. * Input:
  279. * ha = adapter block pointer.
  280. * TARGET_QUEUE_LOCK must be released.
  281. * ADAPTER_STATE_LOCK must be released.
  282. *
  283. * Returns:
  284. * qla2x00 local function return status code.
  285. *
  286. * Context:
  287. * Kernel context.
  288. */
  289. int
  290. qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
  291. {
  292. int rval;
  293. mbx_cmd_t mc;
  294. mbx_cmd_t *mcp = &mc;
  295. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  296. mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
  297. mcp->out_mb = MBX_0;
  298. mcp->in_mb = MBX_0;
  299. if (IS_FWI2_CAPABLE(ha)) {
  300. mcp->mb[1] = MSW(risc_addr);
  301. mcp->mb[2] = LSW(risc_addr);
  302. mcp->mb[3] = 0;
  303. mcp->mb[4] = 0;
  304. mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
  305. mcp->in_mb |= MBX_1;
  306. } else {
  307. mcp->mb[1] = LSW(risc_addr);
  308. mcp->out_mb |= MBX_1;
  309. if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
  310. mcp->mb[2] = 0;
  311. mcp->out_mb |= MBX_2;
  312. }
  313. }
  314. mcp->tov = 30;
  315. mcp->flags = 0;
  316. rval = qla2x00_mailbox_command(ha, mcp);
  317. if (rval != QLA_SUCCESS) {
  318. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  319. ha->host_no, rval, mcp->mb[0]));
  320. } else {
  321. if (IS_FWI2_CAPABLE(ha)) {
  322. DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
  323. __func__, ha->host_no, mcp->mb[1]));
  324. } else {
  325. DEBUG11(printk("%s(%ld): done.\n", __func__,
  326. ha->host_no));
  327. }
  328. }
  329. return rval;
  330. }
  331. /*
  332. * qla2x00_get_fw_version
  333. * Get firmware version.
  334. *
  335. * Input:
  336. * ha: adapter state pointer.
  337. * major: pointer for major number.
  338. * minor: pointer for minor number.
  339. * subminor: pointer for subminor number.
  340. *
  341. * Returns:
  342. * qla2x00 local function return status code.
  343. *
  344. * Context:
  345. * Kernel context.
  346. */
  347. void
  348. qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
  349. uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
  350. {
  351. int rval;
  352. mbx_cmd_t mc;
  353. mbx_cmd_t *mcp = &mc;
  354. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  355. mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
  356. mcp->out_mb = MBX_0;
  357. mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  358. mcp->flags = 0;
  359. mcp->tov = 30;
  360. rval = qla2x00_mailbox_command(ha, mcp);
  361. /* Return mailbox data. */
  362. *major = mcp->mb[1];
  363. *minor = mcp->mb[2];
  364. *subminor = mcp->mb[3];
  365. *attributes = mcp->mb[6];
  366. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  367. *memory = 0x1FFFF; /* Defaults to 128KB. */
  368. else
  369. *memory = (mcp->mb[5] << 16) | mcp->mb[4];
  370. if (rval != QLA_SUCCESS) {
  371. /*EMPTY*/
  372. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  373. ha->host_no, rval));
  374. } else {
  375. /*EMPTY*/
  376. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  377. }
  378. }
  379. /*
  380. * qla2x00_get_fw_options
  381. * Set firmware options.
  382. *
  383. * Input:
  384. * ha = adapter block pointer.
  385. * fwopt = pointer for firmware options.
  386. *
  387. * Returns:
  388. * qla2x00 local function return status code.
  389. *
  390. * Context:
  391. * Kernel context.
  392. */
  393. int
  394. qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
  395. {
  396. int rval;
  397. mbx_cmd_t mc;
  398. mbx_cmd_t *mcp = &mc;
  399. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  400. mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
  401. mcp->out_mb = MBX_0;
  402. mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  403. mcp->tov = 30;
  404. mcp->flags = 0;
  405. rval = qla2x00_mailbox_command(ha, mcp);
  406. if (rval != QLA_SUCCESS) {
  407. /*EMPTY*/
  408. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  409. ha->host_no, rval));
  410. } else {
  411. fwopts[0] = mcp->mb[0];
  412. fwopts[1] = mcp->mb[1];
  413. fwopts[2] = mcp->mb[2];
  414. fwopts[3] = mcp->mb[3];
  415. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  416. }
  417. return rval;
  418. }
  419. /*
  420. * qla2x00_set_fw_options
  421. * Set firmware options.
  422. *
  423. * Input:
  424. * ha = adapter block pointer.
  425. * fwopt = pointer for firmware options.
  426. *
  427. * Returns:
  428. * qla2x00 local function return status code.
  429. *
  430. * Context:
  431. * Kernel context.
  432. */
  433. int
  434. qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
  435. {
  436. int rval;
  437. mbx_cmd_t mc;
  438. mbx_cmd_t *mcp = &mc;
  439. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  440. mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
  441. mcp->mb[1] = fwopts[1];
  442. mcp->mb[2] = fwopts[2];
  443. mcp->mb[3] = fwopts[3];
  444. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  445. mcp->in_mb = MBX_0;
  446. if (IS_FWI2_CAPABLE(ha)) {
  447. mcp->in_mb |= MBX_1;
  448. } else {
  449. mcp->mb[10] = fwopts[10];
  450. mcp->mb[11] = fwopts[11];
  451. mcp->mb[12] = 0; /* Undocumented, but used */
  452. mcp->out_mb |= MBX_12|MBX_11|MBX_10;
  453. }
  454. mcp->tov = 30;
  455. mcp->flags = 0;
  456. rval = qla2x00_mailbox_command(ha, mcp);
  457. fwopts[0] = mcp->mb[0];
  458. if (rval != QLA_SUCCESS) {
  459. /*EMPTY*/
  460. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
  461. ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  462. } else {
  463. /*EMPTY*/
  464. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  465. }
  466. return rval;
  467. }
  468. /*
  469. * qla2x00_mbx_reg_test
  470. * Mailbox register wrap test.
  471. *
  472. * Input:
  473. * ha = adapter block pointer.
  474. * TARGET_QUEUE_LOCK must be released.
  475. * ADAPTER_STATE_LOCK must be released.
  476. *
  477. * Returns:
  478. * qla2x00 local function return status code.
  479. *
  480. * Context:
  481. * Kernel context.
  482. */
  483. int
  484. qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
  485. {
  486. int rval;
  487. mbx_cmd_t mc;
  488. mbx_cmd_t *mcp = &mc;
  489. DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
  490. mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
  491. mcp->mb[1] = 0xAAAA;
  492. mcp->mb[2] = 0x5555;
  493. mcp->mb[3] = 0xAA55;
  494. mcp->mb[4] = 0x55AA;
  495. mcp->mb[5] = 0xA5A5;
  496. mcp->mb[6] = 0x5A5A;
  497. mcp->mb[7] = 0x2525;
  498. mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  499. mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  500. mcp->tov = 30;
  501. mcp->flags = 0;
  502. rval = qla2x00_mailbox_command(ha, mcp);
  503. if (rval == QLA_SUCCESS) {
  504. if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
  505. mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
  506. rval = QLA_FUNCTION_FAILED;
  507. if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
  508. mcp->mb[7] != 0x2525)
  509. rval = QLA_FUNCTION_FAILED;
  510. }
  511. if (rval != QLA_SUCCESS) {
  512. /*EMPTY*/
  513. DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
  514. ha->host_no, rval));
  515. } else {
  516. /*EMPTY*/
  517. DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
  518. ha->host_no));
  519. }
  520. return rval;
  521. }
  522. /*
  523. * qla2x00_verify_checksum
  524. * Verify firmware checksum.
  525. *
  526. * Input:
  527. * ha = adapter block pointer.
  528. * TARGET_QUEUE_LOCK must be released.
  529. * ADAPTER_STATE_LOCK must be released.
  530. *
  531. * Returns:
  532. * qla2x00 local function return status code.
  533. *
  534. * Context:
  535. * Kernel context.
  536. */
  537. int
  538. qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
  539. {
  540. int rval;
  541. mbx_cmd_t mc;
  542. mbx_cmd_t *mcp = &mc;
  543. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  544. mcp->mb[0] = MBC_VERIFY_CHECKSUM;
  545. mcp->out_mb = MBX_0;
  546. mcp->in_mb = MBX_0;
  547. if (IS_FWI2_CAPABLE(ha)) {
  548. mcp->mb[1] = MSW(risc_addr);
  549. mcp->mb[2] = LSW(risc_addr);
  550. mcp->out_mb |= MBX_2|MBX_1;
  551. mcp->in_mb |= MBX_2|MBX_1;
  552. } else {
  553. mcp->mb[1] = LSW(risc_addr);
  554. mcp->out_mb |= MBX_1;
  555. mcp->in_mb |= MBX_1;
  556. }
  557. mcp->tov = 30;
  558. mcp->flags = 0;
  559. rval = qla2x00_mailbox_command(ha, mcp);
  560. if (rval != QLA_SUCCESS) {
  561. DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
  562. ha->host_no, rval, IS_FWI2_CAPABLE(ha) ?
  563. (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
  564. } else {
  565. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  566. }
  567. return rval;
  568. }
  569. /*
  570. * qla2x00_issue_iocb
  571. * Issue IOCB using mailbox command
  572. *
  573. * Input:
  574. * ha = adapter state pointer.
  575. * buffer = buffer pointer.
  576. * phys_addr = physical address of buffer.
  577. * size = size of buffer.
  578. * TARGET_QUEUE_LOCK must be released.
  579. * ADAPTER_STATE_LOCK must be released.
  580. *
  581. * Returns:
  582. * qla2x00 local function return status code.
  583. *
  584. * Context:
  585. * Kernel context.
  586. */
  587. int
  588. qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
  589. size_t size)
  590. {
  591. int rval;
  592. mbx_cmd_t mc;
  593. mbx_cmd_t *mcp = &mc;
  594. mcp->mb[0] = MBC_IOCB_COMMAND_A64;
  595. mcp->mb[1] = 0;
  596. mcp->mb[2] = MSW(phys_addr);
  597. mcp->mb[3] = LSW(phys_addr);
  598. mcp->mb[6] = MSW(MSD(phys_addr));
  599. mcp->mb[7] = LSW(MSD(phys_addr));
  600. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  601. mcp->in_mb = MBX_2|MBX_0;
  602. mcp->tov = 30;
  603. mcp->flags = 0;
  604. rval = qla2x00_mailbox_command(ha, mcp);
  605. if (rval != QLA_SUCCESS) {
  606. /*EMPTY*/
  607. DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
  608. ha->host_no, rval));
  609. DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
  610. ha->host_no, rval));
  611. } else {
  612. sts_entry_t *sts_entry = (sts_entry_t *) buffer;
  613. /* Mask reserved bits. */
  614. sts_entry->entry_status &=
  615. IS_FWI2_CAPABLE(ha) ? RF_MASK_24XX :RF_MASK;
  616. }
  617. return rval;
  618. }
  619. /*
  620. * qla2x00_abort_command
  621. * Abort command aborts a specified IOCB.
  622. *
  623. * Input:
  624. * ha = adapter block pointer.
  625. * sp = SB structure pointer.
  626. *
  627. * Returns:
  628. * qla2x00 local function return status code.
  629. *
  630. * Context:
  631. * Kernel context.
  632. */
  633. int
  634. qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
  635. {
  636. unsigned long flags = 0;
  637. fc_port_t *fcport;
  638. int rval;
  639. uint32_t handle;
  640. mbx_cmd_t mc;
  641. mbx_cmd_t *mcp = &mc;
  642. DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
  643. fcport = sp->fcport;
  644. spin_lock_irqsave(&ha->hardware_lock, flags);
  645. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  646. if (ha->outstanding_cmds[handle] == sp)
  647. break;
  648. }
  649. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  650. if (handle == MAX_OUTSTANDING_COMMANDS) {
  651. /* command not found */
  652. return QLA_FUNCTION_FAILED;
  653. }
  654. mcp->mb[0] = MBC_ABORT_COMMAND;
  655. if (HAS_EXTENDED_IDS(ha))
  656. mcp->mb[1] = fcport->loop_id;
  657. else
  658. mcp->mb[1] = fcport->loop_id << 8;
  659. mcp->mb[2] = (uint16_t)handle;
  660. mcp->mb[3] = (uint16_t)(handle >> 16);
  661. mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
  662. mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  663. mcp->in_mb = MBX_0;
  664. mcp->tov = 30;
  665. mcp->flags = 0;
  666. rval = qla2x00_mailbox_command(ha, mcp);
  667. if (rval != QLA_SUCCESS) {
  668. DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
  669. ha->host_no, rval));
  670. } else {
  671. sp->flags |= SRB_ABORT_PENDING;
  672. DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
  673. ha->host_no));
  674. }
  675. return rval;
  676. }
  677. #if USE_ABORT_TGT
  678. /*
  679. * qla2x00_abort_target
  680. * Issue abort target mailbox command.
  681. *
  682. * Input:
  683. * ha = adapter block pointer.
  684. *
  685. * Returns:
  686. * qla2x00 local function return status code.
  687. *
  688. * Context:
  689. * Kernel context.
  690. */
  691. int
  692. qla2x00_abort_target(fc_port_t *fcport)
  693. {
  694. int rval;
  695. mbx_cmd_t mc;
  696. mbx_cmd_t *mcp = &mc;
  697. scsi_qla_host_t *ha;
  698. if (fcport == NULL)
  699. return 0;
  700. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
  701. ha = fcport->ha;
  702. mcp->mb[0] = MBC_ABORT_TARGET;
  703. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  704. if (HAS_EXTENDED_IDS(ha)) {
  705. mcp->mb[1] = fcport->loop_id;
  706. mcp->mb[10] = 0;
  707. mcp->out_mb |= MBX_10;
  708. } else {
  709. mcp->mb[1] = fcport->loop_id << 8;
  710. }
  711. mcp->mb[2] = ha->loop_reset_delay;
  712. mcp->in_mb = MBX_0;
  713. mcp->tov = 30;
  714. mcp->flags = 0;
  715. rval = qla2x00_mailbox_command(ha, mcp);
  716. /* Issue marker command. */
  717. ha->marker_needed = 1;
  718. if (rval != QLA_SUCCESS) {
  719. DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
  720. ha->host_no, rval));
  721. } else {
  722. /*EMPTY*/
  723. DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
  724. ha->host_no));
  725. }
  726. return rval;
  727. }
  728. #endif
  729. /*
  730. * qla2x00_get_adapter_id
  731. * Get adapter ID and topology.
  732. *
  733. * Input:
  734. * ha = adapter block pointer.
  735. * id = pointer for loop ID.
  736. * al_pa = pointer for AL_PA.
  737. * area = pointer for area.
  738. * domain = pointer for domain.
  739. * top = pointer for topology.
  740. * TARGET_QUEUE_LOCK must be released.
  741. * ADAPTER_STATE_LOCK must be released.
  742. *
  743. * Returns:
  744. * qla2x00 local function return status code.
  745. *
  746. * Context:
  747. * Kernel context.
  748. */
  749. int
  750. qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
  751. uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
  752. {
  753. int rval;
  754. mbx_cmd_t mc;
  755. mbx_cmd_t *mcp = &mc;
  756. DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
  757. ha->host_no));
  758. mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
  759. mcp->mb[9] = ha->vp_idx;
  760. mcp->out_mb = MBX_9|MBX_0;
  761. mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  762. mcp->tov = 30;
  763. mcp->flags = 0;
  764. rval = qla2x00_mailbox_command(ha, mcp);
  765. if (mcp->mb[0] == MBS_COMMAND_ERROR)
  766. rval = QLA_COMMAND_ERROR;
  767. /* Return data. */
  768. *id = mcp->mb[1];
  769. *al_pa = LSB(mcp->mb[2]);
  770. *area = MSB(mcp->mb[2]);
  771. *domain = LSB(mcp->mb[3]);
  772. *top = mcp->mb[6];
  773. *sw_cap = mcp->mb[7];
  774. if (rval != QLA_SUCCESS) {
  775. /*EMPTY*/
  776. DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
  777. ha->host_no, rval));
  778. } else {
  779. /*EMPTY*/
  780. DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
  781. ha->host_no));
  782. }
  783. return rval;
  784. }
  785. /*
  786. * qla2x00_get_retry_cnt
  787. * Get current firmware login retry count and delay.
  788. *
  789. * Input:
  790. * ha = adapter block pointer.
  791. * retry_cnt = pointer to login retry count.
  792. * tov = pointer to login timeout value.
  793. *
  794. * Returns:
  795. * qla2x00 local function return status code.
  796. *
  797. * Context:
  798. * Kernel context.
  799. */
  800. int
  801. qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
  802. uint16_t *r_a_tov)
  803. {
  804. int rval;
  805. uint16_t ratov;
  806. mbx_cmd_t mc;
  807. mbx_cmd_t *mcp = &mc;
  808. DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
  809. ha->host_no));
  810. mcp->mb[0] = MBC_GET_RETRY_COUNT;
  811. mcp->out_mb = MBX_0;
  812. mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  813. mcp->tov = 30;
  814. mcp->flags = 0;
  815. rval = qla2x00_mailbox_command(ha, mcp);
  816. if (rval != QLA_SUCCESS) {
  817. /*EMPTY*/
  818. DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
  819. ha->host_no, mcp->mb[0]));
  820. } else {
  821. /* Convert returned data and check our values. */
  822. *r_a_tov = mcp->mb[3] / 2;
  823. ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
  824. if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
  825. /* Update to the larger values */
  826. *retry_cnt = (uint8_t)mcp->mb[1];
  827. *tov = ratov;
  828. }
  829. DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
  830. "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
  831. }
  832. return rval;
  833. }
  834. /*
  835. * qla2x00_init_firmware
  836. * Initialize adapter firmware.
  837. *
  838. * Input:
  839. * ha = adapter block pointer.
  840. * dptr = Initialization control block pointer.
  841. * size = size of initialization control block.
  842. * TARGET_QUEUE_LOCK must be released.
  843. * ADAPTER_STATE_LOCK must be released.
  844. *
  845. * Returns:
  846. * qla2x00 local function return status code.
  847. *
  848. * Context:
  849. * Kernel context.
  850. */
  851. int
  852. qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
  853. {
  854. int rval;
  855. mbx_cmd_t mc;
  856. mbx_cmd_t *mcp = &mc;
  857. DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
  858. ha->host_no));
  859. if (ha->fw_attributes & BIT_2)
  860. mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
  861. else
  862. mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
  863. mcp->mb[2] = MSW(ha->init_cb_dma);
  864. mcp->mb[3] = LSW(ha->init_cb_dma);
  865. mcp->mb[4] = 0;
  866. mcp->mb[5] = 0;
  867. mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
  868. mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
  869. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  870. mcp->in_mb = MBX_5|MBX_4|MBX_0;
  871. mcp->buf_size = size;
  872. mcp->flags = MBX_DMA_OUT;
  873. mcp->tov = 30;
  874. rval = qla2x00_mailbox_command(ha, mcp);
  875. if (rval != QLA_SUCCESS) {
  876. /*EMPTY*/
  877. DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
  878. "mb0=%x.\n",
  879. ha->host_no, rval, mcp->mb[0]));
  880. } else {
  881. /*EMPTY*/
  882. DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
  883. ha->host_no));
  884. }
  885. return rval;
  886. }
  887. /*
  888. * qla2x00_get_port_database
  889. * Issue normal/enhanced get port database mailbox command
  890. * and copy device name as necessary.
  891. *
  892. * Input:
  893. * ha = adapter state pointer.
  894. * dev = structure pointer.
  895. * opt = enhanced cmd option byte.
  896. *
  897. * Returns:
  898. * qla2x00 local function return status code.
  899. *
  900. * Context:
  901. * Kernel context.
  902. */
  903. int
  904. qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
  905. {
  906. int rval;
  907. mbx_cmd_t mc;
  908. mbx_cmd_t *mcp = &mc;
  909. port_database_t *pd;
  910. struct port_database_24xx *pd24;
  911. dma_addr_t pd_dma;
  912. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  913. pd24 = NULL;
  914. pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
  915. if (pd == NULL) {
  916. DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
  917. "structure.\n", __func__, ha->host_no));
  918. return QLA_MEMORY_ALLOC_FAILED;
  919. }
  920. memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
  921. mcp->mb[0] = MBC_GET_PORT_DATABASE;
  922. if (opt != 0 && !IS_FWI2_CAPABLE(ha))
  923. mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
  924. mcp->mb[2] = MSW(pd_dma);
  925. mcp->mb[3] = LSW(pd_dma);
  926. mcp->mb[6] = MSW(MSD(pd_dma));
  927. mcp->mb[7] = LSW(MSD(pd_dma));
  928. mcp->mb[9] = ha->vp_idx;
  929. mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  930. mcp->in_mb = MBX_0;
  931. if (IS_FWI2_CAPABLE(ha)) {
  932. mcp->mb[1] = fcport->loop_id;
  933. mcp->mb[10] = opt;
  934. mcp->out_mb |= MBX_10|MBX_1;
  935. mcp->in_mb |= MBX_1;
  936. } else if (HAS_EXTENDED_IDS(ha)) {
  937. mcp->mb[1] = fcport->loop_id;
  938. mcp->mb[10] = opt;
  939. mcp->out_mb |= MBX_10|MBX_1;
  940. } else {
  941. mcp->mb[1] = fcport->loop_id << 8 | opt;
  942. mcp->out_mb |= MBX_1;
  943. }
  944. mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
  945. PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
  946. mcp->flags = MBX_DMA_IN;
  947. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  948. rval = qla2x00_mailbox_command(ha, mcp);
  949. if (rval != QLA_SUCCESS)
  950. goto gpd_error_out;
  951. if (IS_FWI2_CAPABLE(ha)) {
  952. pd24 = (struct port_database_24xx *) pd;
  953. /* Check for logged in state. */
  954. if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
  955. pd24->last_login_state != PDS_PRLI_COMPLETE) {
  956. DEBUG2(printk("%s(%ld): Unable to verify "
  957. "login-state (%x/%x) for loop_id %x\n",
  958. __func__, ha->host_no,
  959. pd24->current_login_state,
  960. pd24->last_login_state, fcport->loop_id));
  961. rval = QLA_FUNCTION_FAILED;
  962. goto gpd_error_out;
  963. }
  964. /* Names are little-endian. */
  965. memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
  966. memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
  967. /* Get port_id of device. */
  968. fcport->d_id.b.domain = pd24->port_id[0];
  969. fcport->d_id.b.area = pd24->port_id[1];
  970. fcport->d_id.b.al_pa = pd24->port_id[2];
  971. fcport->d_id.b.rsvd_1 = 0;
  972. /* If not target must be initiator or unknown type. */
  973. if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
  974. fcport->port_type = FCT_INITIATOR;
  975. else
  976. fcport->port_type = FCT_TARGET;
  977. } else {
  978. /* Check for logged in state. */
  979. if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
  980. pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
  981. rval = QLA_FUNCTION_FAILED;
  982. goto gpd_error_out;
  983. }
  984. /* Names are little-endian. */
  985. memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
  986. memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
  987. /* Get port_id of device. */
  988. fcport->d_id.b.domain = pd->port_id[0];
  989. fcport->d_id.b.area = pd->port_id[3];
  990. fcport->d_id.b.al_pa = pd->port_id[2];
  991. fcport->d_id.b.rsvd_1 = 0;
  992. /* Check for device require authentication. */
  993. pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
  994. (fcport->flags &= ~FCF_AUTH_REQ);
  995. /* If not target must be initiator or unknown type. */
  996. if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
  997. fcport->port_type = FCT_INITIATOR;
  998. else
  999. fcport->port_type = FCT_TARGET;
  1000. /* Passback COS information. */
  1001. fcport->supported_classes = (pd->options & BIT_4) ?
  1002. FC_COS_CLASS2: FC_COS_CLASS3;
  1003. }
  1004. gpd_error_out:
  1005. dma_pool_free(ha->s_dma_pool, pd, pd_dma);
  1006. if (rval != QLA_SUCCESS) {
  1007. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  1008. __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1009. } else {
  1010. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1011. }
  1012. return rval;
  1013. }
  1014. /*
  1015. * qla2x00_get_firmware_state
  1016. * Get adapter firmware state.
  1017. *
  1018. * Input:
  1019. * ha = adapter block pointer.
  1020. * dptr = pointer for firmware state.
  1021. * TARGET_QUEUE_LOCK must be released.
  1022. * ADAPTER_STATE_LOCK must be released.
  1023. *
  1024. * Returns:
  1025. * qla2x00 local function return status code.
  1026. *
  1027. * Context:
  1028. * Kernel context.
  1029. */
  1030. int
  1031. qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
  1032. {
  1033. int rval;
  1034. mbx_cmd_t mc;
  1035. mbx_cmd_t *mcp = &mc;
  1036. DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
  1037. ha->host_no));
  1038. mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
  1039. mcp->out_mb = MBX_0;
  1040. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  1041. mcp->tov = 30;
  1042. mcp->flags = 0;
  1043. rval = qla2x00_mailbox_command(ha, mcp);
  1044. /* Return firmware state. */
  1045. *dptr = mcp->mb[1];
  1046. if (rval != QLA_SUCCESS) {
  1047. /*EMPTY*/
  1048. DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
  1049. "failed=%x.\n", ha->host_no, rval));
  1050. } else {
  1051. /*EMPTY*/
  1052. DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
  1053. ha->host_no));
  1054. }
  1055. return rval;
  1056. }
  1057. /*
  1058. * qla2x00_get_port_name
  1059. * Issue get port name mailbox command.
  1060. * Returned name is in big endian format.
  1061. *
  1062. * Input:
  1063. * ha = adapter block pointer.
  1064. * loop_id = loop ID of device.
  1065. * name = pointer for name.
  1066. * TARGET_QUEUE_LOCK must be released.
  1067. * ADAPTER_STATE_LOCK must be released.
  1068. *
  1069. * Returns:
  1070. * qla2x00 local function return status code.
  1071. *
  1072. * Context:
  1073. * Kernel context.
  1074. */
  1075. int
  1076. qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
  1077. uint8_t opt)
  1078. {
  1079. int rval;
  1080. mbx_cmd_t mc;
  1081. mbx_cmd_t *mcp = &mc;
  1082. DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
  1083. ha->host_no));
  1084. mcp->mb[0] = MBC_GET_PORT_NAME;
  1085. mcp->mb[9] = ha->vp_idx;
  1086. mcp->out_mb = MBX_9|MBX_1|MBX_0;
  1087. if (HAS_EXTENDED_IDS(ha)) {
  1088. mcp->mb[1] = loop_id;
  1089. mcp->mb[10] = opt;
  1090. mcp->out_mb |= MBX_10;
  1091. } else {
  1092. mcp->mb[1] = loop_id << 8 | opt;
  1093. }
  1094. mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1095. mcp->tov = 30;
  1096. mcp->flags = 0;
  1097. rval = qla2x00_mailbox_command(ha, mcp);
  1098. if (rval != QLA_SUCCESS) {
  1099. /*EMPTY*/
  1100. DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
  1101. ha->host_no, rval));
  1102. } else {
  1103. if (name != NULL) {
  1104. /* This function returns name in big endian. */
  1105. name[0] = MSB(mcp->mb[2]);
  1106. name[1] = LSB(mcp->mb[2]);
  1107. name[2] = MSB(mcp->mb[3]);
  1108. name[3] = LSB(mcp->mb[3]);
  1109. name[4] = MSB(mcp->mb[6]);
  1110. name[5] = LSB(mcp->mb[6]);
  1111. name[6] = MSB(mcp->mb[7]);
  1112. name[7] = LSB(mcp->mb[7]);
  1113. }
  1114. DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
  1115. ha->host_no));
  1116. }
  1117. return rval;
  1118. }
  1119. /*
  1120. * qla2x00_lip_reset
  1121. * Issue LIP reset mailbox command.
  1122. *
  1123. * Input:
  1124. * ha = adapter block pointer.
  1125. * TARGET_QUEUE_LOCK must be released.
  1126. * ADAPTER_STATE_LOCK must be released.
  1127. *
  1128. * Returns:
  1129. * qla2x00 local function return status code.
  1130. *
  1131. * Context:
  1132. * Kernel context.
  1133. */
  1134. int
  1135. qla2x00_lip_reset(scsi_qla_host_t *ha)
  1136. {
  1137. int rval;
  1138. mbx_cmd_t mc;
  1139. mbx_cmd_t *mcp = &mc;
  1140. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1141. if (IS_FWI2_CAPABLE(ha)) {
  1142. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1143. mcp->mb[1] = BIT_6;
  1144. mcp->mb[2] = 0;
  1145. mcp->mb[3] = ha->loop_reset_delay;
  1146. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1147. } else {
  1148. mcp->mb[0] = MBC_LIP_RESET;
  1149. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1150. if (HAS_EXTENDED_IDS(ha)) {
  1151. mcp->mb[1] = 0x00ff;
  1152. mcp->mb[10] = 0;
  1153. mcp->out_mb |= MBX_10;
  1154. } else {
  1155. mcp->mb[1] = 0xff00;
  1156. }
  1157. mcp->mb[2] = ha->loop_reset_delay;
  1158. mcp->mb[3] = 0;
  1159. }
  1160. mcp->in_mb = MBX_0;
  1161. mcp->tov = 30;
  1162. mcp->flags = 0;
  1163. rval = qla2x00_mailbox_command(ha, mcp);
  1164. if (rval != QLA_SUCCESS) {
  1165. /*EMPTY*/
  1166. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
  1167. __func__, ha->host_no, rval));
  1168. } else {
  1169. /*EMPTY*/
  1170. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1171. }
  1172. return rval;
  1173. }
  1174. /*
  1175. * qla2x00_send_sns
  1176. * Send SNS command.
  1177. *
  1178. * Input:
  1179. * ha = adapter block pointer.
  1180. * sns = pointer for command.
  1181. * cmd_size = command size.
  1182. * buf_size = response/command size.
  1183. * TARGET_QUEUE_LOCK must be released.
  1184. * ADAPTER_STATE_LOCK must be released.
  1185. *
  1186. * Returns:
  1187. * qla2x00 local function return status code.
  1188. *
  1189. * Context:
  1190. * Kernel context.
  1191. */
  1192. int
  1193. qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
  1194. uint16_t cmd_size, size_t buf_size)
  1195. {
  1196. int rval;
  1197. mbx_cmd_t mc;
  1198. mbx_cmd_t *mcp = &mc;
  1199. DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
  1200. ha->host_no));
  1201. DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
  1202. "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
  1203. mcp->mb[0] = MBC_SEND_SNS_COMMAND;
  1204. mcp->mb[1] = cmd_size;
  1205. mcp->mb[2] = MSW(sns_phys_address);
  1206. mcp->mb[3] = LSW(sns_phys_address);
  1207. mcp->mb[6] = MSW(MSD(sns_phys_address));
  1208. mcp->mb[7] = LSW(MSD(sns_phys_address));
  1209. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1210. mcp->in_mb = MBX_0|MBX_1;
  1211. mcp->buf_size = buf_size;
  1212. mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
  1213. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1214. rval = qla2x00_mailbox_command(ha, mcp);
  1215. if (rval != QLA_SUCCESS) {
  1216. /*EMPTY*/
  1217. DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1218. "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1219. DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
  1220. "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  1221. } else {
  1222. /*EMPTY*/
  1223. DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
  1224. }
  1225. return rval;
  1226. }
  1227. int
  1228. qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1229. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1230. {
  1231. int rval;
  1232. struct logio_entry_24xx *lg;
  1233. dma_addr_t lg_dma;
  1234. uint32_t iop[2];
  1235. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1236. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1237. if (lg == NULL) {
  1238. DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
  1239. __func__, ha->host_no));
  1240. return QLA_MEMORY_ALLOC_FAILED;
  1241. }
  1242. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1243. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1244. lg->entry_count = 1;
  1245. lg->nport_handle = cpu_to_le16(loop_id);
  1246. lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
  1247. if (opt & BIT_0)
  1248. lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
  1249. if (opt & BIT_1)
  1250. lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
  1251. lg->port_id[0] = al_pa;
  1252. lg->port_id[1] = area;
  1253. lg->port_id[2] = domain;
  1254. lg->vp_index = cpu_to_le16(ha->vp_idx);
  1255. rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
  1256. if (rval != QLA_SUCCESS) {
  1257. DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
  1258. "(%x).\n", __func__, ha->host_no, rval));
  1259. } else if (lg->entry_status != 0) {
  1260. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1261. "-- error status (%x).\n", __func__, ha->host_no,
  1262. lg->entry_status));
  1263. rval = QLA_FUNCTION_FAILED;
  1264. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1265. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1266. iop[1] = le32_to_cpu(lg->io_parameter[1]);
  1267. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1268. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1269. ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
  1270. iop[1]));
  1271. switch (iop[0]) {
  1272. case LSC_SCODE_PORTID_USED:
  1273. mb[0] = MBS_PORT_ID_USED;
  1274. mb[1] = LSW(iop[1]);
  1275. break;
  1276. case LSC_SCODE_NPORT_USED:
  1277. mb[0] = MBS_LOOP_ID_USED;
  1278. break;
  1279. case LSC_SCODE_NOLINK:
  1280. case LSC_SCODE_NOIOCB:
  1281. case LSC_SCODE_NOXCB:
  1282. case LSC_SCODE_CMD_FAILED:
  1283. case LSC_SCODE_NOFABRIC:
  1284. case LSC_SCODE_FW_NOT_READY:
  1285. case LSC_SCODE_NOT_LOGGED_IN:
  1286. case LSC_SCODE_NOPCB:
  1287. case LSC_SCODE_ELS_REJECT:
  1288. case LSC_SCODE_CMD_PARAM_ERR:
  1289. case LSC_SCODE_NONPORT:
  1290. case LSC_SCODE_LOGGED_IN:
  1291. case LSC_SCODE_NOFLOGI_ACC:
  1292. default:
  1293. mb[0] = MBS_COMMAND_ERROR;
  1294. break;
  1295. }
  1296. } else {
  1297. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1298. iop[0] = le32_to_cpu(lg->io_parameter[0]);
  1299. mb[0] = MBS_COMMAND_COMPLETE;
  1300. mb[1] = 0;
  1301. if (iop[0] & BIT_4) {
  1302. if (iop[0] & BIT_8)
  1303. mb[1] |= BIT_1;
  1304. } else
  1305. mb[1] = BIT_0;
  1306. /* Passback COS information. */
  1307. mb[10] = 0;
  1308. if (lg->io_parameter[7] || lg->io_parameter[8])
  1309. mb[10] |= BIT_0; /* Class 2. */
  1310. if (lg->io_parameter[9] || lg->io_parameter[10])
  1311. mb[10] |= BIT_1; /* Class 3. */
  1312. }
  1313. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1314. return rval;
  1315. }
  1316. /*
  1317. * qla2x00_login_fabric
  1318. * Issue login fabric port mailbox command.
  1319. *
  1320. * Input:
  1321. * ha = adapter block pointer.
  1322. * loop_id = device loop ID.
  1323. * domain = device domain.
  1324. * area = device area.
  1325. * al_pa = device AL_PA.
  1326. * status = pointer for return status.
  1327. * opt = command options.
  1328. * TARGET_QUEUE_LOCK must be released.
  1329. * ADAPTER_STATE_LOCK must be released.
  1330. *
  1331. * Returns:
  1332. * qla2x00 local function return status code.
  1333. *
  1334. * Context:
  1335. * Kernel context.
  1336. */
  1337. int
  1338. qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1339. uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
  1340. {
  1341. int rval;
  1342. mbx_cmd_t mc;
  1343. mbx_cmd_t *mcp = &mc;
  1344. DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
  1345. mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
  1346. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1347. if (HAS_EXTENDED_IDS(ha)) {
  1348. mcp->mb[1] = loop_id;
  1349. mcp->mb[10] = opt;
  1350. mcp->out_mb |= MBX_10;
  1351. } else {
  1352. mcp->mb[1] = (loop_id << 8) | opt;
  1353. }
  1354. mcp->mb[2] = domain;
  1355. mcp->mb[3] = area << 8 | al_pa;
  1356. mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
  1357. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1358. mcp->flags = 0;
  1359. rval = qla2x00_mailbox_command(ha, mcp);
  1360. /* Return mailbox statuses. */
  1361. if (mb != NULL) {
  1362. mb[0] = mcp->mb[0];
  1363. mb[1] = mcp->mb[1];
  1364. mb[2] = mcp->mb[2];
  1365. mb[6] = mcp->mb[6];
  1366. mb[7] = mcp->mb[7];
  1367. /* COS retrieved from Get-Port-Database mailbox command. */
  1368. mb[10] = 0;
  1369. }
  1370. if (rval != QLA_SUCCESS) {
  1371. /* RLU tmp code: need to change main mailbox_command function to
  1372. * return ok even when the mailbox completion value is not
  1373. * SUCCESS. The caller needs to be responsible to interpret
  1374. * the return values of this mailbox command if we're not
  1375. * to change too much of the existing code.
  1376. */
  1377. if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
  1378. mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
  1379. mcp->mb[0] == 0x4006)
  1380. rval = QLA_SUCCESS;
  1381. /*EMPTY*/
  1382. DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
  1383. "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
  1384. mcp->mb[0], mcp->mb[1], mcp->mb[2]));
  1385. } else {
  1386. /*EMPTY*/
  1387. DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
  1388. ha->host_no));
  1389. }
  1390. return rval;
  1391. }
  1392. /*
  1393. * qla2x00_login_local_device
  1394. * Issue login loop port mailbox command.
  1395. *
  1396. * Input:
  1397. * ha = adapter block pointer.
  1398. * loop_id = device loop ID.
  1399. * opt = command options.
  1400. *
  1401. * Returns:
  1402. * Return status code.
  1403. *
  1404. * Context:
  1405. * Kernel context.
  1406. *
  1407. */
  1408. int
  1409. qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
  1410. uint16_t *mb_ret, uint8_t opt)
  1411. {
  1412. int rval;
  1413. mbx_cmd_t mc;
  1414. mbx_cmd_t *mcp = &mc;
  1415. if (IS_FWI2_CAPABLE(ha))
  1416. return qla24xx_login_fabric(ha, fcport->loop_id,
  1417. fcport->d_id.b.domain, fcport->d_id.b.area,
  1418. fcport->d_id.b.al_pa, mb_ret, opt);
  1419. DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1420. mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
  1421. if (HAS_EXTENDED_IDS(ha))
  1422. mcp->mb[1] = fcport->loop_id;
  1423. else
  1424. mcp->mb[1] = fcport->loop_id << 8;
  1425. mcp->mb[2] = opt;
  1426. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  1427. mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
  1428. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1429. mcp->flags = 0;
  1430. rval = qla2x00_mailbox_command(ha, mcp);
  1431. /* Return mailbox statuses. */
  1432. if (mb_ret != NULL) {
  1433. mb_ret[0] = mcp->mb[0];
  1434. mb_ret[1] = mcp->mb[1];
  1435. mb_ret[6] = mcp->mb[6];
  1436. mb_ret[7] = mcp->mb[7];
  1437. }
  1438. if (rval != QLA_SUCCESS) {
  1439. /* AV tmp code: need to change main mailbox_command function to
  1440. * return ok even when the mailbox completion value is not
  1441. * SUCCESS. The caller needs to be responsible to interpret
  1442. * the return values of this mailbox command if we're not
  1443. * to change too much of the existing code.
  1444. */
  1445. if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
  1446. rval = QLA_SUCCESS;
  1447. DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1448. "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
  1449. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
  1450. DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
  1451. "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
  1452. mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
  1453. } else {
  1454. /*EMPTY*/
  1455. DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1456. }
  1457. return (rval);
  1458. }
  1459. int
  1460. qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1461. uint8_t area, uint8_t al_pa)
  1462. {
  1463. int rval;
  1464. struct logio_entry_24xx *lg;
  1465. dma_addr_t lg_dma;
  1466. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1467. lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
  1468. if (lg == NULL) {
  1469. DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
  1470. __func__, ha->host_no));
  1471. return QLA_MEMORY_ALLOC_FAILED;
  1472. }
  1473. memset(lg, 0, sizeof(struct logio_entry_24xx));
  1474. lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
  1475. lg->entry_count = 1;
  1476. lg->nport_handle = cpu_to_le16(loop_id);
  1477. lg->control_flags =
  1478. __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
  1479. lg->port_id[0] = al_pa;
  1480. lg->port_id[1] = area;
  1481. lg->port_id[2] = domain;
  1482. lg->vp_index = cpu_to_le16(ha->vp_idx);
  1483. rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
  1484. if (rval != QLA_SUCCESS) {
  1485. DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
  1486. "(%x).\n", __func__, ha->host_no, rval));
  1487. } else if (lg->entry_status != 0) {
  1488. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1489. "-- error status (%x).\n", __func__, ha->host_no,
  1490. lg->entry_status));
  1491. rval = QLA_FUNCTION_FAILED;
  1492. } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  1493. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1494. "-- completion status (%x) ioparam=%x/%x.\n", __func__,
  1495. ha->host_no, le16_to_cpu(lg->comp_status),
  1496. le32_to_cpu(lg->io_parameter[0]),
  1497. le32_to_cpu(lg->io_parameter[1])));
  1498. } else {
  1499. /*EMPTY*/
  1500. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1501. }
  1502. dma_pool_free(ha->s_dma_pool, lg, lg_dma);
  1503. return rval;
  1504. }
  1505. /*
  1506. * qla2x00_fabric_logout
  1507. * Issue logout fabric port mailbox command.
  1508. *
  1509. * Input:
  1510. * ha = adapter block pointer.
  1511. * loop_id = device loop ID.
  1512. * TARGET_QUEUE_LOCK must be released.
  1513. * ADAPTER_STATE_LOCK must be released.
  1514. *
  1515. * Returns:
  1516. * qla2x00 local function return status code.
  1517. *
  1518. * Context:
  1519. * Kernel context.
  1520. */
  1521. int
  1522. qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
  1523. uint8_t area, uint8_t al_pa)
  1524. {
  1525. int rval;
  1526. mbx_cmd_t mc;
  1527. mbx_cmd_t *mcp = &mc;
  1528. DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
  1529. ha->host_no));
  1530. mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
  1531. mcp->out_mb = MBX_1|MBX_0;
  1532. if (HAS_EXTENDED_IDS(ha)) {
  1533. mcp->mb[1] = loop_id;
  1534. mcp->mb[10] = 0;
  1535. mcp->out_mb |= MBX_10;
  1536. } else {
  1537. mcp->mb[1] = loop_id << 8;
  1538. }
  1539. mcp->in_mb = MBX_1|MBX_0;
  1540. mcp->tov = 30;
  1541. mcp->flags = 0;
  1542. rval = qla2x00_mailbox_command(ha, mcp);
  1543. if (rval != QLA_SUCCESS) {
  1544. /*EMPTY*/
  1545. DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
  1546. "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
  1547. } else {
  1548. /*EMPTY*/
  1549. DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
  1550. ha->host_no));
  1551. }
  1552. return rval;
  1553. }
  1554. /*
  1555. * qla2x00_full_login_lip
  1556. * Issue full login LIP mailbox command.
  1557. *
  1558. * Input:
  1559. * ha = adapter block pointer.
  1560. * TARGET_QUEUE_LOCK must be released.
  1561. * ADAPTER_STATE_LOCK must be released.
  1562. *
  1563. * Returns:
  1564. * qla2x00 local function return status code.
  1565. *
  1566. * Context:
  1567. * Kernel context.
  1568. */
  1569. int
  1570. qla2x00_full_login_lip(scsi_qla_host_t *ha)
  1571. {
  1572. int rval;
  1573. mbx_cmd_t mc;
  1574. mbx_cmd_t *mcp = &mc;
  1575. DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
  1576. ha->host_no));
  1577. mcp->mb[0] = MBC_LIP_FULL_LOGIN;
  1578. mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
  1579. mcp->mb[2] = 0;
  1580. mcp->mb[3] = 0;
  1581. mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
  1582. mcp->in_mb = MBX_0;
  1583. mcp->tov = 30;
  1584. mcp->flags = 0;
  1585. rval = qla2x00_mailbox_command(ha, mcp);
  1586. if (rval != QLA_SUCCESS) {
  1587. /*EMPTY*/
  1588. DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
  1589. ha->host_no, rval));
  1590. } else {
  1591. /*EMPTY*/
  1592. DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
  1593. ha->host_no));
  1594. }
  1595. return rval;
  1596. }
  1597. /*
  1598. * qla2x00_get_id_list
  1599. *
  1600. * Input:
  1601. * ha = adapter block pointer.
  1602. *
  1603. * Returns:
  1604. * qla2x00 local function return status code.
  1605. *
  1606. * Context:
  1607. * Kernel context.
  1608. */
  1609. int
  1610. qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
  1611. uint16_t *entries)
  1612. {
  1613. int rval;
  1614. mbx_cmd_t mc;
  1615. mbx_cmd_t *mcp = &mc;
  1616. DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
  1617. ha->host_no));
  1618. if (id_list == NULL)
  1619. return QLA_FUNCTION_FAILED;
  1620. mcp->mb[0] = MBC_GET_ID_LIST;
  1621. mcp->out_mb = MBX_0;
  1622. if (IS_FWI2_CAPABLE(ha)) {
  1623. mcp->mb[2] = MSW(id_list_dma);
  1624. mcp->mb[3] = LSW(id_list_dma);
  1625. mcp->mb[6] = MSW(MSD(id_list_dma));
  1626. mcp->mb[7] = LSW(MSD(id_list_dma));
  1627. mcp->mb[8] = 0;
  1628. mcp->mb[9] = ha->vp_idx;
  1629. mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
  1630. } else {
  1631. mcp->mb[1] = MSW(id_list_dma);
  1632. mcp->mb[2] = LSW(id_list_dma);
  1633. mcp->mb[3] = MSW(MSD(id_list_dma));
  1634. mcp->mb[6] = LSW(MSD(id_list_dma));
  1635. mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
  1636. }
  1637. mcp->in_mb = MBX_1|MBX_0;
  1638. mcp->tov = 30;
  1639. mcp->flags = 0;
  1640. rval = qla2x00_mailbox_command(ha, mcp);
  1641. if (rval != QLA_SUCCESS) {
  1642. /*EMPTY*/
  1643. DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
  1644. ha->host_no, rval));
  1645. } else {
  1646. *entries = mcp->mb[1];
  1647. DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
  1648. ha->host_no));
  1649. }
  1650. return rval;
  1651. }
  1652. /*
  1653. * qla2x00_get_resource_cnts
  1654. * Get current firmware resource counts.
  1655. *
  1656. * Input:
  1657. * ha = adapter block pointer.
  1658. *
  1659. * Returns:
  1660. * qla2x00 local function return status code.
  1661. *
  1662. * Context:
  1663. * Kernel context.
  1664. */
  1665. int
  1666. qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
  1667. uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
  1668. uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
  1669. {
  1670. int rval;
  1671. mbx_cmd_t mc;
  1672. mbx_cmd_t *mcp = &mc;
  1673. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1674. mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
  1675. mcp->out_mb = MBX_0;
  1676. mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  1677. mcp->tov = 30;
  1678. mcp->flags = 0;
  1679. rval = qla2x00_mailbox_command(ha, mcp);
  1680. if (rval != QLA_SUCCESS) {
  1681. /*EMPTY*/
  1682. DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
  1683. ha->host_no, mcp->mb[0]));
  1684. } else {
  1685. DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
  1686. "mb7=%x mb10=%x mb11=%x.\n", __func__, ha->host_no,
  1687. mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
  1688. mcp->mb[10], mcp->mb[11]));
  1689. if (cur_xchg_cnt)
  1690. *cur_xchg_cnt = mcp->mb[3];
  1691. if (orig_xchg_cnt)
  1692. *orig_xchg_cnt = mcp->mb[6];
  1693. if (cur_iocb_cnt)
  1694. *cur_iocb_cnt = mcp->mb[7];
  1695. if (orig_iocb_cnt)
  1696. *orig_iocb_cnt = mcp->mb[10];
  1697. if (max_npiv_vports)
  1698. *max_npiv_vports = mcp->mb[11];
  1699. }
  1700. return (rval);
  1701. }
  1702. #if defined(QL_DEBUG_LEVEL_3)
  1703. /*
  1704. * qla2x00_get_fcal_position_map
  1705. * Get FCAL (LILP) position map using mailbox command
  1706. *
  1707. * Input:
  1708. * ha = adapter state pointer.
  1709. * pos_map = buffer pointer (can be NULL).
  1710. *
  1711. * Returns:
  1712. * qla2x00 local function return status code.
  1713. *
  1714. * Context:
  1715. * Kernel context.
  1716. */
  1717. int
  1718. qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
  1719. {
  1720. int rval;
  1721. mbx_cmd_t mc;
  1722. mbx_cmd_t *mcp = &mc;
  1723. char *pmap;
  1724. dma_addr_t pmap_dma;
  1725. pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
  1726. if (pmap == NULL) {
  1727. DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
  1728. __func__, ha->host_no));
  1729. return QLA_MEMORY_ALLOC_FAILED;
  1730. }
  1731. memset(pmap, 0, FCAL_MAP_SIZE);
  1732. mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
  1733. mcp->mb[2] = MSW(pmap_dma);
  1734. mcp->mb[3] = LSW(pmap_dma);
  1735. mcp->mb[6] = MSW(MSD(pmap_dma));
  1736. mcp->mb[7] = LSW(MSD(pmap_dma));
  1737. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1738. mcp->in_mb = MBX_1|MBX_0;
  1739. mcp->buf_size = FCAL_MAP_SIZE;
  1740. mcp->flags = MBX_DMA_IN;
  1741. mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
  1742. rval = qla2x00_mailbox_command(ha, mcp);
  1743. if (rval == QLA_SUCCESS) {
  1744. DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
  1745. "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
  1746. mcp->mb[1], (unsigned)pmap[0]));
  1747. DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
  1748. if (pos_map)
  1749. memcpy(pos_map, pmap, FCAL_MAP_SIZE);
  1750. }
  1751. dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
  1752. if (rval != QLA_SUCCESS) {
  1753. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1754. ha->host_no, rval));
  1755. } else {
  1756. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1757. }
  1758. return rval;
  1759. }
  1760. #endif
  1761. /*
  1762. * qla2x00_get_link_status
  1763. *
  1764. * Input:
  1765. * ha = adapter block pointer.
  1766. * loop_id = device loop ID.
  1767. * ret_buf = pointer to link status return buffer.
  1768. *
  1769. * Returns:
  1770. * 0 = success.
  1771. * BIT_0 = mem alloc error.
  1772. * BIT_1 = mailbox error.
  1773. */
  1774. int
  1775. qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
  1776. struct link_statistics *stats, dma_addr_t stats_dma)
  1777. {
  1778. int rval;
  1779. mbx_cmd_t mc;
  1780. mbx_cmd_t *mcp = &mc;
  1781. uint32_t *siter, *diter, dwords;
  1782. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1783. mcp->mb[0] = MBC_GET_LINK_STATUS;
  1784. mcp->mb[2] = MSW(stats_dma);
  1785. mcp->mb[3] = LSW(stats_dma);
  1786. mcp->mb[6] = MSW(MSD(stats_dma));
  1787. mcp->mb[7] = LSW(MSD(stats_dma));
  1788. mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1789. mcp->in_mb = MBX_0;
  1790. if (IS_FWI2_CAPABLE(ha)) {
  1791. mcp->mb[1] = loop_id;
  1792. mcp->mb[4] = 0;
  1793. mcp->mb[10] = 0;
  1794. mcp->out_mb |= MBX_10|MBX_4|MBX_1;
  1795. mcp->in_mb |= MBX_1;
  1796. } else if (HAS_EXTENDED_IDS(ha)) {
  1797. mcp->mb[1] = loop_id;
  1798. mcp->mb[10] = 0;
  1799. mcp->out_mb |= MBX_10|MBX_1;
  1800. } else {
  1801. mcp->mb[1] = loop_id << 8;
  1802. mcp->out_mb |= MBX_1;
  1803. }
  1804. mcp->tov = 30;
  1805. mcp->flags = IOCTL_CMD;
  1806. rval = qla2x00_mailbox_command(ha, mcp);
  1807. if (rval == QLA_SUCCESS) {
  1808. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  1809. DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
  1810. __func__, ha->host_no, mcp->mb[0]));
  1811. rval = QLA_FUNCTION_FAILED;
  1812. } else {
  1813. /* Copy over data -- firmware data is LE. */
  1814. dwords = offsetof(struct link_statistics, unused1) / 4;
  1815. siter = diter = &stats->link_fail_cnt;
  1816. while (dwords--)
  1817. *diter++ = le32_to_cpu(*siter++);
  1818. }
  1819. } else {
  1820. /* Failed. */
  1821. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1822. ha->host_no, rval));
  1823. }
  1824. return rval;
  1825. }
  1826. int
  1827. qla24xx_get_isp_stats(scsi_qla_host_t *ha, struct link_statistics *stats,
  1828. dma_addr_t stats_dma)
  1829. {
  1830. int rval;
  1831. mbx_cmd_t mc;
  1832. mbx_cmd_t *mcp = &mc;
  1833. uint32_t *siter, *diter, dwords;
  1834. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1835. mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
  1836. mcp->mb[2] = MSW(stats_dma);
  1837. mcp->mb[3] = LSW(stats_dma);
  1838. mcp->mb[6] = MSW(MSD(stats_dma));
  1839. mcp->mb[7] = LSW(MSD(stats_dma));
  1840. mcp->mb[8] = sizeof(struct link_statistics) / 4;
  1841. mcp->mb[9] = ha->vp_idx;
  1842. mcp->mb[10] = 0;
  1843. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
  1844. mcp->in_mb = MBX_2|MBX_1|MBX_0;
  1845. mcp->tov = 30;
  1846. mcp->flags = IOCTL_CMD;
  1847. rval = qla2x00_mailbox_command(ha, mcp);
  1848. if (rval == QLA_SUCCESS) {
  1849. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  1850. DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
  1851. __func__, ha->host_no, mcp->mb[0]));
  1852. rval = QLA_FUNCTION_FAILED;
  1853. } else {
  1854. /* Copy over data -- firmware data is LE. */
  1855. dwords = sizeof(struct link_statistics) / 4;
  1856. siter = diter = &stats->link_fail_cnt;
  1857. while (dwords--)
  1858. *diter++ = le32_to_cpu(*siter++);
  1859. }
  1860. } else {
  1861. /* Failed. */
  1862. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  1863. ha->host_no, rval));
  1864. }
  1865. return rval;
  1866. }
  1867. int
  1868. qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
  1869. {
  1870. int rval;
  1871. fc_port_t *fcport;
  1872. unsigned long flags = 0;
  1873. struct abort_entry_24xx *abt;
  1874. dma_addr_t abt_dma;
  1875. uint32_t handle;
  1876. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1877. fcport = sp->fcport;
  1878. spin_lock_irqsave(&ha->hardware_lock, flags);
  1879. for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
  1880. if (ha->outstanding_cmds[handle] == sp)
  1881. break;
  1882. }
  1883. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  1884. if (handle == MAX_OUTSTANDING_COMMANDS) {
  1885. /* Command not found. */
  1886. return QLA_FUNCTION_FAILED;
  1887. }
  1888. abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
  1889. if (abt == NULL) {
  1890. DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
  1891. __func__, ha->host_no));
  1892. return QLA_MEMORY_ALLOC_FAILED;
  1893. }
  1894. memset(abt, 0, sizeof(struct abort_entry_24xx));
  1895. abt->entry_type = ABORT_IOCB_TYPE;
  1896. abt->entry_count = 1;
  1897. abt->nport_handle = cpu_to_le16(fcport->loop_id);
  1898. abt->handle_to_abort = handle;
  1899. abt->port_id[0] = fcport->d_id.b.al_pa;
  1900. abt->port_id[1] = fcport->d_id.b.area;
  1901. abt->port_id[2] = fcport->d_id.b.domain;
  1902. abt->vp_index = fcport->vp_idx;
  1903. rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
  1904. if (rval != QLA_SUCCESS) {
  1905. DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
  1906. __func__, ha->host_no, rval));
  1907. } else if (abt->entry_status != 0) {
  1908. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1909. "-- error status (%x).\n", __func__, ha->host_no,
  1910. abt->entry_status));
  1911. rval = QLA_FUNCTION_FAILED;
  1912. } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
  1913. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1914. "-- completion status (%x).\n", __func__, ha->host_no,
  1915. le16_to_cpu(abt->nport_handle)));
  1916. rval = QLA_FUNCTION_FAILED;
  1917. } else {
  1918. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1919. sp->flags |= SRB_ABORT_PENDING;
  1920. }
  1921. dma_pool_free(ha->s_dma_pool, abt, abt_dma);
  1922. return rval;
  1923. }
  1924. struct tsk_mgmt_cmd {
  1925. union {
  1926. struct tsk_mgmt_entry tsk;
  1927. struct sts_entry_24xx sts;
  1928. } p;
  1929. };
  1930. int
  1931. qla24xx_abort_target(fc_port_t *fcport)
  1932. {
  1933. int rval;
  1934. struct tsk_mgmt_cmd *tsk;
  1935. dma_addr_t tsk_dma;
  1936. scsi_qla_host_t *ha, *pha;
  1937. if (fcport == NULL)
  1938. return 0;
  1939. DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
  1940. ha = fcport->ha;
  1941. pha = to_qla_parent(ha);
  1942. tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
  1943. if (tsk == NULL) {
  1944. DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
  1945. "IOCB.\n", __func__, ha->host_no));
  1946. return QLA_MEMORY_ALLOC_FAILED;
  1947. }
  1948. memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
  1949. tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
  1950. tsk->p.tsk.entry_count = 1;
  1951. tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
  1952. tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
  1953. tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
  1954. tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
  1955. tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
  1956. tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
  1957. tsk->p.tsk.vp_index = fcport->vp_idx;
  1958. rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
  1959. if (rval != QLA_SUCCESS) {
  1960. DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
  1961. "(%x).\n", __func__, ha->host_no, rval));
  1962. goto atarget_done;
  1963. } else if (tsk->p.sts.entry_status != 0) {
  1964. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1965. "-- error status (%x).\n", __func__, ha->host_no,
  1966. tsk->p.sts.entry_status));
  1967. rval = QLA_FUNCTION_FAILED;
  1968. goto atarget_done;
  1969. } else if (tsk->p.sts.comp_status !=
  1970. __constant_cpu_to_le16(CS_COMPLETE)) {
  1971. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  1972. "-- completion status (%x).\n", __func__,
  1973. ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
  1974. rval = QLA_FUNCTION_FAILED;
  1975. goto atarget_done;
  1976. }
  1977. /* Issue marker IOCB. */
  1978. rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
  1979. if (rval != QLA_SUCCESS) {
  1980. DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
  1981. "(%x).\n", __func__, ha->host_no, rval));
  1982. } else {
  1983. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  1984. }
  1985. atarget_done:
  1986. dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
  1987. return rval;
  1988. }
  1989. #if 0
  1990. int
  1991. qla2x00_system_error(scsi_qla_host_t *ha)
  1992. {
  1993. int rval;
  1994. mbx_cmd_t mc;
  1995. mbx_cmd_t *mcp = &mc;
  1996. if (!IS_FWI2_CAPABLE(ha))
  1997. return QLA_FUNCTION_FAILED;
  1998. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  1999. mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
  2000. mcp->out_mb = MBX_0;
  2001. mcp->in_mb = MBX_0;
  2002. mcp->tov = 5;
  2003. mcp->flags = 0;
  2004. rval = qla2x00_mailbox_command(ha, mcp);
  2005. if (rval != QLA_SUCCESS) {
  2006. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2007. ha->host_no, rval));
  2008. } else {
  2009. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2010. }
  2011. return rval;
  2012. }
  2013. #endif /* 0 */
  2014. /**
  2015. * qla2x00_set_serdes_params() -
  2016. * @ha: HA context
  2017. *
  2018. * Returns
  2019. */
  2020. int
  2021. qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
  2022. uint16_t sw_em_2g, uint16_t sw_em_4g)
  2023. {
  2024. int rval;
  2025. mbx_cmd_t mc;
  2026. mbx_cmd_t *mcp = &mc;
  2027. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2028. mcp->mb[0] = MBC_SERDES_PARAMS;
  2029. mcp->mb[1] = BIT_0;
  2030. mcp->mb[2] = sw_em_1g | BIT_15;
  2031. mcp->mb[3] = sw_em_2g | BIT_15;
  2032. mcp->mb[4] = sw_em_4g | BIT_15;
  2033. mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2034. mcp->in_mb = MBX_0;
  2035. mcp->tov = 30;
  2036. mcp->flags = 0;
  2037. rval = qla2x00_mailbox_command(ha, mcp);
  2038. if (rval != QLA_SUCCESS) {
  2039. /*EMPTY*/
  2040. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2041. ha->host_no, rval, mcp->mb[0]));
  2042. } else {
  2043. /*EMPTY*/
  2044. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2045. }
  2046. return rval;
  2047. }
  2048. int
  2049. qla2x00_stop_firmware(scsi_qla_host_t *ha)
  2050. {
  2051. int rval;
  2052. mbx_cmd_t mc;
  2053. mbx_cmd_t *mcp = &mc;
  2054. if (!IS_FWI2_CAPABLE(ha))
  2055. return QLA_FUNCTION_FAILED;
  2056. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2057. mcp->mb[0] = MBC_STOP_FIRMWARE;
  2058. mcp->out_mb = MBX_0;
  2059. mcp->in_mb = MBX_0;
  2060. mcp->tov = 5;
  2061. mcp->flags = 0;
  2062. rval = qla2x00_mailbox_command(ha, mcp);
  2063. if (rval != QLA_SUCCESS) {
  2064. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2065. ha->host_no, rval));
  2066. } else {
  2067. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2068. }
  2069. return rval;
  2070. }
  2071. int
  2072. qla2x00_enable_eft_trace(scsi_qla_host_t *ha, dma_addr_t eft_dma,
  2073. uint16_t buffers)
  2074. {
  2075. int rval;
  2076. mbx_cmd_t mc;
  2077. mbx_cmd_t *mcp = &mc;
  2078. if (!IS_FWI2_CAPABLE(ha))
  2079. return QLA_FUNCTION_FAILED;
  2080. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2081. mcp->mb[0] = MBC_TRACE_CONTROL;
  2082. mcp->mb[1] = TC_EFT_ENABLE;
  2083. mcp->mb[2] = LSW(eft_dma);
  2084. mcp->mb[3] = MSW(eft_dma);
  2085. mcp->mb[4] = LSW(MSD(eft_dma));
  2086. mcp->mb[5] = MSW(MSD(eft_dma));
  2087. mcp->mb[6] = buffers;
  2088. mcp->mb[7] = TC_AEN_DISABLE;
  2089. mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2090. mcp->in_mb = MBX_1|MBX_0;
  2091. mcp->tov = 30;
  2092. mcp->flags = 0;
  2093. rval = qla2x00_mailbox_command(ha, mcp);
  2094. if (rval != QLA_SUCCESS) {
  2095. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2096. __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2097. } else {
  2098. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2099. }
  2100. return rval;
  2101. }
  2102. int
  2103. qla2x00_disable_eft_trace(scsi_qla_host_t *ha)
  2104. {
  2105. int rval;
  2106. mbx_cmd_t mc;
  2107. mbx_cmd_t *mcp = &mc;
  2108. if (!IS_FWI2_CAPABLE(ha))
  2109. return QLA_FUNCTION_FAILED;
  2110. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2111. mcp->mb[0] = MBC_TRACE_CONTROL;
  2112. mcp->mb[1] = TC_EFT_DISABLE;
  2113. mcp->out_mb = MBX_1|MBX_0;
  2114. mcp->in_mb = MBX_1|MBX_0;
  2115. mcp->tov = 30;
  2116. mcp->flags = 0;
  2117. rval = qla2x00_mailbox_command(ha, mcp);
  2118. if (rval != QLA_SUCCESS) {
  2119. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2120. __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2121. } else {
  2122. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2123. }
  2124. return rval;
  2125. }
  2126. int
  2127. qla2x00_enable_fce_trace(scsi_qla_host_t *ha, dma_addr_t fce_dma,
  2128. uint16_t buffers, uint16_t *mb, uint32_t *dwords)
  2129. {
  2130. int rval;
  2131. mbx_cmd_t mc;
  2132. mbx_cmd_t *mcp = &mc;
  2133. if (!IS_QLA25XX(ha))
  2134. return QLA_FUNCTION_FAILED;
  2135. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2136. mcp->mb[0] = MBC_TRACE_CONTROL;
  2137. mcp->mb[1] = TC_FCE_ENABLE;
  2138. mcp->mb[2] = LSW(fce_dma);
  2139. mcp->mb[3] = MSW(fce_dma);
  2140. mcp->mb[4] = LSW(MSD(fce_dma));
  2141. mcp->mb[5] = MSW(MSD(fce_dma));
  2142. mcp->mb[6] = buffers;
  2143. mcp->mb[7] = TC_AEN_DISABLE;
  2144. mcp->mb[8] = 0;
  2145. mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
  2146. mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
  2147. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
  2148. MBX_1|MBX_0;
  2149. mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2150. mcp->tov = 30;
  2151. mcp->flags = 0;
  2152. rval = qla2x00_mailbox_command(ha, mcp);
  2153. if (rval != QLA_SUCCESS) {
  2154. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2155. __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2156. } else {
  2157. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2158. if (mb)
  2159. memcpy(mb, mcp->mb, 8 * sizeof(*mb));
  2160. if (dwords)
  2161. *dwords = mcp->mb[6];
  2162. }
  2163. return rval;
  2164. }
  2165. int
  2166. qla2x00_disable_fce_trace(scsi_qla_host_t *ha, uint64_t *wr, uint64_t *rd)
  2167. {
  2168. int rval;
  2169. mbx_cmd_t mc;
  2170. mbx_cmd_t *mcp = &mc;
  2171. if (!IS_FWI2_CAPABLE(ha))
  2172. return QLA_FUNCTION_FAILED;
  2173. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2174. mcp->mb[0] = MBC_TRACE_CONTROL;
  2175. mcp->mb[1] = TC_FCE_DISABLE;
  2176. mcp->mb[2] = TC_FCE_DISABLE_TRACE;
  2177. mcp->out_mb = MBX_2|MBX_1|MBX_0;
  2178. mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
  2179. MBX_1|MBX_0;
  2180. mcp->tov = 30;
  2181. mcp->flags = 0;
  2182. rval = qla2x00_mailbox_command(ha, mcp);
  2183. if (rval != QLA_SUCCESS) {
  2184. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
  2185. __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
  2186. } else {
  2187. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2188. if (wr)
  2189. *wr = (uint64_t) mcp->mb[5] << 48 |
  2190. (uint64_t) mcp->mb[4] << 32 |
  2191. (uint64_t) mcp->mb[3] << 16 |
  2192. (uint64_t) mcp->mb[2];
  2193. if (rd)
  2194. *rd = (uint64_t) mcp->mb[9] << 48 |
  2195. (uint64_t) mcp->mb[8] << 32 |
  2196. (uint64_t) mcp->mb[7] << 16 |
  2197. (uint64_t) mcp->mb[6];
  2198. }
  2199. return rval;
  2200. }
  2201. int
  2202. qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
  2203. uint16_t off, uint16_t count)
  2204. {
  2205. int rval;
  2206. mbx_cmd_t mc;
  2207. mbx_cmd_t *mcp = &mc;
  2208. if (!IS_FWI2_CAPABLE(ha))
  2209. return QLA_FUNCTION_FAILED;
  2210. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2211. mcp->mb[0] = MBC_READ_SFP;
  2212. mcp->mb[1] = addr;
  2213. mcp->mb[2] = MSW(sfp_dma);
  2214. mcp->mb[3] = LSW(sfp_dma);
  2215. mcp->mb[6] = MSW(MSD(sfp_dma));
  2216. mcp->mb[7] = LSW(MSD(sfp_dma));
  2217. mcp->mb[8] = count;
  2218. mcp->mb[9] = off;
  2219. mcp->mb[10] = 0;
  2220. mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
  2221. mcp->in_mb = MBX_0;
  2222. mcp->tov = 30;
  2223. mcp->flags = 0;
  2224. rval = qla2x00_mailbox_command(ha, mcp);
  2225. if (rval != QLA_SUCCESS) {
  2226. DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
  2227. ha->host_no, rval, mcp->mb[0]));
  2228. } else {
  2229. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2230. }
  2231. return rval;
  2232. }
  2233. int
  2234. qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
  2235. uint16_t port_speed, uint16_t *mb)
  2236. {
  2237. int rval;
  2238. mbx_cmd_t mc;
  2239. mbx_cmd_t *mcp = &mc;
  2240. if (!IS_IIDMA_CAPABLE(ha))
  2241. return QLA_FUNCTION_FAILED;
  2242. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2243. mcp->mb[0] = MBC_PORT_PARAMS;
  2244. mcp->mb[1] = loop_id;
  2245. mcp->mb[2] = BIT_0;
  2246. mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
  2247. mcp->mb[4] = mcp->mb[5] = 0;
  2248. mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
  2249. mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
  2250. mcp->tov = 30;
  2251. mcp->flags = 0;
  2252. rval = qla2x00_mailbox_command(ha, mcp);
  2253. /* Return mailbox statuses. */
  2254. if (mb != NULL) {
  2255. mb[0] = mcp->mb[0];
  2256. mb[1] = mcp->mb[1];
  2257. mb[3] = mcp->mb[3];
  2258. mb[4] = mcp->mb[4];
  2259. mb[5] = mcp->mb[5];
  2260. }
  2261. if (rval != QLA_SUCCESS) {
  2262. DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
  2263. ha->host_no, rval));
  2264. } else {
  2265. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2266. }
  2267. return rval;
  2268. }
  2269. void
  2270. qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
  2271. struct vp_rpt_id_entry_24xx *rptid_entry)
  2272. {
  2273. uint8_t vp_idx;
  2274. scsi_qla_host_t *vha;
  2275. if (rptid_entry->entry_status != 0)
  2276. return;
  2277. if (rptid_entry->entry_status != __constant_cpu_to_le16(CS_COMPLETE))
  2278. return;
  2279. if (rptid_entry->format == 0) {
  2280. DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
  2281. " number of VPs acquired %d\n", __func__, ha->host_no,
  2282. MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
  2283. DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
  2284. rptid_entry->port_id[2], rptid_entry->port_id[1],
  2285. rptid_entry->port_id[0]));
  2286. } else if (rptid_entry->format == 1) {
  2287. vp_idx = LSB(rptid_entry->vp_idx);
  2288. DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
  2289. "- status %d - "
  2290. "with port id %02x%02x%02x\n",__func__,ha->host_no,
  2291. vp_idx, MSB(rptid_entry->vp_idx),
  2292. rptid_entry->port_id[2], rptid_entry->port_id[1],
  2293. rptid_entry->port_id[0]));
  2294. if (vp_idx == 0)
  2295. return;
  2296. if (MSB(rptid_entry->vp_idx) == 1)
  2297. return;
  2298. list_for_each_entry(vha, &ha->vp_list, vp_list)
  2299. if (vp_idx == vha->vp_idx)
  2300. break;
  2301. if (!vha)
  2302. return;
  2303. vha->d_id.b.domain = rptid_entry->port_id[2];
  2304. vha->d_id.b.area = rptid_entry->port_id[1];
  2305. vha->d_id.b.al_pa = rptid_entry->port_id[0];
  2306. /*
  2307. * Cannot configure here as we are still sitting on the
  2308. * response queue. Handle it in dpc context.
  2309. */
  2310. set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
  2311. set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
  2312. wake_up_process(ha->dpc_thread);
  2313. }
  2314. }
  2315. /*
  2316. * qla24xx_modify_vp_config
  2317. * Change VP configuration for vha
  2318. *
  2319. * Input:
  2320. * vha = adapter block pointer.
  2321. *
  2322. * Returns:
  2323. * qla2xxx local function return status code.
  2324. *
  2325. * Context:
  2326. * Kernel context.
  2327. */
  2328. int
  2329. qla24xx_modify_vp_config(scsi_qla_host_t *vha)
  2330. {
  2331. int rval;
  2332. struct vp_config_entry_24xx *vpmod;
  2333. dma_addr_t vpmod_dma;
  2334. scsi_qla_host_t *pha;
  2335. /* This can be called by the parent */
  2336. pha = to_qla_parent(vha);
  2337. vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
  2338. if (!vpmod) {
  2339. DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
  2340. "IOCB.\n", __func__, pha->host_no));
  2341. return QLA_MEMORY_ALLOC_FAILED;
  2342. }
  2343. memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
  2344. vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
  2345. vpmod->entry_count = 1;
  2346. vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
  2347. vpmod->vp_count = 1;
  2348. vpmod->vp_index1 = vha->vp_idx;
  2349. vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
  2350. memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
  2351. memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
  2352. vpmod->entry_count = 1;
  2353. rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
  2354. if (rval != QLA_SUCCESS) {
  2355. DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
  2356. "(%x).\n", __func__, pha->host_no, rval));
  2357. } else if (vpmod->comp_status != 0) {
  2358. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2359. "-- error status (%x).\n", __func__, pha->host_no,
  2360. vpmod->comp_status));
  2361. rval = QLA_FUNCTION_FAILED;
  2362. } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  2363. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2364. "-- completion status (%x).\n", __func__, pha->host_no,
  2365. le16_to_cpu(vpmod->comp_status)));
  2366. rval = QLA_FUNCTION_FAILED;
  2367. } else {
  2368. /* EMPTY */
  2369. DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
  2370. fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
  2371. }
  2372. dma_pool_free(pha->s_dma_pool, vpmod, vpmod_dma);
  2373. return rval;
  2374. }
  2375. /*
  2376. * qla24xx_control_vp
  2377. * Enable a virtual port for given host
  2378. *
  2379. * Input:
  2380. * ha = adapter block pointer.
  2381. * vhba = virtual adapter (unused)
  2382. * index = index number for enabled VP
  2383. *
  2384. * Returns:
  2385. * qla2xxx local function return status code.
  2386. *
  2387. * Context:
  2388. * Kernel context.
  2389. */
  2390. int
  2391. qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
  2392. {
  2393. int rval;
  2394. int map, pos;
  2395. struct vp_ctrl_entry_24xx *vce;
  2396. dma_addr_t vce_dma;
  2397. scsi_qla_host_t *ha = vha->parent;
  2398. int vp_index = vha->vp_idx;
  2399. DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
  2400. ha->host_no, vp_index));
  2401. if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
  2402. return QLA_PARAMETER_ERROR;
  2403. vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
  2404. if (!vce) {
  2405. DEBUG2_3(printk("%s(%ld): "
  2406. "failed to allocate VP Control IOCB.\n", __func__,
  2407. ha->host_no));
  2408. return QLA_MEMORY_ALLOC_FAILED;
  2409. }
  2410. memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
  2411. vce->entry_type = VP_CTRL_IOCB_TYPE;
  2412. vce->entry_count = 1;
  2413. vce->command = cpu_to_le16(cmd);
  2414. vce->vp_count = __constant_cpu_to_le16(1);
  2415. /* index map in firmware starts with 1; decrement index
  2416. * this is ok as we never use index 0
  2417. */
  2418. map = (vp_index - 1) / 8;
  2419. pos = (vp_index - 1) & 7;
  2420. down(&ha->vport_sem);
  2421. vce->vp_idx_map[map] |= 1 << pos;
  2422. up(&ha->vport_sem);
  2423. rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
  2424. if (rval != QLA_SUCCESS) {
  2425. DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
  2426. "(%x).\n", __func__, ha->host_no, rval));
  2427. printk("%s(%ld): failed to issue VP control IOCB"
  2428. "(%x).\n", __func__, ha->host_no, rval);
  2429. } else if (vce->entry_status != 0) {
  2430. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2431. "-- error status (%x).\n", __func__, ha->host_no,
  2432. vce->entry_status));
  2433. printk("%s(%ld): failed to complete IOCB "
  2434. "-- error status (%x).\n", __func__, ha->host_no,
  2435. vce->entry_status);
  2436. rval = QLA_FUNCTION_FAILED;
  2437. } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
  2438. DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
  2439. "-- completion status (%x).\n", __func__, ha->host_no,
  2440. le16_to_cpu(vce->comp_status)));
  2441. printk("%s(%ld): failed to complete IOCB "
  2442. "-- completion status (%x).\n", __func__, ha->host_no,
  2443. le16_to_cpu(vce->comp_status));
  2444. rval = QLA_FUNCTION_FAILED;
  2445. } else {
  2446. DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2447. }
  2448. dma_pool_free(ha->s_dma_pool, vce, vce_dma);
  2449. return rval;
  2450. }
  2451. /*
  2452. * qla2x00_send_change_request
  2453. * Receive or disable RSCN request from fabric controller
  2454. *
  2455. * Input:
  2456. * ha = adapter block pointer
  2457. * format = registration format:
  2458. * 0 - Reserved
  2459. * 1 - Fabric detected registration
  2460. * 2 - N_port detected registration
  2461. * 3 - Full registration
  2462. * FF - clear registration
  2463. * vp_idx = Virtual port index
  2464. *
  2465. * Returns:
  2466. * qla2x00 local function return status code.
  2467. *
  2468. * Context:
  2469. * Kernel Context
  2470. */
  2471. int
  2472. qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
  2473. uint16_t vp_idx)
  2474. {
  2475. int rval;
  2476. mbx_cmd_t mc;
  2477. mbx_cmd_t *mcp = &mc;
  2478. /*
  2479. * This command is implicitly executed by firmware during login for the
  2480. * physical hosts
  2481. */
  2482. if (vp_idx == 0)
  2483. return QLA_FUNCTION_FAILED;
  2484. mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
  2485. mcp->mb[1] = format;
  2486. mcp->mb[9] = vp_idx;
  2487. mcp->out_mb = MBX_9|MBX_1|MBX_0;
  2488. mcp->in_mb = MBX_0|MBX_1;
  2489. mcp->tov = MBX_TOV_SECONDS;
  2490. mcp->flags = 0;
  2491. rval = qla2x00_mailbox_command(ha, mcp);
  2492. if (rval == QLA_SUCCESS) {
  2493. if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
  2494. rval = BIT_1;
  2495. }
  2496. } else
  2497. rval = BIT_1;
  2498. return rval;
  2499. }
  2500. int
  2501. qla2x00_dump_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t addr,
  2502. uint32_t size)
  2503. {
  2504. int rval;
  2505. mbx_cmd_t mc;
  2506. mbx_cmd_t *mcp = &mc;
  2507. DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2508. if (MSW(addr) || IS_FWI2_CAPABLE(ha)) {
  2509. mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
  2510. mcp->mb[8] = MSW(addr);
  2511. mcp->out_mb = MBX_8|MBX_0;
  2512. } else {
  2513. mcp->mb[0] = MBC_DUMP_RISC_RAM;
  2514. mcp->out_mb = MBX_0;
  2515. }
  2516. mcp->mb[1] = LSW(addr);
  2517. mcp->mb[2] = MSW(req_dma);
  2518. mcp->mb[3] = LSW(req_dma);
  2519. mcp->mb[6] = MSW(MSD(req_dma));
  2520. mcp->mb[7] = LSW(MSD(req_dma));
  2521. mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
  2522. if (IS_FWI2_CAPABLE(ha)) {
  2523. mcp->mb[4] = MSW(size);
  2524. mcp->mb[5] = LSW(size);
  2525. mcp->out_mb |= MBX_5|MBX_4;
  2526. } else {
  2527. mcp->mb[4] = LSW(size);
  2528. mcp->out_mb |= MBX_4;
  2529. }
  2530. mcp->in_mb = MBX_0;
  2531. mcp->tov = 30;
  2532. mcp->flags = 0;
  2533. rval = qla2x00_mailbox_command(ha, mcp);
  2534. if (rval != QLA_SUCCESS) {
  2535. DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
  2536. ha->host_no, rval, mcp->mb[0]));
  2537. } else {
  2538. DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
  2539. }
  2540. return rval;
  2541. }