qla_mbx.c 64 KB

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