qla_mbx.c 72 KB

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