lpfc_init.c 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/blkdev.h>
  22. #include <linux/delay.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/idr.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kthread.h>
  27. #include <linux/pci.h>
  28. #include <linux/spinlock.h>
  29. #include <linux/ctype.h>
  30. #include <scsi/scsi.h>
  31. #include <scsi/scsi_device.h>
  32. #include <scsi/scsi_host.h>
  33. #include <scsi/scsi_transport_fc.h>
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_disc.h"
  37. #include "lpfc_scsi.h"
  38. #include "lpfc.h"
  39. #include "lpfc_logmsg.h"
  40. #include "lpfc_crtn.h"
  41. #include "lpfc_vport.h"
  42. #include "lpfc_version.h"
  43. static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
  44. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  45. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  46. static struct scsi_transport_template *lpfc_transport_template = NULL;
  47. static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
  48. static DEFINE_IDR(lpfc_hba_index);
  49. /************************************************************************/
  50. /* */
  51. /* lpfc_config_port_prep */
  52. /* This routine will do LPFC initialization prior to the */
  53. /* CONFIG_PORT mailbox command. This will be initialized */
  54. /* as a SLI layer callback routine. */
  55. /* This routine returns 0 on success or -ERESTART if it wants */
  56. /* the SLI layer to reset the HBA and try again. Any */
  57. /* other return value indicates an error. */
  58. /* */
  59. /************************************************************************/
  60. int
  61. lpfc_config_port_prep(struct lpfc_hba *phba)
  62. {
  63. lpfc_vpd_t *vp = &phba->vpd;
  64. int i = 0, rc;
  65. LPFC_MBOXQ_t *pmb;
  66. MAILBOX_t *mb;
  67. char *lpfc_vpd_data = NULL;
  68. uint16_t offset = 0;
  69. static char licensed[56] =
  70. "key unlock for use with gnu public licensed code only\0";
  71. static int init_key = 1;
  72. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  73. if (!pmb) {
  74. phba->link_state = LPFC_HBA_ERROR;
  75. return -ENOMEM;
  76. }
  77. mb = &pmb->mb;
  78. phba->link_state = LPFC_INIT_MBX_CMDS;
  79. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  80. if (init_key) {
  81. uint32_t *ptext = (uint32_t *) licensed;
  82. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  83. *ptext = cpu_to_be32(*ptext);
  84. init_key = 0;
  85. }
  86. lpfc_read_nv(phba, pmb);
  87. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  88. sizeof (mb->un.varRDnvp.rsvd3));
  89. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  90. sizeof (licensed));
  91. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  92. if (rc != MBX_SUCCESS) {
  93. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  94. "0324 Config Port initialization "
  95. "error, mbxCmd x%x READ_NVPARM, "
  96. "mbxStatus x%x\n",
  97. mb->mbxCommand, mb->mbxStatus);
  98. mempool_free(pmb, phba->mbox_mem_pool);
  99. return -ERESTART;
  100. }
  101. memcpy(phba->wwnn, (char *)mb->un.varRDnvp.nodename,
  102. sizeof(phba->wwnn));
  103. memcpy(phba->wwpn, (char *)mb->un.varRDnvp.portname,
  104. sizeof(phba->wwpn));
  105. }
  106. phba->sli3_options = 0x0;
  107. /* Setup and issue mailbox READ REV command */
  108. lpfc_read_rev(phba, pmb);
  109. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  110. if (rc != MBX_SUCCESS) {
  111. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  112. "0439 Adapter failed to init, mbxCmd x%x "
  113. "READ_REV, mbxStatus x%x\n",
  114. mb->mbxCommand, mb->mbxStatus);
  115. mempool_free( pmb, phba->mbox_mem_pool);
  116. return -ERESTART;
  117. }
  118. /*
  119. * The value of rr must be 1 since the driver set the cv field to 1.
  120. * This setting requires the FW to set all revision fields.
  121. */
  122. if (mb->un.varRdRev.rr == 0) {
  123. vp->rev.rBit = 0;
  124. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  125. "0440 Adapter failed to init, READ_REV has "
  126. "missing revision information.\n");
  127. mempool_free(pmb, phba->mbox_mem_pool);
  128. return -ERESTART;
  129. }
  130. if (phba->sli_rev == 3 && !mb->un.varRdRev.v3rsp)
  131. return -EINVAL;
  132. /* Save information as VPD data */
  133. vp->rev.rBit = 1;
  134. memcpy(&vp->sli3Feat, &mb->un.varRdRev.sli3Feat, sizeof(uint32_t));
  135. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  136. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  137. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  138. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  139. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  140. vp->rev.smRev = mb->un.varRdRev.smRev;
  141. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  142. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  143. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  144. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  145. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  146. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  147. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  148. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  149. /* If the sli feature level is less then 9, we must
  150. * tear down all RPIs and VPIs on link down if NPIV
  151. * is enabled.
  152. */
  153. if (vp->rev.feaLevelHigh < 9)
  154. phba->sli3_options |= LPFC_SLI3_VPORT_TEARDOWN;
  155. if (lpfc_is_LC_HBA(phba->pcidev->device))
  156. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  157. sizeof (phba->RandomData));
  158. /* Get adapter VPD information */
  159. pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
  160. if (!pmb->context2)
  161. goto out_free_mbox;
  162. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  163. if (!lpfc_vpd_data)
  164. goto out_free_context2;
  165. do {
  166. lpfc_dump_mem(phba, pmb, offset);
  167. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  168. if (rc != MBX_SUCCESS) {
  169. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  170. "0441 VPD not present on adapter, "
  171. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  172. mb->mbxCommand, mb->mbxStatus);
  173. mb->un.varDmp.word_cnt = 0;
  174. }
  175. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  176. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  177. lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
  178. mb->un.varDmp.word_cnt);
  179. offset += mb->un.varDmp.word_cnt;
  180. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  181. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  182. kfree(lpfc_vpd_data);
  183. out_free_context2:
  184. kfree(pmb->context2);
  185. out_free_mbox:
  186. mempool_free(pmb, phba->mbox_mem_pool);
  187. return 0;
  188. }
  189. /* Completion handler for config async event mailbox command. */
  190. static void
  191. lpfc_config_async_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  192. {
  193. if (pmboxq->mb.mbxStatus == MBX_SUCCESS)
  194. phba->temp_sensor_support = 1;
  195. else
  196. phba->temp_sensor_support = 0;
  197. mempool_free(pmboxq, phba->mbox_mem_pool);
  198. return;
  199. }
  200. /************************************************************************/
  201. /* */
  202. /* lpfc_config_port_post */
  203. /* This routine will do LPFC initialization after the */
  204. /* CONFIG_PORT mailbox command. This will be initialized */
  205. /* as a SLI layer callback routine. */
  206. /* This routine returns 0 on success. Any other return value */
  207. /* indicates an error. */
  208. /* */
  209. /************************************************************************/
  210. int
  211. lpfc_config_port_post(struct lpfc_hba *phba)
  212. {
  213. struct lpfc_vport *vport = phba->pport;
  214. LPFC_MBOXQ_t *pmb;
  215. MAILBOX_t *mb;
  216. struct lpfc_dmabuf *mp;
  217. struct lpfc_sli *psli = &phba->sli;
  218. uint32_t status, timeout;
  219. int i, j;
  220. int rc;
  221. spin_lock_irq(&phba->hbalock);
  222. /*
  223. * If the Config port completed correctly the HBA is not
  224. * over heated any more.
  225. */
  226. if (phba->over_temp_state == HBA_OVER_TEMP)
  227. phba->over_temp_state = HBA_NORMAL_TEMP;
  228. spin_unlock_irq(&phba->hbalock);
  229. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  230. if (!pmb) {
  231. phba->link_state = LPFC_HBA_ERROR;
  232. return -ENOMEM;
  233. }
  234. mb = &pmb->mb;
  235. /* Get login parameters for NID. */
  236. lpfc_read_sparam(phba, pmb, 0);
  237. pmb->vport = vport;
  238. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  239. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  240. "0448 Adapter failed init, mbxCmd x%x "
  241. "READ_SPARM mbxStatus x%x\n",
  242. mb->mbxCommand, mb->mbxStatus);
  243. phba->link_state = LPFC_HBA_ERROR;
  244. mp = (struct lpfc_dmabuf *) pmb->context1;
  245. mempool_free( pmb, phba->mbox_mem_pool);
  246. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  247. kfree(mp);
  248. return -EIO;
  249. }
  250. mp = (struct lpfc_dmabuf *) pmb->context1;
  251. memcpy(&vport->fc_sparam, mp->virt, sizeof (struct serv_parm));
  252. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  253. kfree(mp);
  254. pmb->context1 = NULL;
  255. if (phba->cfg_soft_wwnn)
  256. u64_to_wwn(phba->cfg_soft_wwnn,
  257. vport->fc_sparam.nodeName.u.wwn);
  258. if (phba->cfg_soft_wwpn)
  259. u64_to_wwn(phba->cfg_soft_wwpn,
  260. vport->fc_sparam.portName.u.wwn);
  261. memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
  262. sizeof (struct lpfc_name));
  263. memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
  264. sizeof (struct lpfc_name));
  265. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  266. /* This should be consolidated into parse_vpd ? - mr */
  267. if (phba->SerialNumber[0] == 0) {
  268. uint8_t *outptr;
  269. outptr = &vport->fc_nodename.u.s.IEEE[0];
  270. for (i = 0; i < 12; i++) {
  271. status = *outptr++;
  272. j = ((status & 0xf0) >> 4);
  273. if (j <= 9)
  274. phba->SerialNumber[i] =
  275. (char)((uint8_t) 0x30 + (uint8_t) j);
  276. else
  277. phba->SerialNumber[i] =
  278. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  279. i++;
  280. j = (status & 0xf);
  281. if (j <= 9)
  282. phba->SerialNumber[i] =
  283. (char)((uint8_t) 0x30 + (uint8_t) j);
  284. else
  285. phba->SerialNumber[i] =
  286. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  287. }
  288. }
  289. lpfc_read_config(phba, pmb);
  290. pmb->vport = vport;
  291. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  292. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  293. "0453 Adapter failed to init, mbxCmd x%x "
  294. "READ_CONFIG, mbxStatus x%x\n",
  295. mb->mbxCommand, mb->mbxStatus);
  296. phba->link_state = LPFC_HBA_ERROR;
  297. mempool_free( pmb, phba->mbox_mem_pool);
  298. return -EIO;
  299. }
  300. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  301. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  302. phba->cfg_hba_queue_depth =
  303. mb->un.varRdConfig.max_xri + 1;
  304. phba->lmt = mb->un.varRdConfig.lmt;
  305. /* Get the default values for Model Name and Description */
  306. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  307. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  308. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  309. && !(phba->lmt & LMT_1Gb))
  310. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  311. && !(phba->lmt & LMT_2Gb))
  312. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  313. && !(phba->lmt & LMT_4Gb))
  314. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  315. && !(phba->lmt & LMT_8Gb))
  316. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  317. && !(phba->lmt & LMT_10Gb))) {
  318. /* Reset link speed to auto */
  319. lpfc_printf_log(phba, KERN_WARNING, LOG_LINK_EVENT,
  320. "1302 Invalid speed for this board: "
  321. "Reset link speed to auto: x%x\n",
  322. phba->cfg_link_speed);
  323. phba->cfg_link_speed = LINK_SPEED_AUTO;
  324. }
  325. phba->link_state = LPFC_LINK_DOWN;
  326. /* Only process IOCBs on ELS ring till hba_state is READY */
  327. if (psli->ring[psli->extra_ring].cmdringaddr)
  328. psli->ring[psli->extra_ring].flag |= LPFC_STOP_IOCB_EVENT;
  329. if (psli->ring[psli->fcp_ring].cmdringaddr)
  330. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  331. if (psli->ring[psli->next_ring].cmdringaddr)
  332. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  333. /* Post receive buffers for desired rings */
  334. if (phba->sli_rev != 3)
  335. lpfc_post_rcv_buf(phba);
  336. /* Enable appropriate host interrupts */
  337. spin_lock_irq(&phba->hbalock);
  338. status = readl(phba->HCregaddr);
  339. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  340. if (psli->num_rings > 0)
  341. status |= HC_R0INT_ENA;
  342. if (psli->num_rings > 1)
  343. status |= HC_R1INT_ENA;
  344. if (psli->num_rings > 2)
  345. status |= HC_R2INT_ENA;
  346. if (psli->num_rings > 3)
  347. status |= HC_R3INT_ENA;
  348. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  349. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  350. status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  351. writel(status, phba->HCregaddr);
  352. readl(phba->HCregaddr); /* flush */
  353. spin_unlock_irq(&phba->hbalock);
  354. /*
  355. * Setup the ring 0 (els) timeout handler
  356. */
  357. timeout = phba->fc_ratov << 1;
  358. mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
  359. mod_timer(&phba->hb_tmofunc, jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  360. phba->hb_outstanding = 0;
  361. phba->last_completion_time = jiffies;
  362. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  363. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  364. pmb->vport = vport;
  365. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  366. lpfc_set_loopback_flag(phba);
  367. if (rc != MBX_SUCCESS) {
  368. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  369. "0454 Adapter failed to init, mbxCmd x%x "
  370. "INIT_LINK, mbxStatus x%x\n",
  371. mb->mbxCommand, mb->mbxStatus);
  372. /* Clear all interrupt enable conditions */
  373. writel(0, phba->HCregaddr);
  374. readl(phba->HCregaddr); /* flush */
  375. /* Clear all pending interrupts */
  376. writel(0xffffffff, phba->HAregaddr);
  377. readl(phba->HAregaddr); /* flush */
  378. phba->link_state = LPFC_HBA_ERROR;
  379. if (rc != MBX_BUSY)
  380. mempool_free(pmb, phba->mbox_mem_pool);
  381. return -EIO;
  382. }
  383. /* MBOX buffer will be freed in mbox compl */
  384. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  385. lpfc_config_async(phba, pmb, LPFC_ELS_RING);
  386. pmb->mbox_cmpl = lpfc_config_async_cmpl;
  387. pmb->vport = phba->pport;
  388. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
  389. if ((rc != MBX_BUSY) && (rc != MBX_SUCCESS)) {
  390. lpfc_printf_log(phba,
  391. KERN_ERR,
  392. LOG_INIT,
  393. "0456 Adapter failed to issue "
  394. "ASYNCEVT_ENABLE mbox status x%x \n.",
  395. rc);
  396. mempool_free(pmb, phba->mbox_mem_pool);
  397. }
  398. return (0);
  399. }
  400. /************************************************************************/
  401. /* */
  402. /* lpfc_hba_down_prep */
  403. /* This routine will do LPFC uninitialization before the */
  404. /* HBA is reset when bringing down the SLI Layer. This will be */
  405. /* initialized as a SLI layer callback routine. */
  406. /* This routine returns 0 on success. Any other return value */
  407. /* indicates an error. */
  408. /* */
  409. /************************************************************************/
  410. int
  411. lpfc_hba_down_prep(struct lpfc_hba *phba)
  412. {
  413. struct lpfc_vport **vports;
  414. int i;
  415. /* Disable interrupts */
  416. writel(0, phba->HCregaddr);
  417. readl(phba->HCregaddr); /* flush */
  418. if (phba->pport->load_flag & FC_UNLOADING)
  419. lpfc_cleanup_discovery_resources(phba->pport);
  420. else {
  421. vports = lpfc_create_vport_work_array(phba);
  422. if (vports != NULL)
  423. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
  424. lpfc_cleanup_discovery_resources(vports[i]);
  425. lpfc_destroy_vport_work_array(phba, vports);
  426. } return 0;
  427. }
  428. /************************************************************************/
  429. /* */
  430. /* lpfc_hba_down_post */
  431. /* This routine will do uninitialization after the HBA is reset */
  432. /* when bringing down the SLI Layer. */
  433. /* This routine returns 0 on success. Any other return value */
  434. /* indicates an error. */
  435. /* */
  436. /************************************************************************/
  437. int
  438. lpfc_hba_down_post(struct lpfc_hba *phba)
  439. {
  440. struct lpfc_sli *psli = &phba->sli;
  441. struct lpfc_sli_ring *pring;
  442. struct lpfc_dmabuf *mp, *next_mp;
  443. struct lpfc_iocbq *iocb;
  444. IOCB_t *cmd = NULL;
  445. LIST_HEAD(completions);
  446. int i;
  447. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
  448. lpfc_sli_hbqbuf_free_all(phba);
  449. else {
  450. /* Cleanup preposted buffers on the ELS ring */
  451. pring = &psli->ring[LPFC_ELS_RING];
  452. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  453. list_del(&mp->list);
  454. pring->postbufq_cnt--;
  455. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  456. kfree(mp);
  457. }
  458. }
  459. spin_lock_irq(&phba->hbalock);
  460. for (i = 0; i < psli->num_rings; i++) {
  461. pring = &psli->ring[i];
  462. /* At this point in time the HBA is either reset or DOA. Either
  463. * way, nothing should be on txcmplq as it will NEVER complete.
  464. */
  465. list_splice_init(&pring->txcmplq, &completions);
  466. pring->txcmplq_cnt = 0;
  467. spin_unlock_irq(&phba->hbalock);
  468. while (!list_empty(&completions)) {
  469. iocb = list_get_first(&completions, struct lpfc_iocbq,
  470. list);
  471. cmd = &iocb->iocb;
  472. list_del_init(&iocb->list);
  473. if (!iocb->iocb_cmpl)
  474. lpfc_sli_release_iocbq(phba, iocb);
  475. else {
  476. cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
  477. cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
  478. (iocb->iocb_cmpl) (phba, iocb, iocb);
  479. }
  480. }
  481. lpfc_sli_abort_iocb_ring(phba, pring);
  482. spin_lock_irq(&phba->hbalock);
  483. }
  484. spin_unlock_irq(&phba->hbalock);
  485. return 0;
  486. }
  487. /* HBA heart beat timeout handler */
  488. static void
  489. lpfc_hb_timeout(unsigned long ptr)
  490. {
  491. struct lpfc_hba *phba;
  492. unsigned long iflag;
  493. phba = (struct lpfc_hba *)ptr;
  494. spin_lock_irqsave(&phba->pport->work_port_lock, iflag);
  495. if (!(phba->pport->work_port_events & WORKER_HB_TMO))
  496. phba->pport->work_port_events |= WORKER_HB_TMO;
  497. spin_unlock_irqrestore(&phba->pport->work_port_lock, iflag);
  498. if (phba->work_wait)
  499. wake_up(phba->work_wait);
  500. return;
  501. }
  502. static void
  503. lpfc_hb_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
  504. {
  505. unsigned long drvr_flag;
  506. spin_lock_irqsave(&phba->hbalock, drvr_flag);
  507. phba->hb_outstanding = 0;
  508. spin_unlock_irqrestore(&phba->hbalock, drvr_flag);
  509. mempool_free(pmboxq, phba->mbox_mem_pool);
  510. if (!(phba->pport->fc_flag & FC_OFFLINE_MODE) &&
  511. !(phba->link_state == LPFC_HBA_ERROR) &&
  512. !(phba->pport->load_flag & FC_UNLOADING))
  513. mod_timer(&phba->hb_tmofunc,
  514. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  515. return;
  516. }
  517. void
  518. lpfc_hb_timeout_handler(struct lpfc_hba *phba)
  519. {
  520. LPFC_MBOXQ_t *pmboxq;
  521. struct lpfc_dmabuf *buf_ptr;
  522. int retval;
  523. struct lpfc_sli *psli = &phba->sli;
  524. LIST_HEAD(completions);
  525. if ((phba->link_state == LPFC_HBA_ERROR) ||
  526. (phba->pport->load_flag & FC_UNLOADING) ||
  527. (phba->pport->fc_flag & FC_OFFLINE_MODE))
  528. return;
  529. spin_lock_irq(&phba->pport->work_port_lock);
  530. /* If the timer is already canceled do nothing */
  531. if (!(phba->pport->work_port_events & WORKER_HB_TMO)) {
  532. spin_unlock_irq(&phba->pport->work_port_lock);
  533. return;
  534. }
  535. if (time_after(phba->last_completion_time + LPFC_HB_MBOX_INTERVAL * HZ,
  536. jiffies)) {
  537. spin_unlock_irq(&phba->pport->work_port_lock);
  538. if (!phba->hb_outstanding)
  539. mod_timer(&phba->hb_tmofunc,
  540. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  541. else
  542. mod_timer(&phba->hb_tmofunc,
  543. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  544. return;
  545. }
  546. spin_unlock_irq(&phba->pport->work_port_lock);
  547. if (phba->elsbuf_cnt &&
  548. (phba->elsbuf_cnt == phba->elsbuf_prev_cnt)) {
  549. spin_lock_irq(&phba->hbalock);
  550. list_splice_init(&phba->elsbuf, &completions);
  551. phba->elsbuf_cnt = 0;
  552. phba->elsbuf_prev_cnt = 0;
  553. spin_unlock_irq(&phba->hbalock);
  554. while (!list_empty(&completions)) {
  555. list_remove_head(&completions, buf_ptr,
  556. struct lpfc_dmabuf, list);
  557. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  558. kfree(buf_ptr);
  559. }
  560. }
  561. phba->elsbuf_prev_cnt = phba->elsbuf_cnt;
  562. /* If there is no heart beat outstanding, issue a heartbeat command */
  563. if (phba->cfg_enable_hba_heartbeat) {
  564. if (!phba->hb_outstanding) {
  565. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  566. if (!pmboxq) {
  567. mod_timer(&phba->hb_tmofunc,
  568. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  569. return;
  570. }
  571. lpfc_heart_beat(phba, pmboxq);
  572. pmboxq->mbox_cmpl = lpfc_hb_mbox_cmpl;
  573. pmboxq->vport = phba->pport;
  574. retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
  575. if (retval != MBX_BUSY && retval != MBX_SUCCESS) {
  576. mempool_free(pmboxq, phba->mbox_mem_pool);
  577. mod_timer(&phba->hb_tmofunc,
  578. jiffies + HZ * LPFC_HB_MBOX_INTERVAL);
  579. return;
  580. }
  581. mod_timer(&phba->hb_tmofunc,
  582. jiffies + HZ * LPFC_HB_MBOX_TIMEOUT);
  583. phba->hb_outstanding = 1;
  584. return;
  585. } else {
  586. /*
  587. * If heart beat timeout called with hb_outstanding set
  588. * we need to take the HBA offline.
  589. */
  590. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  591. "0459 Adapter heartbeat failure, "
  592. "taking this port offline.\n");
  593. spin_lock_irq(&phba->hbalock);
  594. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  595. spin_unlock_irq(&phba->hbalock);
  596. lpfc_offline_prep(phba);
  597. lpfc_offline(phba);
  598. lpfc_unblock_mgmt_io(phba);
  599. phba->link_state = LPFC_HBA_ERROR;
  600. lpfc_hba_down_post(phba);
  601. }
  602. }
  603. }
  604. static void
  605. lpfc_offline_eratt(struct lpfc_hba *phba)
  606. {
  607. struct lpfc_sli *psli = &phba->sli;
  608. spin_lock_irq(&phba->hbalock);
  609. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  610. spin_unlock_irq(&phba->hbalock);
  611. lpfc_offline_prep(phba);
  612. lpfc_offline(phba);
  613. lpfc_reset_barrier(phba);
  614. lpfc_sli_brdreset(phba);
  615. lpfc_hba_down_post(phba);
  616. lpfc_sli_brdready(phba, HS_MBRDY);
  617. lpfc_unblock_mgmt_io(phba);
  618. phba->link_state = LPFC_HBA_ERROR;
  619. return;
  620. }
  621. /************************************************************************/
  622. /* */
  623. /* lpfc_handle_eratt */
  624. /* This routine will handle processing a Host Attention */
  625. /* Error Status event. This will be initialized */
  626. /* as a SLI layer callback routine. */
  627. /* */
  628. /************************************************************************/
  629. void
  630. lpfc_handle_eratt(struct lpfc_hba *phba)
  631. {
  632. struct lpfc_vport *vport = phba->pport;
  633. struct lpfc_sli *psli = &phba->sli;
  634. struct lpfc_sli_ring *pring;
  635. struct lpfc_vport **vports;
  636. uint32_t event_data;
  637. unsigned long temperature;
  638. struct temp_event temp_event_data;
  639. struct Scsi_Host *shost;
  640. int i;
  641. /* If the pci channel is offline, ignore possible errors,
  642. * since we cannot communicate with the pci card anyway. */
  643. if (pci_channel_offline(phba->pcidev))
  644. return;
  645. /* If resets are disabled then leave the HBA alone and return */
  646. if (!phba->cfg_enable_hba_reset)
  647. return;
  648. if (phba->work_hs & HS_FFER6 ||
  649. phba->work_hs & HS_FFER5) {
  650. /* Re-establishing Link */
  651. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  652. "1301 Re-establishing Link "
  653. "Data: x%x x%x x%x\n",
  654. phba->work_hs,
  655. phba->work_status[0], phba->work_status[1]);
  656. vports = lpfc_create_vport_work_array(phba);
  657. if (vports != NULL)
  658. for(i = 0;
  659. i <= phba->max_vpi && vports[i] != NULL;
  660. i++){
  661. shost = lpfc_shost_from_vport(vports[i]);
  662. spin_lock_irq(shost->host_lock);
  663. vports[i]->fc_flag |= FC_ESTABLISH_LINK;
  664. spin_unlock_irq(shost->host_lock);
  665. }
  666. lpfc_destroy_vport_work_array(phba, vports);
  667. spin_lock_irq(&phba->hbalock);
  668. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  669. spin_unlock_irq(&phba->hbalock);
  670. /*
  671. * Firmware stops when it triggled erratt with HS_FFER6.
  672. * That could cause the I/Os dropped by the firmware.
  673. * Error iocb (I/O) on txcmplq and let the SCSI layer
  674. * retry it after re-establishing link.
  675. */
  676. pring = &psli->ring[psli->fcp_ring];
  677. lpfc_sli_abort_iocb_ring(phba, pring);
  678. /*
  679. * There was a firmware error. Take the hba offline and then
  680. * attempt to restart it.
  681. */
  682. lpfc_offline_prep(phba);
  683. lpfc_offline(phba);
  684. lpfc_sli_brdrestart(phba);
  685. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  686. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  687. lpfc_unblock_mgmt_io(phba);
  688. return;
  689. }
  690. lpfc_unblock_mgmt_io(phba);
  691. } else if (phba->work_hs & HS_CRIT_TEMP) {
  692. temperature = readl(phba->MBslimaddr + TEMPERATURE_OFFSET);
  693. temp_event_data.event_type = FC_REG_TEMPERATURE_EVENT;
  694. temp_event_data.event_code = LPFC_CRIT_TEMP;
  695. temp_event_data.data = (uint32_t)temperature;
  696. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  697. "0459 Adapter maximum temperature exceeded "
  698. "(%ld), taking this port offline "
  699. "Data: x%x x%x x%x\n",
  700. temperature, phba->work_hs,
  701. phba->work_status[0], phba->work_status[1]);
  702. shost = lpfc_shost_from_vport(phba->pport);
  703. fc_host_post_vendor_event(shost, fc_get_event_number(),
  704. sizeof(temp_event_data),
  705. (char *) &temp_event_data,
  706. SCSI_NL_VID_TYPE_PCI
  707. | PCI_VENDOR_ID_EMULEX);
  708. spin_lock_irq(&phba->hbalock);
  709. phba->over_temp_state = HBA_OVER_TEMP;
  710. spin_unlock_irq(&phba->hbalock);
  711. lpfc_offline_eratt(phba);
  712. } else {
  713. /* The if clause above forces this code path when the status
  714. * failure is a value other than FFER6. Do not call the offline
  715. * twice. This is the adapter hardware error path.
  716. */
  717. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  718. "0457 Adapter Hardware Error "
  719. "Data: x%x x%x x%x\n",
  720. phba->work_hs,
  721. phba->work_status[0], phba->work_status[1]);
  722. event_data = FC_REG_DUMP_EVENT;
  723. shost = lpfc_shost_from_vport(vport);
  724. fc_host_post_vendor_event(shost, fc_get_event_number(),
  725. sizeof(event_data), (char *) &event_data,
  726. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  727. lpfc_offline_eratt(phba);
  728. }
  729. }
  730. /************************************************************************/
  731. /* */
  732. /* lpfc_handle_latt */
  733. /* This routine will handle processing a Host Attention */
  734. /* Link Status event. This will be initialized */
  735. /* as a SLI layer callback routine. */
  736. /* */
  737. /************************************************************************/
  738. void
  739. lpfc_handle_latt(struct lpfc_hba *phba)
  740. {
  741. struct lpfc_vport *vport = phba->pport;
  742. struct lpfc_sli *psli = &phba->sli;
  743. LPFC_MBOXQ_t *pmb;
  744. volatile uint32_t control;
  745. struct lpfc_dmabuf *mp;
  746. int rc = 0;
  747. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  748. if (!pmb) {
  749. rc = 1;
  750. goto lpfc_handle_latt_err_exit;
  751. }
  752. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  753. if (!mp) {
  754. rc = 2;
  755. goto lpfc_handle_latt_free_pmb;
  756. }
  757. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  758. if (!mp->virt) {
  759. rc = 3;
  760. goto lpfc_handle_latt_free_mp;
  761. }
  762. /* Cleanup any outstanding ELS commands */
  763. lpfc_els_flush_all_cmd(phba);
  764. psli->slistat.link_event++;
  765. lpfc_read_la(phba, pmb, mp);
  766. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  767. pmb->vport = vport;
  768. rc = lpfc_sli_issue_mbox (phba, pmb, MBX_NOWAIT);
  769. if (rc == MBX_NOT_FINISHED) {
  770. rc = 4;
  771. goto lpfc_handle_latt_free_mbuf;
  772. }
  773. /* Clear Link Attention in HA REG */
  774. spin_lock_irq(&phba->hbalock);
  775. writel(HA_LATT, phba->HAregaddr);
  776. readl(phba->HAregaddr); /* flush */
  777. spin_unlock_irq(&phba->hbalock);
  778. return;
  779. lpfc_handle_latt_free_mbuf:
  780. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  781. lpfc_handle_latt_free_mp:
  782. kfree(mp);
  783. lpfc_handle_latt_free_pmb:
  784. mempool_free(pmb, phba->mbox_mem_pool);
  785. lpfc_handle_latt_err_exit:
  786. /* Enable Link attention interrupts */
  787. spin_lock_irq(&phba->hbalock);
  788. psli->sli_flag |= LPFC_PROCESS_LA;
  789. control = readl(phba->HCregaddr);
  790. control |= HC_LAINT_ENA;
  791. writel(control, phba->HCregaddr);
  792. readl(phba->HCregaddr); /* flush */
  793. /* Clear Link Attention in HA REG */
  794. writel(HA_LATT, phba->HAregaddr);
  795. readl(phba->HAregaddr); /* flush */
  796. spin_unlock_irq(&phba->hbalock);
  797. lpfc_linkdown(phba);
  798. phba->link_state = LPFC_HBA_ERROR;
  799. lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
  800. "0300 LATT: Cannot issue READ_LA: Data:%d\n", rc);
  801. return;
  802. }
  803. /************************************************************************/
  804. /* */
  805. /* lpfc_parse_vpd */
  806. /* This routine will parse the VPD data */
  807. /* */
  808. /************************************************************************/
  809. static int
  810. lpfc_parse_vpd(struct lpfc_hba *phba, uint8_t *vpd, int len)
  811. {
  812. uint8_t lenlo, lenhi;
  813. int Length;
  814. int i, j;
  815. int finished = 0;
  816. int index = 0;
  817. if (!vpd)
  818. return 0;
  819. /* Vital Product */
  820. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  821. "0455 Vital Product Data: x%x x%x x%x x%x\n",
  822. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  823. (uint32_t) vpd[3]);
  824. while (!finished && (index < (len - 4))) {
  825. switch (vpd[index]) {
  826. case 0x82:
  827. case 0x91:
  828. index += 1;
  829. lenlo = vpd[index];
  830. index += 1;
  831. lenhi = vpd[index];
  832. index += 1;
  833. i = ((((unsigned short)lenhi) << 8) + lenlo);
  834. index += i;
  835. break;
  836. case 0x90:
  837. index += 1;
  838. lenlo = vpd[index];
  839. index += 1;
  840. lenhi = vpd[index];
  841. index += 1;
  842. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  843. if (Length > len - index)
  844. Length = len - index;
  845. while (Length > 0) {
  846. /* Look for Serial Number */
  847. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  848. index += 2;
  849. i = vpd[index];
  850. index += 1;
  851. j = 0;
  852. Length -= (3+i);
  853. while(i--) {
  854. phba->SerialNumber[j++] = vpd[index++];
  855. if (j == 31)
  856. break;
  857. }
  858. phba->SerialNumber[j] = 0;
  859. continue;
  860. }
  861. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  862. phba->vpd_flag |= VPD_MODEL_DESC;
  863. index += 2;
  864. i = vpd[index];
  865. index += 1;
  866. j = 0;
  867. Length -= (3+i);
  868. while(i--) {
  869. phba->ModelDesc[j++] = vpd[index++];
  870. if (j == 255)
  871. break;
  872. }
  873. phba->ModelDesc[j] = 0;
  874. continue;
  875. }
  876. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  877. phba->vpd_flag |= VPD_MODEL_NAME;
  878. index += 2;
  879. i = vpd[index];
  880. index += 1;
  881. j = 0;
  882. Length -= (3+i);
  883. while(i--) {
  884. phba->ModelName[j++] = vpd[index++];
  885. if (j == 79)
  886. break;
  887. }
  888. phba->ModelName[j] = 0;
  889. continue;
  890. }
  891. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  892. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  893. index += 2;
  894. i = vpd[index];
  895. index += 1;
  896. j = 0;
  897. Length -= (3+i);
  898. while(i--) {
  899. phba->ProgramType[j++] = vpd[index++];
  900. if (j == 255)
  901. break;
  902. }
  903. phba->ProgramType[j] = 0;
  904. continue;
  905. }
  906. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  907. phba->vpd_flag |= VPD_PORT;
  908. index += 2;
  909. i = vpd[index];
  910. index += 1;
  911. j = 0;
  912. Length -= (3+i);
  913. while(i--) {
  914. phba->Port[j++] = vpd[index++];
  915. if (j == 19)
  916. break;
  917. }
  918. phba->Port[j] = 0;
  919. continue;
  920. }
  921. else {
  922. index += 2;
  923. i = vpd[index];
  924. index += 1;
  925. index += i;
  926. Length -= (3 + i);
  927. }
  928. }
  929. finished = 0;
  930. break;
  931. case 0x78:
  932. finished = 1;
  933. break;
  934. default:
  935. index ++;
  936. break;
  937. }
  938. }
  939. return(1);
  940. }
  941. static void
  942. lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
  943. {
  944. lpfc_vpd_t *vp;
  945. uint16_t dev_id = phba->pcidev->device;
  946. int max_speed;
  947. struct {
  948. char * name;
  949. int max_speed;
  950. char * bus;
  951. } m = {"<Unknown>", 0, ""};
  952. if (mdp && mdp[0] != '\0'
  953. && descp && descp[0] != '\0')
  954. return;
  955. if (phba->lmt & LMT_10Gb)
  956. max_speed = 10;
  957. else if (phba->lmt & LMT_8Gb)
  958. max_speed = 8;
  959. else if (phba->lmt & LMT_4Gb)
  960. max_speed = 4;
  961. else if (phba->lmt & LMT_2Gb)
  962. max_speed = 2;
  963. else
  964. max_speed = 1;
  965. vp = &phba->vpd;
  966. switch (dev_id) {
  967. case PCI_DEVICE_ID_FIREFLY:
  968. m = (typeof(m)){"LP6000", max_speed, "PCI"};
  969. break;
  970. case PCI_DEVICE_ID_SUPERFLY:
  971. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  972. m = (typeof(m)){"LP7000", max_speed, "PCI"};
  973. else
  974. m = (typeof(m)){"LP7000E", max_speed, "PCI"};
  975. break;
  976. case PCI_DEVICE_ID_DRAGONFLY:
  977. m = (typeof(m)){"LP8000", max_speed, "PCI"};
  978. break;
  979. case PCI_DEVICE_ID_CENTAUR:
  980. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  981. m = (typeof(m)){"LP9002", max_speed, "PCI"};
  982. else
  983. m = (typeof(m)){"LP9000", max_speed, "PCI"};
  984. break;
  985. case PCI_DEVICE_ID_RFLY:
  986. m = (typeof(m)){"LP952", max_speed, "PCI"};
  987. break;
  988. case PCI_DEVICE_ID_PEGASUS:
  989. m = (typeof(m)){"LP9802", max_speed, "PCI-X"};
  990. break;
  991. case PCI_DEVICE_ID_THOR:
  992. m = (typeof(m)){"LP10000", max_speed, "PCI-X"};
  993. break;
  994. case PCI_DEVICE_ID_VIPER:
  995. m = (typeof(m)){"LPX1000", max_speed, "PCI-X"};
  996. break;
  997. case PCI_DEVICE_ID_PFLY:
  998. m = (typeof(m)){"LP982", max_speed, "PCI-X"};
  999. break;
  1000. case PCI_DEVICE_ID_TFLY:
  1001. m = (typeof(m)){"LP1050", max_speed, "PCI-X"};
  1002. break;
  1003. case PCI_DEVICE_ID_HELIOS:
  1004. m = (typeof(m)){"LP11000", max_speed, "PCI-X2"};
  1005. break;
  1006. case PCI_DEVICE_ID_HELIOS_SCSP:
  1007. m = (typeof(m)){"LP11000-SP", max_speed, "PCI-X2"};
  1008. break;
  1009. case PCI_DEVICE_ID_HELIOS_DCSP:
  1010. m = (typeof(m)){"LP11002-SP", max_speed, "PCI-X2"};
  1011. break;
  1012. case PCI_DEVICE_ID_NEPTUNE:
  1013. m = (typeof(m)){"LPe1000", max_speed, "PCIe"};
  1014. break;
  1015. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  1016. m = (typeof(m)){"LPe1000-SP", max_speed, "PCIe"};
  1017. break;
  1018. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  1019. m = (typeof(m)){"LPe1002-SP", max_speed, "PCIe"};
  1020. break;
  1021. case PCI_DEVICE_ID_BMID:
  1022. m = (typeof(m)){"LP1150", max_speed, "PCI-X2"};
  1023. break;
  1024. case PCI_DEVICE_ID_BSMB:
  1025. m = (typeof(m)){"LP111", max_speed, "PCI-X2"};
  1026. break;
  1027. case PCI_DEVICE_ID_ZEPHYR:
  1028. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1029. break;
  1030. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  1031. m = (typeof(m)){"LPe11000", max_speed, "PCIe"};
  1032. break;
  1033. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  1034. m = (typeof(m)){"LPe11002-SP", max_speed, "PCIe"};
  1035. break;
  1036. case PCI_DEVICE_ID_ZMID:
  1037. m = (typeof(m)){"LPe1150", max_speed, "PCIe"};
  1038. break;
  1039. case PCI_DEVICE_ID_ZSMB:
  1040. m = (typeof(m)){"LPe111", max_speed, "PCIe"};
  1041. break;
  1042. case PCI_DEVICE_ID_LP101:
  1043. m = (typeof(m)){"LP101", max_speed, "PCI-X"};
  1044. break;
  1045. case PCI_DEVICE_ID_LP10000S:
  1046. m = (typeof(m)){"LP10000-S", max_speed, "PCI"};
  1047. break;
  1048. case PCI_DEVICE_ID_LP11000S:
  1049. m = (typeof(m)){"LP11000-S", max_speed,
  1050. "PCI-X2"};
  1051. break;
  1052. case PCI_DEVICE_ID_LPE11000S:
  1053. m = (typeof(m)){"LPe11000-S", max_speed,
  1054. "PCIe"};
  1055. break;
  1056. case PCI_DEVICE_ID_SAT:
  1057. m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
  1058. break;
  1059. case PCI_DEVICE_ID_SAT_MID:
  1060. m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
  1061. break;
  1062. case PCI_DEVICE_ID_SAT_SMB:
  1063. m = (typeof(m)){"LPe121", max_speed, "PCIe"};
  1064. break;
  1065. case PCI_DEVICE_ID_SAT_DCSP:
  1066. m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
  1067. break;
  1068. case PCI_DEVICE_ID_SAT_SCSP:
  1069. m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
  1070. break;
  1071. case PCI_DEVICE_ID_SAT_S:
  1072. m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
  1073. break;
  1074. default:
  1075. m = (typeof(m)){ NULL };
  1076. break;
  1077. }
  1078. if (mdp && mdp[0] == '\0')
  1079. snprintf(mdp, 79,"%s", m.name);
  1080. if (descp && descp[0] == '\0')
  1081. snprintf(descp, 255,
  1082. "Emulex %s %dGb %s Fibre Channel Adapter",
  1083. m.name, m.max_speed, m.bus);
  1084. }
  1085. /**************************************************/
  1086. /* lpfc_post_buffer */
  1087. /* */
  1088. /* This routine will post count buffers to the */
  1089. /* ring with the QUE_RING_BUF_CN command. This */
  1090. /* allows 3 buffers / command to be posted. */
  1091. /* Returns the number of buffers NOT posted. */
  1092. /**************************************************/
  1093. int
  1094. lpfc_post_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring, int cnt,
  1095. int type)
  1096. {
  1097. IOCB_t *icmd;
  1098. struct lpfc_iocbq *iocb;
  1099. struct lpfc_dmabuf *mp1, *mp2;
  1100. cnt += pring->missbufcnt;
  1101. /* While there are buffers to post */
  1102. while (cnt > 0) {
  1103. /* Allocate buffer for command iocb */
  1104. iocb = lpfc_sli_get_iocbq(phba);
  1105. if (iocb == NULL) {
  1106. pring->missbufcnt = cnt;
  1107. return cnt;
  1108. }
  1109. icmd = &iocb->iocb;
  1110. /* 2 buffers can be posted per command */
  1111. /* Allocate buffer to post */
  1112. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1113. if (mp1)
  1114. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &mp1->phys);
  1115. if (!mp1 || !mp1->virt) {
  1116. kfree(mp1);
  1117. lpfc_sli_release_iocbq(phba, iocb);
  1118. pring->missbufcnt = cnt;
  1119. return cnt;
  1120. }
  1121. INIT_LIST_HEAD(&mp1->list);
  1122. /* Allocate buffer to post */
  1123. if (cnt > 1) {
  1124. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  1125. if (mp2)
  1126. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  1127. &mp2->phys);
  1128. if (!mp2 || !mp2->virt) {
  1129. kfree(mp2);
  1130. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1131. kfree(mp1);
  1132. lpfc_sli_release_iocbq(phba, iocb);
  1133. pring->missbufcnt = cnt;
  1134. return cnt;
  1135. }
  1136. INIT_LIST_HEAD(&mp2->list);
  1137. } else {
  1138. mp2 = NULL;
  1139. }
  1140. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  1141. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  1142. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  1143. icmd->ulpBdeCount = 1;
  1144. cnt--;
  1145. if (mp2) {
  1146. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  1147. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  1148. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  1149. cnt--;
  1150. icmd->ulpBdeCount = 2;
  1151. }
  1152. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  1153. icmd->ulpLe = 1;
  1154. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  1155. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  1156. kfree(mp1);
  1157. cnt++;
  1158. if (mp2) {
  1159. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  1160. kfree(mp2);
  1161. cnt++;
  1162. }
  1163. lpfc_sli_release_iocbq(phba, iocb);
  1164. pring->missbufcnt = cnt;
  1165. return cnt;
  1166. }
  1167. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  1168. if (mp2)
  1169. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  1170. }
  1171. pring->missbufcnt = 0;
  1172. return 0;
  1173. }
  1174. /************************************************************************/
  1175. /* */
  1176. /* lpfc_post_rcv_buf */
  1177. /* This routine post initial rcv buffers to the configured rings */
  1178. /* */
  1179. /************************************************************************/
  1180. static int
  1181. lpfc_post_rcv_buf(struct lpfc_hba *phba)
  1182. {
  1183. struct lpfc_sli *psli = &phba->sli;
  1184. /* Ring 0, ELS / CT buffers */
  1185. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
  1186. /* Ring 2 - FCP no buffers needed */
  1187. return 0;
  1188. }
  1189. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1190. /************************************************************************/
  1191. /* */
  1192. /* lpfc_sha_init */
  1193. /* */
  1194. /************************************************************************/
  1195. static void
  1196. lpfc_sha_init(uint32_t * HashResultPointer)
  1197. {
  1198. HashResultPointer[0] = 0x67452301;
  1199. HashResultPointer[1] = 0xEFCDAB89;
  1200. HashResultPointer[2] = 0x98BADCFE;
  1201. HashResultPointer[3] = 0x10325476;
  1202. HashResultPointer[4] = 0xC3D2E1F0;
  1203. }
  1204. /************************************************************************/
  1205. /* */
  1206. /* lpfc_sha_iterate */
  1207. /* */
  1208. /************************************************************************/
  1209. static void
  1210. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1211. {
  1212. int t;
  1213. uint32_t TEMP;
  1214. uint32_t A, B, C, D, E;
  1215. t = 16;
  1216. do {
  1217. HashWorkingPointer[t] =
  1218. S(1,
  1219. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1220. 8] ^
  1221. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1222. } while (++t <= 79);
  1223. t = 0;
  1224. A = HashResultPointer[0];
  1225. B = HashResultPointer[1];
  1226. C = HashResultPointer[2];
  1227. D = HashResultPointer[3];
  1228. E = HashResultPointer[4];
  1229. do {
  1230. if (t < 20) {
  1231. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1232. } else if (t < 40) {
  1233. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1234. } else if (t < 60) {
  1235. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1236. } else {
  1237. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1238. }
  1239. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1240. E = D;
  1241. D = C;
  1242. C = S(30, B);
  1243. B = A;
  1244. A = TEMP;
  1245. } while (++t <= 79);
  1246. HashResultPointer[0] += A;
  1247. HashResultPointer[1] += B;
  1248. HashResultPointer[2] += C;
  1249. HashResultPointer[3] += D;
  1250. HashResultPointer[4] += E;
  1251. }
  1252. /************************************************************************/
  1253. /* */
  1254. /* lpfc_challenge_key */
  1255. /* */
  1256. /************************************************************************/
  1257. static void
  1258. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1259. {
  1260. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1261. }
  1262. /************************************************************************/
  1263. /* */
  1264. /* lpfc_hba_init */
  1265. /* */
  1266. /************************************************************************/
  1267. void
  1268. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1269. {
  1270. int t;
  1271. uint32_t *HashWorking;
  1272. uint32_t *pwwnn = (uint32_t *) phba->wwnn;
  1273. HashWorking = kcalloc(80, sizeof(uint32_t), GFP_KERNEL);
  1274. if (!HashWorking)
  1275. return;
  1276. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1277. HashWorking[1] = HashWorking[79] = *pwwnn;
  1278. for (t = 0; t < 7; t++)
  1279. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1280. lpfc_sha_init(hbainit);
  1281. lpfc_sha_iterate(hbainit, HashWorking);
  1282. kfree(HashWorking);
  1283. }
  1284. void
  1285. lpfc_cleanup(struct lpfc_vport *vport)
  1286. {
  1287. struct lpfc_hba *phba = vport->phba;
  1288. struct lpfc_nodelist *ndlp, *next_ndlp;
  1289. int i = 0;
  1290. if (phba->link_state > LPFC_LINK_DOWN)
  1291. lpfc_port_link_failure(vport);
  1292. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1293. if (!NLP_CHK_NODE_ACT(ndlp)) {
  1294. ndlp = lpfc_enable_node(vport, ndlp,
  1295. NLP_STE_UNUSED_NODE);
  1296. if (!ndlp)
  1297. continue;
  1298. spin_lock_irq(&phba->ndlp_lock);
  1299. NLP_SET_FREE_REQ(ndlp);
  1300. spin_unlock_irq(&phba->ndlp_lock);
  1301. /* Trigger the release of the ndlp memory */
  1302. lpfc_nlp_put(ndlp);
  1303. continue;
  1304. }
  1305. spin_lock_irq(&phba->ndlp_lock);
  1306. if (NLP_CHK_FREE_REQ(ndlp)) {
  1307. /* The ndlp should not be in memory free mode already */
  1308. spin_unlock_irq(&phba->ndlp_lock);
  1309. continue;
  1310. } else
  1311. /* Indicate request for freeing ndlp memory */
  1312. NLP_SET_FREE_REQ(ndlp);
  1313. spin_unlock_irq(&phba->ndlp_lock);
  1314. if (ndlp->nlp_type & NLP_FABRIC)
  1315. lpfc_disc_state_machine(vport, ndlp, NULL,
  1316. NLP_EVT_DEVICE_RECOVERY);
  1317. lpfc_disc_state_machine(vport, ndlp, NULL,
  1318. NLP_EVT_DEVICE_RM);
  1319. }
  1320. /* At this point, ALL ndlp's should be gone
  1321. * because of the previous NLP_EVT_DEVICE_RM.
  1322. * Lets wait for this to happen, if needed.
  1323. */
  1324. while (!list_empty(&vport->fc_nodes)) {
  1325. if (i++ > 3000) {
  1326. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1327. "0233 Nodelist not empty\n");
  1328. list_for_each_entry_safe(ndlp, next_ndlp,
  1329. &vport->fc_nodes, nlp_listp) {
  1330. lpfc_printf_vlog(ndlp->vport, KERN_ERR,
  1331. LOG_NODE,
  1332. "0282: did:x%x ndlp:x%p "
  1333. "usgmap:x%x refcnt:%d\n",
  1334. ndlp->nlp_DID, (void *)ndlp,
  1335. ndlp->nlp_usg_map,
  1336. atomic_read(
  1337. &ndlp->kref.refcount));
  1338. }
  1339. break;
  1340. }
  1341. /* Wait for any activity on ndlps to settle */
  1342. msleep(10);
  1343. }
  1344. return;
  1345. }
  1346. static void
  1347. lpfc_establish_link_tmo(unsigned long ptr)
  1348. {
  1349. struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
  1350. struct lpfc_vport **vports;
  1351. unsigned long iflag;
  1352. int i;
  1353. /* Re-establishing Link, timer expired */
  1354. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1355. "1300 Re-establishing Link, timer expired "
  1356. "Data: x%x x%x\n",
  1357. phba->pport->fc_flag, phba->pport->port_state);
  1358. vports = lpfc_create_vport_work_array(phba);
  1359. if (vports != NULL)
  1360. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1361. struct Scsi_Host *shost;
  1362. shost = lpfc_shost_from_vport(vports[i]);
  1363. spin_lock_irqsave(shost->host_lock, iflag);
  1364. vports[i]->fc_flag &= ~FC_ESTABLISH_LINK;
  1365. spin_unlock_irqrestore(shost->host_lock, iflag);
  1366. }
  1367. lpfc_destroy_vport_work_array(phba, vports);
  1368. }
  1369. void
  1370. lpfc_stop_vport_timers(struct lpfc_vport *vport)
  1371. {
  1372. del_timer_sync(&vport->els_tmofunc);
  1373. del_timer_sync(&vport->fc_fdmitmo);
  1374. lpfc_can_disctmo(vport);
  1375. return;
  1376. }
  1377. static void
  1378. lpfc_stop_phba_timers(struct lpfc_hba *phba)
  1379. {
  1380. del_timer_sync(&phba->fcp_poll_timer);
  1381. del_timer_sync(&phba->fc_estabtmo);
  1382. lpfc_stop_vport_timers(phba->pport);
  1383. del_timer_sync(&phba->sli.mbox_tmo);
  1384. del_timer_sync(&phba->fabric_block_timer);
  1385. phba->hb_outstanding = 0;
  1386. del_timer_sync(&phba->hb_tmofunc);
  1387. return;
  1388. }
  1389. static void
  1390. lpfc_block_mgmt_io(struct lpfc_hba * phba)
  1391. {
  1392. unsigned long iflag;
  1393. spin_lock_irqsave(&phba->hbalock, iflag);
  1394. phba->sli.sli_flag |= LPFC_BLOCK_MGMT_IO;
  1395. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1396. }
  1397. int
  1398. lpfc_online(struct lpfc_hba *phba)
  1399. {
  1400. struct lpfc_vport *vport = phba->pport;
  1401. struct lpfc_vport **vports;
  1402. int i;
  1403. if (!phba)
  1404. return 0;
  1405. if (!(vport->fc_flag & FC_OFFLINE_MODE))
  1406. return 0;
  1407. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1408. "0458 Bring Adapter online\n");
  1409. lpfc_block_mgmt_io(phba);
  1410. if (!lpfc_sli_queue_setup(phba)) {
  1411. lpfc_unblock_mgmt_io(phba);
  1412. return 1;
  1413. }
  1414. if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
  1415. lpfc_unblock_mgmt_io(phba);
  1416. return 1;
  1417. }
  1418. vports = lpfc_create_vport_work_array(phba);
  1419. if (vports != NULL)
  1420. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1421. struct Scsi_Host *shost;
  1422. shost = lpfc_shost_from_vport(vports[i]);
  1423. spin_lock_irq(shost->host_lock);
  1424. vports[i]->fc_flag &= ~FC_OFFLINE_MODE;
  1425. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
  1426. vports[i]->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1427. spin_unlock_irq(shost->host_lock);
  1428. }
  1429. lpfc_destroy_vport_work_array(phba, vports);
  1430. lpfc_unblock_mgmt_io(phba);
  1431. return 0;
  1432. }
  1433. void
  1434. lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
  1435. {
  1436. unsigned long iflag;
  1437. spin_lock_irqsave(&phba->hbalock, iflag);
  1438. phba->sli.sli_flag &= ~LPFC_BLOCK_MGMT_IO;
  1439. spin_unlock_irqrestore(&phba->hbalock, iflag);
  1440. }
  1441. void
  1442. lpfc_offline_prep(struct lpfc_hba * phba)
  1443. {
  1444. struct lpfc_vport *vport = phba->pport;
  1445. struct lpfc_nodelist *ndlp, *next_ndlp;
  1446. struct lpfc_vport **vports;
  1447. int i;
  1448. if (vport->fc_flag & FC_OFFLINE_MODE)
  1449. return;
  1450. lpfc_block_mgmt_io(phba);
  1451. lpfc_linkdown(phba);
  1452. /* Issue an unreg_login to all nodes on all vports */
  1453. vports = lpfc_create_vport_work_array(phba);
  1454. if (vports != NULL) {
  1455. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1456. struct Scsi_Host *shost;
  1457. if (vports[i]->load_flag & FC_UNLOADING)
  1458. continue;
  1459. shost = lpfc_shost_from_vport(vports[i]);
  1460. list_for_each_entry_safe(ndlp, next_ndlp,
  1461. &vports[i]->fc_nodes,
  1462. nlp_listp) {
  1463. if (!NLP_CHK_NODE_ACT(ndlp))
  1464. continue;
  1465. if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
  1466. continue;
  1467. if (ndlp->nlp_type & NLP_FABRIC) {
  1468. lpfc_disc_state_machine(vports[i], ndlp,
  1469. NULL, NLP_EVT_DEVICE_RECOVERY);
  1470. lpfc_disc_state_machine(vports[i], ndlp,
  1471. NULL, NLP_EVT_DEVICE_RM);
  1472. }
  1473. spin_lock_irq(shost->host_lock);
  1474. ndlp->nlp_flag &= ~NLP_NPR_ADISC;
  1475. spin_unlock_irq(shost->host_lock);
  1476. lpfc_unreg_rpi(vports[i], ndlp);
  1477. }
  1478. }
  1479. }
  1480. lpfc_destroy_vport_work_array(phba, vports);
  1481. lpfc_sli_flush_mbox_queue(phba);
  1482. }
  1483. void
  1484. lpfc_offline(struct lpfc_hba *phba)
  1485. {
  1486. struct Scsi_Host *shost;
  1487. struct lpfc_vport **vports;
  1488. int i;
  1489. if (phba->pport->fc_flag & FC_OFFLINE_MODE)
  1490. return;
  1491. /* stop all timers associated with this hba */
  1492. lpfc_stop_phba_timers(phba);
  1493. vports = lpfc_create_vport_work_array(phba);
  1494. if (vports != NULL)
  1495. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
  1496. lpfc_stop_vport_timers(vports[i]);
  1497. lpfc_destroy_vport_work_array(phba, vports);
  1498. lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
  1499. "0460 Bring Adapter offline\n");
  1500. /* Bring down the SLI Layer and cleanup. The HBA is offline
  1501. now. */
  1502. lpfc_sli_hba_down(phba);
  1503. spin_lock_irq(&phba->hbalock);
  1504. phba->work_ha = 0;
  1505. spin_unlock_irq(&phba->hbalock);
  1506. vports = lpfc_create_vport_work_array(phba);
  1507. if (vports != NULL)
  1508. for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
  1509. shost = lpfc_shost_from_vport(vports[i]);
  1510. spin_lock_irq(shost->host_lock);
  1511. vports[i]->work_port_events = 0;
  1512. vports[i]->fc_flag |= FC_OFFLINE_MODE;
  1513. spin_unlock_irq(shost->host_lock);
  1514. }
  1515. lpfc_destroy_vport_work_array(phba, vports);
  1516. }
  1517. /******************************************************************************
  1518. * Function name: lpfc_scsi_free
  1519. *
  1520. * Description: Called from lpfc_pci_remove_one free internal driver resources
  1521. *
  1522. ******************************************************************************/
  1523. static int
  1524. lpfc_scsi_free(struct lpfc_hba *phba)
  1525. {
  1526. struct lpfc_scsi_buf *sb, *sb_next;
  1527. struct lpfc_iocbq *io, *io_next;
  1528. spin_lock_irq(&phba->hbalock);
  1529. /* Release all the lpfc_scsi_bufs maintained by this host. */
  1530. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  1531. list_del(&sb->list);
  1532. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  1533. sb->dma_handle);
  1534. kfree(sb);
  1535. phba->total_scsi_bufs--;
  1536. }
  1537. /* Release all the lpfc_iocbq entries maintained by this host. */
  1538. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  1539. list_del(&io->list);
  1540. kfree(io);
  1541. phba->total_iocbq_bufs--;
  1542. }
  1543. spin_unlock_irq(&phba->hbalock);
  1544. return 0;
  1545. }
  1546. struct lpfc_vport *
  1547. lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
  1548. {
  1549. struct lpfc_vport *vport;
  1550. struct Scsi_Host *shost;
  1551. int error = 0;
  1552. if (dev != &phba->pcidev->dev)
  1553. shost = scsi_host_alloc(&lpfc_vport_template,
  1554. sizeof(struct lpfc_vport));
  1555. else
  1556. shost = scsi_host_alloc(&lpfc_template,
  1557. sizeof(struct lpfc_vport));
  1558. if (!shost)
  1559. goto out;
  1560. vport = (struct lpfc_vport *) shost->hostdata;
  1561. vport->phba = phba;
  1562. vport->load_flag |= FC_LOADING;
  1563. vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
  1564. lpfc_get_vport_cfgparam(vport);
  1565. shost->unique_id = instance;
  1566. shost->max_id = LPFC_MAX_TARGET;
  1567. shost->max_lun = vport->cfg_max_luns;
  1568. shost->this_id = -1;
  1569. shost->max_cmd_len = 16;
  1570. /*
  1571. * Set initial can_queue value since 0 is no longer supported and
  1572. * scsi_add_host will fail. This will be adjusted later based on the
  1573. * max xri value determined in hba setup.
  1574. */
  1575. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1576. if (dev != &phba->pcidev->dev) {
  1577. shost->transportt = lpfc_vport_transport_template;
  1578. vport->port_type = LPFC_NPIV_PORT;
  1579. } else {
  1580. shost->transportt = lpfc_transport_template;
  1581. vport->port_type = LPFC_PHYSICAL_PORT;
  1582. }
  1583. /* Initialize all internally managed lists. */
  1584. INIT_LIST_HEAD(&vport->fc_nodes);
  1585. spin_lock_init(&vport->work_port_lock);
  1586. init_timer(&vport->fc_disctmo);
  1587. vport->fc_disctmo.function = lpfc_disc_timeout;
  1588. vport->fc_disctmo.data = (unsigned long)vport;
  1589. init_timer(&vport->fc_fdmitmo);
  1590. vport->fc_fdmitmo.function = lpfc_fdmi_tmo;
  1591. vport->fc_fdmitmo.data = (unsigned long)vport;
  1592. init_timer(&vport->els_tmofunc);
  1593. vport->els_tmofunc.function = lpfc_els_timeout;
  1594. vport->els_tmofunc.data = (unsigned long)vport;
  1595. error = scsi_add_host(shost, dev);
  1596. if (error)
  1597. goto out_put_shost;
  1598. spin_lock_irq(&phba->hbalock);
  1599. list_add_tail(&vport->listentry, &phba->port_list);
  1600. spin_unlock_irq(&phba->hbalock);
  1601. return vport;
  1602. out_put_shost:
  1603. scsi_host_put(shost);
  1604. out:
  1605. return NULL;
  1606. }
  1607. void
  1608. destroy_port(struct lpfc_vport *vport)
  1609. {
  1610. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1611. struct lpfc_hba *phba = vport->phba;
  1612. kfree(vport->vname);
  1613. lpfc_debugfs_terminate(vport);
  1614. fc_remove_host(shost);
  1615. scsi_remove_host(shost);
  1616. spin_lock_irq(&phba->hbalock);
  1617. list_del_init(&vport->listentry);
  1618. spin_unlock_irq(&phba->hbalock);
  1619. lpfc_cleanup(vport);
  1620. return;
  1621. }
  1622. int
  1623. lpfc_get_instance(void)
  1624. {
  1625. int instance = 0;
  1626. /* Assign an unused number */
  1627. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  1628. return -1;
  1629. if (idr_get_new(&lpfc_hba_index, NULL, &instance))
  1630. return -1;
  1631. return instance;
  1632. }
  1633. /*
  1634. * Note: there is no scan_start function as adapter initialization
  1635. * will have asynchronously kicked off the link initialization.
  1636. */
  1637. int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
  1638. {
  1639. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1640. struct lpfc_hba *phba = vport->phba;
  1641. int stat = 0;
  1642. spin_lock_irq(shost->host_lock);
  1643. if (vport->load_flag & FC_UNLOADING) {
  1644. stat = 1;
  1645. goto finished;
  1646. }
  1647. if (time >= 30 * HZ) {
  1648. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1649. "0461 Scanning longer than 30 "
  1650. "seconds. Continuing initialization\n");
  1651. stat = 1;
  1652. goto finished;
  1653. }
  1654. if (time >= 15 * HZ && phba->link_state <= LPFC_LINK_DOWN) {
  1655. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1656. "0465 Link down longer than 15 "
  1657. "seconds. Continuing initialization\n");
  1658. stat = 1;
  1659. goto finished;
  1660. }
  1661. if (vport->port_state != LPFC_VPORT_READY)
  1662. goto finished;
  1663. if (vport->num_disc_nodes || vport->fc_prli_sent)
  1664. goto finished;
  1665. if (vport->fc_map_cnt == 0 && time < 2 * HZ)
  1666. goto finished;
  1667. if ((phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) != 0)
  1668. goto finished;
  1669. stat = 1;
  1670. finished:
  1671. spin_unlock_irq(shost->host_lock);
  1672. return stat;
  1673. }
  1674. void lpfc_host_attrib_init(struct Scsi_Host *shost)
  1675. {
  1676. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1677. struct lpfc_hba *phba = vport->phba;
  1678. /*
  1679. * Set fixed host attributes. Must done after lpfc_sli_hba_setup().
  1680. */
  1681. fc_host_node_name(shost) = wwn_to_u64(vport->fc_nodename.u.wwn);
  1682. fc_host_port_name(shost) = wwn_to_u64(vport->fc_portname.u.wwn);
  1683. fc_host_supported_classes(shost) = FC_COS_CLASS3;
  1684. memset(fc_host_supported_fc4s(shost), 0,
  1685. sizeof(fc_host_supported_fc4s(shost)));
  1686. fc_host_supported_fc4s(shost)[2] = 1;
  1687. fc_host_supported_fc4s(shost)[7] = 1;
  1688. lpfc_vport_symbolic_node_name(vport, fc_host_symbolic_name(shost),
  1689. sizeof fc_host_symbolic_name(shost));
  1690. fc_host_supported_speeds(shost) = 0;
  1691. if (phba->lmt & LMT_10Gb)
  1692. fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
  1693. if (phba->lmt & LMT_8Gb)
  1694. fc_host_supported_speeds(shost) |= FC_PORTSPEED_8GBIT;
  1695. if (phba->lmt & LMT_4Gb)
  1696. fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
  1697. if (phba->lmt & LMT_2Gb)
  1698. fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
  1699. if (phba->lmt & LMT_1Gb)
  1700. fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
  1701. fc_host_maxframe_size(shost) =
  1702. (((uint32_t) vport->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1703. (uint32_t) vport->fc_sparam.cmn.bbRcvSizeLsb;
  1704. /* This value is also unchanging */
  1705. memset(fc_host_active_fc4s(shost), 0,
  1706. sizeof(fc_host_active_fc4s(shost)));
  1707. fc_host_active_fc4s(shost)[2] = 1;
  1708. fc_host_active_fc4s(shost)[7] = 1;
  1709. fc_host_max_npiv_vports(shost) = phba->max_vpi;
  1710. spin_lock_irq(shost->host_lock);
  1711. vport->load_flag &= ~FC_LOADING;
  1712. spin_unlock_irq(shost->host_lock);
  1713. }
  1714. static int __devinit
  1715. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  1716. {
  1717. struct lpfc_vport *vport = NULL;
  1718. struct lpfc_hba *phba;
  1719. struct lpfc_sli *psli;
  1720. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  1721. struct Scsi_Host *shost = NULL;
  1722. void *ptr;
  1723. unsigned long bar0map_len, bar2map_len;
  1724. int error = -ENODEV, retval;
  1725. int i, hbq_count;
  1726. uint16_t iotag;
  1727. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1728. if (pci_enable_device_mem(pdev))
  1729. goto out;
  1730. if (pci_request_selected_regions(pdev, bars, LPFC_DRIVER_NAME))
  1731. goto out_disable_device;
  1732. phba = kzalloc(sizeof (struct lpfc_hba), GFP_KERNEL);
  1733. if (!phba)
  1734. goto out_release_regions;
  1735. spin_lock_init(&phba->hbalock);
  1736. /* Initialize ndlp management spinlock */
  1737. spin_lock_init(&phba->ndlp_lock);
  1738. phba->pcidev = pdev;
  1739. /* Assign an unused board number */
  1740. if ((phba->brd_no = lpfc_get_instance()) < 0)
  1741. goto out_free_phba;
  1742. INIT_LIST_HEAD(&phba->port_list);
  1743. /*
  1744. * Get all the module params for configuring this host and then
  1745. * establish the host.
  1746. */
  1747. lpfc_get_cfgparam(phba);
  1748. phba->max_vpi = LPFC_MAX_VPI;
  1749. /* Initialize timers used by driver */
  1750. init_timer(&phba->fc_estabtmo);
  1751. phba->fc_estabtmo.function = lpfc_establish_link_tmo;
  1752. phba->fc_estabtmo.data = (unsigned long)phba;
  1753. init_timer(&phba->hb_tmofunc);
  1754. phba->hb_tmofunc.function = lpfc_hb_timeout;
  1755. phba->hb_tmofunc.data = (unsigned long)phba;
  1756. psli = &phba->sli;
  1757. init_timer(&psli->mbox_tmo);
  1758. psli->mbox_tmo.function = lpfc_mbox_timeout;
  1759. psli->mbox_tmo.data = (unsigned long) phba;
  1760. init_timer(&phba->fcp_poll_timer);
  1761. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  1762. phba->fcp_poll_timer.data = (unsigned long) phba;
  1763. init_timer(&phba->fabric_block_timer);
  1764. phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
  1765. phba->fabric_block_timer.data = (unsigned long) phba;
  1766. pci_set_master(pdev);
  1767. pci_try_set_mwi(pdev);
  1768. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  1769. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  1770. goto out_idr_remove;
  1771. /*
  1772. * Get the bus address of Bar0 and Bar2 and the number of bytes
  1773. * required by each mapping.
  1774. */
  1775. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  1776. bar0map_len = pci_resource_len(phba->pcidev, 0);
  1777. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  1778. bar2map_len = pci_resource_len(phba->pcidev, 2);
  1779. /* Map HBA SLIM to a kernel virtual address. */
  1780. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  1781. if (!phba->slim_memmap_p) {
  1782. error = -ENODEV;
  1783. dev_printk(KERN_ERR, &pdev->dev,
  1784. "ioremap failed for SLIM memory.\n");
  1785. goto out_idr_remove;
  1786. }
  1787. /* Map HBA Control Registers to a kernel virtual address. */
  1788. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  1789. if (!phba->ctrl_regs_memmap_p) {
  1790. error = -ENODEV;
  1791. dev_printk(KERN_ERR, &pdev->dev,
  1792. "ioremap failed for HBA control registers.\n");
  1793. goto out_iounmap_slim;
  1794. }
  1795. /* Allocate memory for SLI-2 structures */
  1796. phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
  1797. &phba->slim2p_mapping, GFP_KERNEL);
  1798. if (!phba->slim2p)
  1799. goto out_iounmap;
  1800. memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
  1801. phba->hbqslimp.virt = dma_alloc_coherent(&phba->pcidev->dev,
  1802. lpfc_sli_hbq_size(),
  1803. &phba->hbqslimp.phys,
  1804. GFP_KERNEL);
  1805. if (!phba->hbqslimp.virt)
  1806. goto out_free_slim;
  1807. hbq_count = lpfc_sli_hbq_count();
  1808. ptr = phba->hbqslimp.virt;
  1809. for (i = 0; i < hbq_count; ++i) {
  1810. phba->hbqs[i].hbq_virt = ptr;
  1811. INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
  1812. ptr += (lpfc_hbq_defs[i]->entry_count *
  1813. sizeof(struct lpfc_hbq_entry));
  1814. }
  1815. phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_els_hbq_alloc;
  1816. phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_els_hbq_free;
  1817. memset(phba->hbqslimp.virt, 0, lpfc_sli_hbq_size());
  1818. /* Initialize the SLI Layer to run with lpfc HBAs. */
  1819. lpfc_sli_setup(phba);
  1820. lpfc_sli_queue_setup(phba);
  1821. retval = lpfc_mem_alloc(phba);
  1822. if (retval) {
  1823. error = retval;
  1824. goto out_free_hbqslimp;
  1825. }
  1826. /* Initialize and populate the iocb list per host. */
  1827. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  1828. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  1829. iocbq_entry = kzalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  1830. if (iocbq_entry == NULL) {
  1831. printk(KERN_ERR "%s: only allocated %d iocbs of "
  1832. "expected %d count. Unloading driver.\n",
  1833. __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
  1834. error = -ENOMEM;
  1835. goto out_free_iocbq;
  1836. }
  1837. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1838. if (iotag == 0) {
  1839. kfree (iocbq_entry);
  1840. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1841. "Unloading driver.\n",
  1842. __FUNCTION__);
  1843. error = -ENOMEM;
  1844. goto out_free_iocbq;
  1845. }
  1846. spin_lock_irq(&phba->hbalock);
  1847. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1848. phba->total_iocbq_bufs++;
  1849. spin_unlock_irq(&phba->hbalock);
  1850. }
  1851. /* Initialize HBA structure */
  1852. phba->fc_edtov = FF_DEF_EDTOV;
  1853. phba->fc_ratov = FF_DEF_RATOV;
  1854. phba->fc_altov = FF_DEF_ALTOV;
  1855. phba->fc_arbtov = FF_DEF_ARBTOV;
  1856. INIT_LIST_HEAD(&phba->work_list);
  1857. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1858. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1859. /* Startup the kernel thread for this host adapter. */
  1860. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1861. "lpfc_worker_%d", phba->brd_no);
  1862. if (IS_ERR(phba->worker_thread)) {
  1863. error = PTR_ERR(phba->worker_thread);
  1864. goto out_free_iocbq;
  1865. }
  1866. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1867. spin_lock_init(&phba->scsi_buf_list_lock);
  1868. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1869. /* Initialize list of fabric iocbs */
  1870. INIT_LIST_HEAD(&phba->fabric_iocb_list);
  1871. /* Initialize list to save ELS buffers */
  1872. INIT_LIST_HEAD(&phba->elsbuf);
  1873. vport = lpfc_create_port(phba, phba->brd_no, &phba->pcidev->dev);
  1874. if (!vport)
  1875. goto out_kthread_stop;
  1876. shost = lpfc_shost_from_vport(vport);
  1877. phba->pport = vport;
  1878. lpfc_debugfs_initialize(vport);
  1879. pci_set_drvdata(pdev, shost);
  1880. if (phba->cfg_use_msi) {
  1881. retval = pci_enable_msi(phba->pcidev);
  1882. if (!retval)
  1883. phba->using_msi = 1;
  1884. else
  1885. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  1886. "0452 Enable MSI failed, continuing "
  1887. "with IRQ\n");
  1888. }
  1889. retval = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
  1890. LPFC_DRIVER_NAME, phba);
  1891. if (retval) {
  1892. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1893. "0451 Enable interrupt handler failed\n");
  1894. error = retval;
  1895. goto out_disable_msi;
  1896. }
  1897. phba->MBslimaddr = phba->slim_memmap_p;
  1898. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1899. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1900. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1901. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1902. if (lpfc_alloc_sysfs_attr(vport)) {
  1903. error = -ENOMEM;
  1904. goto out_free_irq;
  1905. }
  1906. if (lpfc_sli_hba_setup(phba)) {
  1907. error = -ENODEV;
  1908. goto out_remove_device;
  1909. }
  1910. /*
  1911. * hba setup may have changed the hba_queue_depth so we need to adjust
  1912. * the value of can_queue.
  1913. */
  1914. shost->can_queue = phba->cfg_hba_queue_depth - 10;
  1915. lpfc_host_attrib_init(shost);
  1916. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  1917. spin_lock_irq(shost->host_lock);
  1918. lpfc_poll_start_timer(phba);
  1919. spin_unlock_irq(shost->host_lock);
  1920. }
  1921. scsi_scan_host(shost);
  1922. return 0;
  1923. out_remove_device:
  1924. lpfc_free_sysfs_attr(vport);
  1925. spin_lock_irq(shost->host_lock);
  1926. vport->load_flag |= FC_UNLOADING;
  1927. spin_unlock_irq(shost->host_lock);
  1928. out_free_irq:
  1929. lpfc_stop_phba_timers(phba);
  1930. phba->pport->work_port_events = 0;
  1931. free_irq(phba->pcidev->irq, phba);
  1932. out_disable_msi:
  1933. if (phba->using_msi)
  1934. pci_disable_msi(phba->pcidev);
  1935. destroy_port(vport);
  1936. out_kthread_stop:
  1937. kthread_stop(phba->worker_thread);
  1938. out_free_iocbq:
  1939. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1940. &phba->lpfc_iocb_list, list) {
  1941. kfree(iocbq_entry);
  1942. phba->total_iocbq_bufs--;
  1943. }
  1944. lpfc_mem_free(phba);
  1945. out_free_hbqslimp:
  1946. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  1947. phba->hbqslimp.phys);
  1948. out_free_slim:
  1949. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1950. phba->slim2p_mapping);
  1951. out_iounmap:
  1952. iounmap(phba->ctrl_regs_memmap_p);
  1953. out_iounmap_slim:
  1954. iounmap(phba->slim_memmap_p);
  1955. out_idr_remove:
  1956. idr_remove(&lpfc_hba_index, phba->brd_no);
  1957. out_free_phba:
  1958. kfree(phba);
  1959. out_release_regions:
  1960. pci_release_selected_regions(pdev, bars);
  1961. out_disable_device:
  1962. pci_disable_device(pdev);
  1963. out:
  1964. pci_set_drvdata(pdev, NULL);
  1965. if (shost)
  1966. scsi_host_put(shost);
  1967. return error;
  1968. }
  1969. static void __devexit
  1970. lpfc_pci_remove_one(struct pci_dev *pdev)
  1971. {
  1972. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  1973. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1974. struct lpfc_hba *phba = vport->phba;
  1975. int bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1976. spin_lock_irq(&phba->hbalock);
  1977. vport->load_flag |= FC_UNLOADING;
  1978. spin_unlock_irq(&phba->hbalock);
  1979. kfree(vport->vname);
  1980. lpfc_free_sysfs_attr(vport);
  1981. kthread_stop(phba->worker_thread);
  1982. fc_remove_host(shost);
  1983. scsi_remove_host(shost);
  1984. lpfc_cleanup(vport);
  1985. /*
  1986. * Bring down the SLI Layer. This step disable all interrupts,
  1987. * clears the rings, discards all mailbox commands, and resets
  1988. * the HBA.
  1989. */
  1990. lpfc_sli_hba_down(phba);
  1991. lpfc_sli_brdrestart(phba);
  1992. lpfc_stop_phba_timers(phba);
  1993. spin_lock_irq(&phba->hbalock);
  1994. list_del_init(&vport->listentry);
  1995. spin_unlock_irq(&phba->hbalock);
  1996. lpfc_debugfs_terminate(vport);
  1997. /* Release the irq reservation */
  1998. free_irq(phba->pcidev->irq, phba);
  1999. if (phba->using_msi)
  2000. pci_disable_msi(phba->pcidev);
  2001. pci_set_drvdata(pdev, NULL);
  2002. scsi_host_put(shost);
  2003. /*
  2004. * Call scsi_free before mem_free since scsi bufs are released to their
  2005. * corresponding pools here.
  2006. */
  2007. lpfc_scsi_free(phba);
  2008. lpfc_mem_free(phba);
  2009. dma_free_coherent(&pdev->dev, lpfc_sli_hbq_size(), phba->hbqslimp.virt,
  2010. phba->hbqslimp.phys);
  2011. /* Free resources associated with SLI2 interface */
  2012. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  2013. phba->slim2p, phba->slim2p_mapping);
  2014. /* unmap adapter SLIM and Control Registers */
  2015. iounmap(phba->ctrl_regs_memmap_p);
  2016. iounmap(phba->slim_memmap_p);
  2017. idr_remove(&lpfc_hba_index, phba->brd_no);
  2018. kfree(phba);
  2019. pci_release_selected_regions(pdev, bars);
  2020. pci_disable_device(pdev);
  2021. }
  2022. /**
  2023. * lpfc_io_error_detected - called when PCI error is detected
  2024. * @pdev: Pointer to PCI device
  2025. * @state: The current pci conneection state
  2026. *
  2027. * This function is called after a PCI bus error affecting
  2028. * this device has been detected.
  2029. */
  2030. static pci_ers_result_t lpfc_io_error_detected(struct pci_dev *pdev,
  2031. pci_channel_state_t state)
  2032. {
  2033. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2034. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2035. struct lpfc_sli *psli = &phba->sli;
  2036. struct lpfc_sli_ring *pring;
  2037. if (state == pci_channel_io_perm_failure)
  2038. return PCI_ERS_RESULT_DISCONNECT;
  2039. pci_disable_device(pdev);
  2040. /*
  2041. * There may be I/Os dropped by the firmware.
  2042. * Error iocb (I/O) on txcmplq and let the SCSI layer
  2043. * retry it after re-establishing link.
  2044. */
  2045. pring = &psli->ring[psli->fcp_ring];
  2046. lpfc_sli_abort_iocb_ring(phba, pring);
  2047. /* Release the irq reservation */
  2048. free_irq(phba->pcidev->irq, phba);
  2049. if (phba->using_msi)
  2050. pci_disable_msi(phba->pcidev);
  2051. /* Request a slot reset. */
  2052. return PCI_ERS_RESULT_NEED_RESET;
  2053. }
  2054. /**
  2055. * lpfc_io_slot_reset - called after the pci bus has been reset.
  2056. * @pdev: Pointer to PCI device
  2057. *
  2058. * Restart the card from scratch, as if from a cold-boot.
  2059. */
  2060. static pci_ers_result_t lpfc_io_slot_reset(struct pci_dev *pdev)
  2061. {
  2062. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2063. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2064. struct lpfc_sli *psli = &phba->sli;
  2065. dev_printk(KERN_INFO, &pdev->dev, "recovering from a slot reset.\n");
  2066. if (pci_enable_device_mem(pdev)) {
  2067. printk(KERN_ERR "lpfc: Cannot re-enable "
  2068. "PCI device after reset.\n");
  2069. return PCI_ERS_RESULT_DISCONNECT;
  2070. }
  2071. pci_set_master(pdev);
  2072. /* Re-establishing Link */
  2073. spin_lock_irq(shost->host_lock);
  2074. phba->pport->fc_flag |= FC_ESTABLISH_LINK;
  2075. spin_unlock_irq(shost->host_lock);
  2076. spin_lock_irq(&phba->hbalock);
  2077. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  2078. spin_unlock_irq(&phba->hbalock);
  2079. /* Take device offline; this will perform cleanup */
  2080. lpfc_offline(phba);
  2081. lpfc_sli_brdrestart(phba);
  2082. return PCI_ERS_RESULT_RECOVERED;
  2083. }
  2084. /**
  2085. * lpfc_io_resume - called when traffic can start flowing again.
  2086. * @pdev: Pointer to PCI device
  2087. *
  2088. * This callback is called when the error recovery driver tells us that
  2089. * its OK to resume normal operation.
  2090. */
  2091. static void lpfc_io_resume(struct pci_dev *pdev)
  2092. {
  2093. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  2094. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  2095. if (lpfc_online(phba) == 0) {
  2096. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  2097. }
  2098. }
  2099. static struct pci_device_id lpfc_id_table[] = {
  2100. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  2101. PCI_ANY_ID, PCI_ANY_ID, },
  2102. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  2103. PCI_ANY_ID, PCI_ANY_ID, },
  2104. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  2105. PCI_ANY_ID, PCI_ANY_ID, },
  2106. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  2107. PCI_ANY_ID, PCI_ANY_ID, },
  2108. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  2109. PCI_ANY_ID, PCI_ANY_ID, },
  2110. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  2111. PCI_ANY_ID, PCI_ANY_ID, },
  2112. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  2113. PCI_ANY_ID, PCI_ANY_ID, },
  2114. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  2115. PCI_ANY_ID, PCI_ANY_ID, },
  2116. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  2117. PCI_ANY_ID, PCI_ANY_ID, },
  2118. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  2119. PCI_ANY_ID, PCI_ANY_ID, },
  2120. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  2121. PCI_ANY_ID, PCI_ANY_ID, },
  2122. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  2123. PCI_ANY_ID, PCI_ANY_ID, },
  2124. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  2125. PCI_ANY_ID, PCI_ANY_ID, },
  2126. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  2127. PCI_ANY_ID, PCI_ANY_ID, },
  2128. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  2129. PCI_ANY_ID, PCI_ANY_ID, },
  2130. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  2131. PCI_ANY_ID, PCI_ANY_ID, },
  2132. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  2133. PCI_ANY_ID, PCI_ANY_ID, },
  2134. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  2135. PCI_ANY_ID, PCI_ANY_ID, },
  2136. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  2137. PCI_ANY_ID, PCI_ANY_ID, },
  2138. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  2139. PCI_ANY_ID, PCI_ANY_ID, },
  2140. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  2141. PCI_ANY_ID, PCI_ANY_ID, },
  2142. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  2143. PCI_ANY_ID, PCI_ANY_ID, },
  2144. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  2145. PCI_ANY_ID, PCI_ANY_ID, },
  2146. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  2147. PCI_ANY_ID, PCI_ANY_ID, },
  2148. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  2149. PCI_ANY_ID, PCI_ANY_ID, },
  2150. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  2151. PCI_ANY_ID, PCI_ANY_ID, },
  2152. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  2153. PCI_ANY_ID, PCI_ANY_ID, },
  2154. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
  2155. PCI_ANY_ID, PCI_ANY_ID, },
  2156. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
  2157. PCI_ANY_ID, PCI_ANY_ID, },
  2158. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
  2159. PCI_ANY_ID, PCI_ANY_ID, },
  2160. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
  2161. PCI_ANY_ID, PCI_ANY_ID, },
  2162. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
  2163. PCI_ANY_ID, PCI_ANY_ID, },
  2164. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
  2165. PCI_ANY_ID, PCI_ANY_ID, },
  2166. { 0 }
  2167. };
  2168. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  2169. static struct pci_error_handlers lpfc_err_handler = {
  2170. .error_detected = lpfc_io_error_detected,
  2171. .slot_reset = lpfc_io_slot_reset,
  2172. .resume = lpfc_io_resume,
  2173. };
  2174. static struct pci_driver lpfc_driver = {
  2175. .name = LPFC_DRIVER_NAME,
  2176. .id_table = lpfc_id_table,
  2177. .probe = lpfc_pci_probe_one,
  2178. .remove = __devexit_p(lpfc_pci_remove_one),
  2179. .err_handler = &lpfc_err_handler,
  2180. };
  2181. static int __init
  2182. lpfc_init(void)
  2183. {
  2184. int error = 0;
  2185. printk(LPFC_MODULE_DESC "\n");
  2186. printk(LPFC_COPYRIGHT "\n");
  2187. if (lpfc_enable_npiv) {
  2188. lpfc_transport_functions.vport_create = lpfc_vport_create;
  2189. lpfc_transport_functions.vport_delete = lpfc_vport_delete;
  2190. }
  2191. lpfc_transport_template =
  2192. fc_attach_transport(&lpfc_transport_functions);
  2193. if (lpfc_transport_template == NULL)
  2194. return -ENOMEM;
  2195. if (lpfc_enable_npiv) {
  2196. lpfc_vport_transport_template =
  2197. fc_attach_transport(&lpfc_vport_transport_functions);
  2198. if (lpfc_vport_transport_template == NULL) {
  2199. fc_release_transport(lpfc_transport_template);
  2200. return -ENOMEM;
  2201. }
  2202. }
  2203. error = pci_register_driver(&lpfc_driver);
  2204. if (error) {
  2205. fc_release_transport(lpfc_transport_template);
  2206. fc_release_transport(lpfc_vport_transport_template);
  2207. }
  2208. return error;
  2209. }
  2210. static void __exit
  2211. lpfc_exit(void)
  2212. {
  2213. pci_unregister_driver(&lpfc_driver);
  2214. fc_release_transport(lpfc_transport_template);
  2215. if (lpfc_enable_npiv)
  2216. fc_release_transport(lpfc_vport_transport_template);
  2217. }
  2218. module_init(lpfc_init);
  2219. module_exit(lpfc_exit);
  2220. MODULE_LICENSE("GPL");
  2221. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  2222. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  2223. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);