qla_mbx.c 59 KB

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