qla_mbx.c 60 KB

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