lpfc_init.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2006 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 <scsi/scsi.h>
  30. #include <scsi/scsi_device.h>
  31. #include <scsi/scsi_host.h>
  32. #include <scsi/scsi_transport_fc.h>
  33. #include "lpfc_hw.h"
  34. #include "lpfc_sli.h"
  35. #include "lpfc_disc.h"
  36. #include "lpfc_scsi.h"
  37. #include "lpfc.h"
  38. #include "lpfc_logmsg.h"
  39. #include "lpfc_crtn.h"
  40. #include "lpfc_version.h"
  41. static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
  42. static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
  43. static int lpfc_post_rcv_buf(struct lpfc_hba *);
  44. static struct scsi_transport_template *lpfc_transport_template = NULL;
  45. static DEFINE_IDR(lpfc_hba_index);
  46. /************************************************************************/
  47. /* */
  48. /* lpfc_config_port_prep */
  49. /* This routine will do LPFC initialization prior to the */
  50. /* CONFIG_PORT mailbox command. This will be initialized */
  51. /* as a SLI layer callback routine. */
  52. /* This routine returns 0 on success or -ERESTART if it wants */
  53. /* the SLI layer to reset the HBA and try again. Any */
  54. /* other return value indicates an error. */
  55. /* */
  56. /************************************************************************/
  57. int
  58. lpfc_config_port_prep(struct lpfc_hba * phba)
  59. {
  60. lpfc_vpd_t *vp = &phba->vpd;
  61. int i = 0, rc;
  62. LPFC_MBOXQ_t *pmb;
  63. MAILBOX_t *mb;
  64. char *lpfc_vpd_data = NULL;
  65. uint16_t offset = 0;
  66. static char licensed[56] =
  67. "key unlock for use with gnu public licensed code only\0";
  68. static int init_key = 1;
  69. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  70. if (!pmb) {
  71. phba->hba_state = LPFC_HBA_ERROR;
  72. return -ENOMEM;
  73. }
  74. mb = &pmb->mb;
  75. phba->hba_state = LPFC_INIT_MBX_CMDS;
  76. if (lpfc_is_LC_HBA(phba->pcidev->device)) {
  77. if (init_key) {
  78. uint32_t *ptext = (uint32_t *) licensed;
  79. for (i = 0; i < 56; i += sizeof (uint32_t), ptext++)
  80. *ptext = cpu_to_be32(*ptext);
  81. init_key = 0;
  82. }
  83. lpfc_read_nv(phba, pmb);
  84. memset((char*)mb->un.varRDnvp.rsvd3, 0,
  85. sizeof (mb->un.varRDnvp.rsvd3));
  86. memcpy((char*)mb->un.varRDnvp.rsvd3, licensed,
  87. sizeof (licensed));
  88. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  89. if (rc != MBX_SUCCESS) {
  90. lpfc_printf_log(phba,
  91. KERN_ERR,
  92. LOG_MBOX,
  93. "%d:0324 Config Port initialization "
  94. "error, mbxCmd x%x READ_NVPARM, "
  95. "mbxStatus x%x\n",
  96. phba->brd_no,
  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 (mb->un.varRDnvp.nodename));
  103. }
  104. /* Setup and issue mailbox READ REV command */
  105. lpfc_read_rev(phba, pmb);
  106. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  107. if (rc != MBX_SUCCESS) {
  108. lpfc_printf_log(phba,
  109. KERN_ERR,
  110. LOG_INIT,
  111. "%d:0439 Adapter failed to init, mbxCmd x%x "
  112. "READ_REV, mbxStatus x%x\n",
  113. phba->brd_no,
  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. "%d:0440 Adapter failed to init, READ_REV has "
  126. "missing revision information.\n",
  127. phba->brd_no);
  128. mempool_free(pmb, phba->mbox_mem_pool);
  129. return -ERESTART;
  130. }
  131. /* Save information as VPD data */
  132. vp->rev.rBit = 1;
  133. vp->rev.sli1FwRev = mb->un.varRdRev.sli1FwRev;
  134. memcpy(vp->rev.sli1FwName, (char*) mb->un.varRdRev.sli1FwName, 16);
  135. vp->rev.sli2FwRev = mb->un.varRdRev.sli2FwRev;
  136. memcpy(vp->rev.sli2FwName, (char *) mb->un.varRdRev.sli2FwName, 16);
  137. vp->rev.biuRev = mb->un.varRdRev.biuRev;
  138. vp->rev.smRev = mb->un.varRdRev.smRev;
  139. vp->rev.smFwRev = mb->un.varRdRev.un.smFwRev;
  140. vp->rev.endecRev = mb->un.varRdRev.endecRev;
  141. vp->rev.fcphHigh = mb->un.varRdRev.fcphHigh;
  142. vp->rev.fcphLow = mb->un.varRdRev.fcphLow;
  143. vp->rev.feaLevelHigh = mb->un.varRdRev.feaLevelHigh;
  144. vp->rev.feaLevelLow = mb->un.varRdRev.feaLevelLow;
  145. vp->rev.postKernRev = mb->un.varRdRev.postKernRev;
  146. vp->rev.opFwRev = mb->un.varRdRev.opFwRev;
  147. if (lpfc_is_LC_HBA(phba->pcidev->device))
  148. memcpy(phba->RandomData, (char *)&mb->un.varWords[24],
  149. sizeof (phba->RandomData));
  150. /* Get adapter VPD information */
  151. pmb->context2 = kmalloc(DMP_RSP_SIZE, GFP_KERNEL);
  152. if (!pmb->context2)
  153. goto out_free_mbox;
  154. lpfc_vpd_data = kmalloc(DMP_VPD_SIZE, GFP_KERNEL);
  155. if (!lpfc_vpd_data)
  156. goto out_free_context2;
  157. do {
  158. lpfc_dump_mem(phba, pmb, offset);
  159. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  160. if (rc != MBX_SUCCESS) {
  161. lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
  162. "%d:0441 VPD not present on adapter, "
  163. "mbxCmd x%x DUMP VPD, mbxStatus x%x\n",
  164. phba->brd_no,
  165. mb->mbxCommand, mb->mbxStatus);
  166. mb->un.varDmp.word_cnt = 0;
  167. }
  168. if (mb->un.varDmp.word_cnt > DMP_VPD_SIZE - offset)
  169. mb->un.varDmp.word_cnt = DMP_VPD_SIZE - offset;
  170. lpfc_sli_pcimem_bcopy(pmb->context2, lpfc_vpd_data + offset,
  171. mb->un.varDmp.word_cnt);
  172. offset += mb->un.varDmp.word_cnt;
  173. } while (mb->un.varDmp.word_cnt && offset < DMP_VPD_SIZE);
  174. lpfc_parse_vpd(phba, lpfc_vpd_data, offset);
  175. kfree(lpfc_vpd_data);
  176. out_free_context2:
  177. kfree(pmb->context2);
  178. out_free_mbox:
  179. mempool_free(pmb, phba->mbox_mem_pool);
  180. return 0;
  181. }
  182. /************************************************************************/
  183. /* */
  184. /* lpfc_config_port_post */
  185. /* This routine will do LPFC initialization after the */
  186. /* CONFIG_PORT mailbox command. This will be initialized */
  187. /* as a SLI layer callback routine. */
  188. /* This routine returns 0 on success. Any other return value */
  189. /* indicates an error. */
  190. /* */
  191. /************************************************************************/
  192. int
  193. lpfc_config_port_post(struct lpfc_hba * phba)
  194. {
  195. LPFC_MBOXQ_t *pmb;
  196. MAILBOX_t *mb;
  197. struct lpfc_dmabuf *mp;
  198. struct lpfc_sli *psli = &phba->sli;
  199. uint32_t status, timeout;
  200. int i, j, rc;
  201. pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  202. if (!pmb) {
  203. phba->hba_state = LPFC_HBA_ERROR;
  204. return -ENOMEM;
  205. }
  206. mb = &pmb->mb;
  207. lpfc_config_link(phba, pmb);
  208. rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
  209. if (rc != MBX_SUCCESS) {
  210. lpfc_printf_log(phba,
  211. KERN_ERR,
  212. LOG_INIT,
  213. "%d:0447 Adapter failed init, mbxCmd x%x "
  214. "CONFIG_LINK mbxStatus x%x\n",
  215. phba->brd_no,
  216. mb->mbxCommand, mb->mbxStatus);
  217. phba->hba_state = LPFC_HBA_ERROR;
  218. mempool_free( pmb, phba->mbox_mem_pool);
  219. return -EIO;
  220. }
  221. /* Get login parameters for NID. */
  222. lpfc_read_sparam(phba, pmb);
  223. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  224. lpfc_printf_log(phba,
  225. KERN_ERR,
  226. LOG_INIT,
  227. "%d:0448 Adapter failed init, mbxCmd x%x "
  228. "READ_SPARM mbxStatus x%x\n",
  229. phba->brd_no,
  230. mb->mbxCommand, mb->mbxStatus);
  231. phba->hba_state = LPFC_HBA_ERROR;
  232. mp = (struct lpfc_dmabuf *) pmb->context1;
  233. mempool_free( pmb, phba->mbox_mem_pool);
  234. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  235. kfree(mp);
  236. return -EIO;
  237. }
  238. mp = (struct lpfc_dmabuf *) pmb->context1;
  239. memcpy(&phba->fc_sparam, mp->virt, sizeof (struct serv_parm));
  240. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  241. kfree(mp);
  242. pmb->context1 = NULL;
  243. if (phba->cfg_soft_wwpn)
  244. u64_to_wwn(phba->cfg_soft_wwpn, phba->fc_sparam.portName.u.wwn);
  245. memcpy(&phba->fc_nodename, &phba->fc_sparam.nodeName,
  246. sizeof (struct lpfc_name));
  247. memcpy(&phba->fc_portname, &phba->fc_sparam.portName,
  248. sizeof (struct lpfc_name));
  249. /* If no serial number in VPD data, use low 6 bytes of WWNN */
  250. /* This should be consolidated into parse_vpd ? - mr */
  251. if (phba->SerialNumber[0] == 0) {
  252. uint8_t *outptr;
  253. outptr = &phba->fc_nodename.u.s.IEEE[0];
  254. for (i = 0; i < 12; i++) {
  255. status = *outptr++;
  256. j = ((status & 0xf0) >> 4);
  257. if (j <= 9)
  258. phba->SerialNumber[i] =
  259. (char)((uint8_t) 0x30 + (uint8_t) j);
  260. else
  261. phba->SerialNumber[i] =
  262. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  263. i++;
  264. j = (status & 0xf);
  265. if (j <= 9)
  266. phba->SerialNumber[i] =
  267. (char)((uint8_t) 0x30 + (uint8_t) j);
  268. else
  269. phba->SerialNumber[i] =
  270. (char)((uint8_t) 0x61 + (uint8_t) (j - 10));
  271. }
  272. }
  273. lpfc_read_config(phba, pmb);
  274. if (lpfc_sli_issue_mbox(phba, pmb, MBX_POLL) != MBX_SUCCESS) {
  275. lpfc_printf_log(phba,
  276. KERN_ERR,
  277. LOG_INIT,
  278. "%d:0453 Adapter failed to init, mbxCmd x%x "
  279. "READ_CONFIG, mbxStatus x%x\n",
  280. phba->brd_no,
  281. mb->mbxCommand, mb->mbxStatus);
  282. phba->hba_state = LPFC_HBA_ERROR;
  283. mempool_free( pmb, phba->mbox_mem_pool);
  284. return -EIO;
  285. }
  286. /* Reset the DFT_HBA_Q_DEPTH to the max xri */
  287. if (phba->cfg_hba_queue_depth > (mb->un.varRdConfig.max_xri+1))
  288. phba->cfg_hba_queue_depth =
  289. mb->un.varRdConfig.max_xri + 1;
  290. phba->lmt = mb->un.varRdConfig.lmt;
  291. /* Get the default values for Model Name and Description */
  292. lpfc_get_hba_model_desc(phba, phba->ModelName, phba->ModelDesc);
  293. if ((phba->cfg_link_speed > LINK_SPEED_10G)
  294. || ((phba->cfg_link_speed == LINK_SPEED_1G)
  295. && !(phba->lmt & LMT_1Gb))
  296. || ((phba->cfg_link_speed == LINK_SPEED_2G)
  297. && !(phba->lmt & LMT_2Gb))
  298. || ((phba->cfg_link_speed == LINK_SPEED_4G)
  299. && !(phba->lmt & LMT_4Gb))
  300. || ((phba->cfg_link_speed == LINK_SPEED_8G)
  301. && !(phba->lmt & LMT_8Gb))
  302. || ((phba->cfg_link_speed == LINK_SPEED_10G)
  303. && !(phba->lmt & LMT_10Gb))) {
  304. /* Reset link speed to auto */
  305. lpfc_printf_log(phba,
  306. KERN_WARNING,
  307. LOG_LINK_EVENT,
  308. "%d:1302 Invalid speed for this board: "
  309. "Reset link speed to auto: x%x\n",
  310. phba->brd_no,
  311. phba->cfg_link_speed);
  312. phba->cfg_link_speed = LINK_SPEED_AUTO;
  313. }
  314. phba->hba_state = LPFC_LINK_DOWN;
  315. /* Only process IOCBs on ring 0 till hba_state is READY */
  316. if (psli->ring[psli->ip_ring].cmdringaddr)
  317. psli->ring[psli->ip_ring].flag |= LPFC_STOP_IOCB_EVENT;
  318. if (psli->ring[psli->fcp_ring].cmdringaddr)
  319. psli->ring[psli->fcp_ring].flag |= LPFC_STOP_IOCB_EVENT;
  320. if (psli->ring[psli->next_ring].cmdringaddr)
  321. psli->ring[psli->next_ring].flag |= LPFC_STOP_IOCB_EVENT;
  322. /* Post receive buffers for desired rings */
  323. lpfc_post_rcv_buf(phba);
  324. /* Enable appropriate host interrupts */
  325. spin_lock_irq(phba->host->host_lock);
  326. status = readl(phba->HCregaddr);
  327. status |= HC_MBINT_ENA | HC_ERINT_ENA | HC_LAINT_ENA;
  328. if (psli->num_rings > 0)
  329. status |= HC_R0INT_ENA;
  330. if (psli->num_rings > 1)
  331. status |= HC_R1INT_ENA;
  332. if (psli->num_rings > 2)
  333. status |= HC_R2INT_ENA;
  334. if (psli->num_rings > 3)
  335. status |= HC_R3INT_ENA;
  336. if ((phba->cfg_poll & ENABLE_FCP_RING_POLLING) &&
  337. (phba->cfg_poll & DISABLE_FCP_RING_INT))
  338. status &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  339. writel(status, phba->HCregaddr);
  340. readl(phba->HCregaddr); /* flush */
  341. spin_unlock_irq(phba->host->host_lock);
  342. /*
  343. * Setup the ring 0 (els) timeout handler
  344. */
  345. timeout = phba->fc_ratov << 1;
  346. phba->els_tmofunc.expires = jiffies + HZ * timeout;
  347. add_timer(&phba->els_tmofunc);
  348. lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
  349. pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  350. if (lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT) != MBX_SUCCESS) {
  351. lpfc_printf_log(phba,
  352. KERN_ERR,
  353. LOG_INIT,
  354. "%d:0454 Adapter failed to init, mbxCmd x%x "
  355. "INIT_LINK, mbxStatus x%x\n",
  356. phba->brd_no,
  357. mb->mbxCommand, mb->mbxStatus);
  358. /* Clear all interrupt enable conditions */
  359. writel(0, phba->HCregaddr);
  360. readl(phba->HCregaddr); /* flush */
  361. /* Clear all pending interrupts */
  362. writel(0xffffffff, phba->HAregaddr);
  363. readl(phba->HAregaddr); /* flush */
  364. phba->hba_state = LPFC_HBA_ERROR;
  365. mempool_free(pmb, phba->mbox_mem_pool);
  366. return -EIO;
  367. }
  368. /* MBOX buffer will be freed in mbox compl */
  369. return (0);
  370. }
  371. static int
  372. lpfc_discovery_wait(struct lpfc_hba *phba)
  373. {
  374. int i = 0;
  375. while ((phba->hba_state != LPFC_HBA_READY) ||
  376. (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
  377. ((phba->fc_map_cnt == 0) && (i<2)) ||
  378. (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
  379. /* Check every second for 30 retries. */
  380. i++;
  381. if (i > 30) {
  382. return -ETIMEDOUT;
  383. }
  384. if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
  385. /* The link is down. Set linkdown timeout */
  386. return -ETIMEDOUT;
  387. }
  388. /* Delay for 1 second to give discovery time to complete. */
  389. msleep(1000);
  390. }
  391. return 0;
  392. }
  393. /************************************************************************/
  394. /* */
  395. /* lpfc_hba_down_prep */
  396. /* This routine will do LPFC uninitialization before the */
  397. /* HBA is reset when bringing down the SLI Layer. This will be */
  398. /* initialized as a SLI layer callback routine. */
  399. /* This routine returns 0 on success. Any other return value */
  400. /* indicates an error. */
  401. /* */
  402. /************************************************************************/
  403. int
  404. lpfc_hba_down_prep(struct lpfc_hba * phba)
  405. {
  406. /* Disable interrupts */
  407. writel(0, phba->HCregaddr);
  408. readl(phba->HCregaddr); /* flush */
  409. /* Cleanup potential discovery resources */
  410. lpfc_els_flush_rscn(phba);
  411. lpfc_els_flush_cmd(phba);
  412. lpfc_disc_flush_list(phba);
  413. return (0);
  414. }
  415. /************************************************************************/
  416. /* */
  417. /* lpfc_hba_down_post */
  418. /* This routine will do uninitialization after the HBA is reset */
  419. /* when bringing down the SLI Layer. */
  420. /* This routine returns 0 on success. Any other return value */
  421. /* indicates an error. */
  422. /* */
  423. /************************************************************************/
  424. int
  425. lpfc_hba_down_post(struct lpfc_hba * phba)
  426. {
  427. struct lpfc_sli *psli = &phba->sli;
  428. struct lpfc_sli_ring *pring;
  429. struct lpfc_dmabuf *mp, *next_mp;
  430. int i;
  431. /* Cleanup preposted buffers on the ELS ring */
  432. pring = &psli->ring[LPFC_ELS_RING];
  433. list_for_each_entry_safe(mp, next_mp, &pring->postbufq, list) {
  434. list_del(&mp->list);
  435. pring->postbufq_cnt--;
  436. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  437. kfree(mp);
  438. }
  439. for (i = 0; i < psli->num_rings; i++) {
  440. pring = &psli->ring[i];
  441. lpfc_sli_abort_iocb_ring(phba, pring);
  442. }
  443. return 0;
  444. }
  445. /************************************************************************/
  446. /* */
  447. /* lpfc_handle_eratt */
  448. /* This routine will handle processing a Host Attention */
  449. /* Error Status event. This will be initialized */
  450. /* as a SLI layer callback routine. */
  451. /* */
  452. /************************************************************************/
  453. void
  454. lpfc_handle_eratt(struct lpfc_hba * phba)
  455. {
  456. struct lpfc_sli *psli = &phba->sli;
  457. struct lpfc_sli_ring *pring;
  458. uint32_t event_data;
  459. if (phba->work_hs & HS_FFER6) {
  460. /* Re-establishing Link */
  461. lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
  462. "%d:1301 Re-establishing Link "
  463. "Data: x%x x%x x%x\n",
  464. phba->brd_no, phba->work_hs,
  465. phba->work_status[0], phba->work_status[1]);
  466. spin_lock_irq(phba->host->host_lock);
  467. phba->fc_flag |= FC_ESTABLISH_LINK;
  468. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  469. spin_unlock_irq(phba->host->host_lock);
  470. /*
  471. * Firmware stops when it triggled erratt with HS_FFER6.
  472. * That could cause the I/Os dropped by the firmware.
  473. * Error iocb (I/O) on txcmplq and let the SCSI layer
  474. * retry it after re-establishing link.
  475. */
  476. pring = &psli->ring[psli->fcp_ring];
  477. lpfc_sli_abort_iocb_ring(phba, pring);
  478. /*
  479. * There was a firmware error. Take the hba offline and then
  480. * attempt to restart it.
  481. */
  482. lpfc_offline(phba);
  483. lpfc_sli_brdrestart(phba);
  484. if (lpfc_online(phba) == 0) { /* Initialize the HBA */
  485. mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
  486. return;
  487. }
  488. } else {
  489. /* The if clause above forces this code path when the status
  490. * failure is a value other than FFER6. Do not call the offline
  491. * twice. This is the adapter hardware error path.
  492. */
  493. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  494. "%d:0457 Adapter Hardware Error "
  495. "Data: x%x x%x x%x\n",
  496. phba->brd_no, phba->work_hs,
  497. phba->work_status[0], phba->work_status[1]);
  498. event_data = FC_REG_DUMP_EVENT;
  499. fc_host_post_vendor_event(phba->host, fc_get_event_number(),
  500. sizeof(event_data), (char *) &event_data,
  501. SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
  502. psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
  503. lpfc_offline(phba);
  504. phba->hba_state = LPFC_HBA_ERROR;
  505. lpfc_hba_down_post(phba);
  506. }
  507. }
  508. /************************************************************************/
  509. /* */
  510. /* lpfc_handle_latt */
  511. /* This routine will handle processing a Host Attention */
  512. /* Link Status event. This will be initialized */
  513. /* as a SLI layer callback routine. */
  514. /* */
  515. /************************************************************************/
  516. void
  517. lpfc_handle_latt(struct lpfc_hba * phba)
  518. {
  519. struct lpfc_sli *psli = &phba->sli;
  520. LPFC_MBOXQ_t *pmb;
  521. volatile uint32_t control;
  522. struct lpfc_dmabuf *mp;
  523. int rc = -ENOMEM;
  524. pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  525. if (!pmb)
  526. goto lpfc_handle_latt_err_exit;
  527. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  528. if (!mp)
  529. goto lpfc_handle_latt_free_pmb;
  530. mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
  531. if (!mp->virt)
  532. goto lpfc_handle_latt_free_mp;
  533. rc = -EIO;
  534. /* Cleanup any outstanding ELS commands */
  535. lpfc_els_flush_cmd(phba);
  536. psli->slistat.link_event++;
  537. lpfc_read_la(phba, pmb, mp);
  538. pmb->mbox_cmpl = lpfc_mbx_cmpl_read_la;
  539. rc = lpfc_sli_issue_mbox (phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
  540. if (rc == MBX_NOT_FINISHED)
  541. goto lpfc_handle_latt_free_mp;
  542. /* Clear Link Attention in HA REG */
  543. spin_lock_irq(phba->host->host_lock);
  544. writel(HA_LATT, phba->HAregaddr);
  545. readl(phba->HAregaddr); /* flush */
  546. spin_unlock_irq(phba->host->host_lock);
  547. return;
  548. lpfc_handle_latt_free_mp:
  549. kfree(mp);
  550. lpfc_handle_latt_free_pmb:
  551. kfree(pmb);
  552. lpfc_handle_latt_err_exit:
  553. /* Enable Link attention interrupts */
  554. spin_lock_irq(phba->host->host_lock);
  555. psli->sli_flag |= LPFC_PROCESS_LA;
  556. control = readl(phba->HCregaddr);
  557. control |= HC_LAINT_ENA;
  558. writel(control, phba->HCregaddr);
  559. readl(phba->HCregaddr); /* flush */
  560. /* Clear Link Attention in HA REG */
  561. writel(HA_LATT, phba->HAregaddr);
  562. readl(phba->HAregaddr); /* flush */
  563. spin_unlock_irq(phba->host->host_lock);
  564. lpfc_linkdown(phba);
  565. phba->hba_state = LPFC_HBA_ERROR;
  566. /* The other case is an error from issue_mbox */
  567. if (rc == -ENOMEM)
  568. lpfc_printf_log(phba,
  569. KERN_WARNING,
  570. LOG_MBOX,
  571. "%d:0300 READ_LA: no buffers\n",
  572. phba->brd_no);
  573. return;
  574. }
  575. /************************************************************************/
  576. /* */
  577. /* lpfc_parse_vpd */
  578. /* This routine will parse the VPD data */
  579. /* */
  580. /************************************************************************/
  581. static int
  582. lpfc_parse_vpd(struct lpfc_hba * phba, uint8_t * vpd, int len)
  583. {
  584. uint8_t lenlo, lenhi;
  585. uint32_t Length;
  586. int i, j;
  587. int finished = 0;
  588. int index = 0;
  589. if (!vpd)
  590. return 0;
  591. /* Vital Product */
  592. lpfc_printf_log(phba,
  593. KERN_INFO,
  594. LOG_INIT,
  595. "%d:0455 Vital Product Data: x%x x%x x%x x%x\n",
  596. phba->brd_no,
  597. (uint32_t) vpd[0], (uint32_t) vpd[1], (uint32_t) vpd[2],
  598. (uint32_t) vpd[3]);
  599. while (!finished && (index < (len - 4))) {
  600. switch (vpd[index]) {
  601. case 0x82:
  602. case 0x91:
  603. index += 1;
  604. lenlo = vpd[index];
  605. index += 1;
  606. lenhi = vpd[index];
  607. index += 1;
  608. i = ((((unsigned short)lenhi) << 8) + lenlo);
  609. index += i;
  610. break;
  611. case 0x90:
  612. index += 1;
  613. lenlo = vpd[index];
  614. index += 1;
  615. lenhi = vpd[index];
  616. index += 1;
  617. Length = ((((unsigned short)lenhi) << 8) + lenlo);
  618. if (Length > len - index)
  619. Length = len - index;
  620. while (Length > 0) {
  621. /* Look for Serial Number */
  622. if ((vpd[index] == 'S') && (vpd[index+1] == 'N')) {
  623. index += 2;
  624. i = vpd[index];
  625. index += 1;
  626. j = 0;
  627. Length -= (3+i);
  628. while(i--) {
  629. phba->SerialNumber[j++] = vpd[index++];
  630. if (j == 31)
  631. break;
  632. }
  633. phba->SerialNumber[j] = 0;
  634. continue;
  635. }
  636. else if ((vpd[index] == 'V') && (vpd[index+1] == '1')) {
  637. phba->vpd_flag |= VPD_MODEL_DESC;
  638. index += 2;
  639. i = vpd[index];
  640. index += 1;
  641. j = 0;
  642. Length -= (3+i);
  643. while(i--) {
  644. phba->ModelDesc[j++] = vpd[index++];
  645. if (j == 255)
  646. break;
  647. }
  648. phba->ModelDesc[j] = 0;
  649. continue;
  650. }
  651. else if ((vpd[index] == 'V') && (vpd[index+1] == '2')) {
  652. phba->vpd_flag |= VPD_MODEL_NAME;
  653. index += 2;
  654. i = vpd[index];
  655. index += 1;
  656. j = 0;
  657. Length -= (3+i);
  658. while(i--) {
  659. phba->ModelName[j++] = vpd[index++];
  660. if (j == 79)
  661. break;
  662. }
  663. phba->ModelName[j] = 0;
  664. continue;
  665. }
  666. else if ((vpd[index] == 'V') && (vpd[index+1] == '3')) {
  667. phba->vpd_flag |= VPD_PROGRAM_TYPE;
  668. index += 2;
  669. i = vpd[index];
  670. index += 1;
  671. j = 0;
  672. Length -= (3+i);
  673. while(i--) {
  674. phba->ProgramType[j++] = vpd[index++];
  675. if (j == 255)
  676. break;
  677. }
  678. phba->ProgramType[j] = 0;
  679. continue;
  680. }
  681. else if ((vpd[index] == 'V') && (vpd[index+1] == '4')) {
  682. phba->vpd_flag |= VPD_PORT;
  683. index += 2;
  684. i = vpd[index];
  685. index += 1;
  686. j = 0;
  687. Length -= (3+i);
  688. while(i--) {
  689. phba->Port[j++] = vpd[index++];
  690. if (j == 19)
  691. break;
  692. }
  693. phba->Port[j] = 0;
  694. continue;
  695. }
  696. else {
  697. index += 2;
  698. i = vpd[index];
  699. index += 1;
  700. index += i;
  701. Length -= (3 + i);
  702. }
  703. }
  704. finished = 0;
  705. break;
  706. case 0x78:
  707. finished = 1;
  708. break;
  709. default:
  710. index ++;
  711. break;
  712. }
  713. }
  714. return(1);
  715. }
  716. static void
  717. lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
  718. {
  719. lpfc_vpd_t *vp;
  720. uint16_t dev_id = phba->pcidev->device;
  721. uint16_t dev_subid = phba->pcidev->subsystem_device;
  722. uint8_t hdrtype;
  723. int max_speed;
  724. char * ports;
  725. struct {
  726. char * name;
  727. int max_speed;
  728. char * ports;
  729. char * bus;
  730. } m = {"<Unknown>", 0, "", ""};
  731. pci_read_config_byte(phba->pcidev, PCI_HEADER_TYPE, &hdrtype);
  732. ports = (hdrtype == 0x80) ? "2-port " : "";
  733. if (mdp && mdp[0] != '\0'
  734. && descp && descp[0] != '\0')
  735. return;
  736. if (phba->lmt & LMT_10Gb)
  737. max_speed = 10;
  738. else if (phba->lmt & LMT_8Gb)
  739. max_speed = 8;
  740. else if (phba->lmt & LMT_4Gb)
  741. max_speed = 4;
  742. else if (phba->lmt & LMT_2Gb)
  743. max_speed = 2;
  744. else
  745. max_speed = 1;
  746. vp = &phba->vpd;
  747. switch (dev_id) {
  748. case PCI_DEVICE_ID_FIREFLY:
  749. m = (typeof(m)){"LP6000", max_speed, "", "PCI"};
  750. break;
  751. case PCI_DEVICE_ID_SUPERFLY:
  752. if (vp->rev.biuRev >= 1 && vp->rev.biuRev <= 3)
  753. m = (typeof(m)){"LP7000", max_speed, "", "PCI"};
  754. else
  755. m = (typeof(m)){"LP7000E", max_speed, "", "PCI"};
  756. break;
  757. case PCI_DEVICE_ID_DRAGONFLY:
  758. m = (typeof(m)){"LP8000", max_speed, "", "PCI"};
  759. break;
  760. case PCI_DEVICE_ID_CENTAUR:
  761. if (FC_JEDEC_ID(vp->rev.biuRev) == CENTAUR_2G_JEDEC_ID)
  762. m = (typeof(m)){"LP9002", max_speed, "", "PCI"};
  763. else
  764. m = (typeof(m)){"LP9000", max_speed, "", "PCI"};
  765. break;
  766. case PCI_DEVICE_ID_RFLY:
  767. m = (typeof(m)){"LP952", max_speed, "", "PCI"};
  768. break;
  769. case PCI_DEVICE_ID_PEGASUS:
  770. m = (typeof(m)){"LP9802", max_speed, "", "PCI-X"};
  771. break;
  772. case PCI_DEVICE_ID_THOR:
  773. if (hdrtype == 0x80)
  774. m = (typeof(m)){"LP10000DC",
  775. max_speed, ports, "PCI-X"};
  776. else
  777. m = (typeof(m)){"LP10000",
  778. max_speed, ports, "PCI-X"};
  779. break;
  780. case PCI_DEVICE_ID_VIPER:
  781. m = (typeof(m)){"LPX1000", max_speed, "", "PCI-X"};
  782. break;
  783. case PCI_DEVICE_ID_PFLY:
  784. m = (typeof(m)){"LP982", max_speed, "", "PCI-X"};
  785. break;
  786. case PCI_DEVICE_ID_TFLY:
  787. if (hdrtype == 0x80)
  788. m = (typeof(m)){"LP1050DC", max_speed, ports, "PCI-X"};
  789. else
  790. m = (typeof(m)){"LP1050", max_speed, ports, "PCI-X"};
  791. break;
  792. case PCI_DEVICE_ID_HELIOS:
  793. if (hdrtype == 0x80)
  794. m = (typeof(m)){"LP11002", max_speed, ports, "PCI-X2"};
  795. else
  796. m = (typeof(m)){"LP11000", max_speed, ports, "PCI-X2"};
  797. break;
  798. case PCI_DEVICE_ID_HELIOS_SCSP:
  799. m = (typeof(m)){"LP11000-SP", max_speed, ports, "PCI-X2"};
  800. break;
  801. case PCI_DEVICE_ID_HELIOS_DCSP:
  802. m = (typeof(m)){"LP11002-SP", max_speed, ports, "PCI-X2"};
  803. break;
  804. case PCI_DEVICE_ID_NEPTUNE:
  805. if (hdrtype == 0x80)
  806. m = (typeof(m)){"LPe1002", max_speed, ports, "PCIe"};
  807. else
  808. m = (typeof(m)){"LPe1000", max_speed, ports, "PCIe"};
  809. break;
  810. case PCI_DEVICE_ID_NEPTUNE_SCSP:
  811. m = (typeof(m)){"LPe1000-SP", max_speed, ports, "PCIe"};
  812. break;
  813. case PCI_DEVICE_ID_NEPTUNE_DCSP:
  814. m = (typeof(m)){"LPe1002-SP", max_speed, ports, "PCIe"};
  815. break;
  816. case PCI_DEVICE_ID_BMID:
  817. m = (typeof(m)){"LP1150", max_speed, ports, "PCI-X2"};
  818. break;
  819. case PCI_DEVICE_ID_BSMB:
  820. m = (typeof(m)){"LP111", max_speed, ports, "PCI-X2"};
  821. break;
  822. case PCI_DEVICE_ID_ZEPHYR:
  823. if (hdrtype == 0x80)
  824. m = (typeof(m)){"LPe11002", max_speed, ports, "PCIe"};
  825. else
  826. m = (typeof(m)){"LPe11000", max_speed, ports, "PCIe"};
  827. break;
  828. case PCI_DEVICE_ID_ZEPHYR_SCSP:
  829. m = (typeof(m)){"LPe11000", max_speed, ports, "PCIe"};
  830. break;
  831. case PCI_DEVICE_ID_ZEPHYR_DCSP:
  832. m = (typeof(m)){"LPe11002-SP", max_speed, ports, "PCIe"};
  833. break;
  834. case PCI_DEVICE_ID_ZMID:
  835. m = (typeof(m)){"LPe1150", max_speed, ports, "PCIe"};
  836. break;
  837. case PCI_DEVICE_ID_ZSMB:
  838. m = (typeof(m)){"LPe111", max_speed, ports, "PCIe"};
  839. break;
  840. case PCI_DEVICE_ID_LP101:
  841. m = (typeof(m)){"LP101", max_speed, ports, "PCI-X"};
  842. break;
  843. case PCI_DEVICE_ID_LP10000S:
  844. m = (typeof(m)){"LP10000-S", max_speed, ports, "PCI"};
  845. break;
  846. case PCI_DEVICE_ID_LP11000S:
  847. case PCI_DEVICE_ID_LPE11000S:
  848. switch (dev_subid) {
  849. case PCI_SUBSYSTEM_ID_LP11000S:
  850. m = (typeof(m)){"LP11000-S", max_speed,
  851. ports, "PCI-X2"};
  852. break;
  853. case PCI_SUBSYSTEM_ID_LP11002S:
  854. m = (typeof(m)){"LP11002-S", max_speed,
  855. ports, "PCI-X2"};
  856. break;
  857. case PCI_SUBSYSTEM_ID_LPE11000S:
  858. m = (typeof(m)){"LPe11000-S", max_speed,
  859. ports, "PCIe"};
  860. break;
  861. case PCI_SUBSYSTEM_ID_LPE11002S:
  862. m = (typeof(m)){"LPe11002-S", max_speed,
  863. ports, "PCIe"};
  864. break;
  865. case PCI_SUBSYSTEM_ID_LPE11010S:
  866. m = (typeof(m)){"LPe11010-S", max_speed,
  867. "10-port ", "PCIe"};
  868. break;
  869. default:
  870. m = (typeof(m)){ NULL };
  871. break;
  872. }
  873. break;
  874. default:
  875. m = (typeof(m)){ NULL };
  876. break;
  877. }
  878. if (mdp && mdp[0] == '\0')
  879. snprintf(mdp, 79,"%s", m.name);
  880. if (descp && descp[0] == '\0')
  881. snprintf(descp, 255,
  882. "Emulex %s %dGb %s%s Fibre Channel Adapter",
  883. m.name, m.max_speed, m.ports, m.bus);
  884. }
  885. /**************************************************/
  886. /* lpfc_post_buffer */
  887. /* */
  888. /* This routine will post count buffers to the */
  889. /* ring with the QUE_RING_BUF_CN command. This */
  890. /* allows 3 buffers / command to be posted. */
  891. /* Returns the number of buffers NOT posted. */
  892. /**************************************************/
  893. int
  894. lpfc_post_buffer(struct lpfc_hba * phba, struct lpfc_sli_ring * pring, int cnt,
  895. int type)
  896. {
  897. IOCB_t *icmd;
  898. struct lpfc_iocbq *iocb;
  899. struct lpfc_dmabuf *mp1, *mp2;
  900. cnt += pring->missbufcnt;
  901. /* While there are buffers to post */
  902. while (cnt > 0) {
  903. /* Allocate buffer for command iocb */
  904. spin_lock_irq(phba->host->host_lock);
  905. iocb = lpfc_sli_get_iocbq(phba);
  906. spin_unlock_irq(phba->host->host_lock);
  907. if (iocb == NULL) {
  908. pring->missbufcnt = cnt;
  909. return cnt;
  910. }
  911. icmd = &iocb->iocb;
  912. /* 2 buffers can be posted per command */
  913. /* Allocate buffer to post */
  914. mp1 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  915. if (mp1)
  916. mp1->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  917. &mp1->phys);
  918. if (mp1 == 0 || mp1->virt == 0) {
  919. kfree(mp1);
  920. spin_lock_irq(phba->host->host_lock);
  921. lpfc_sli_release_iocbq(phba, iocb);
  922. spin_unlock_irq(phba->host->host_lock);
  923. pring->missbufcnt = cnt;
  924. return cnt;
  925. }
  926. INIT_LIST_HEAD(&mp1->list);
  927. /* Allocate buffer to post */
  928. if (cnt > 1) {
  929. mp2 = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
  930. if (mp2)
  931. mp2->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
  932. &mp2->phys);
  933. if (mp2 == 0 || mp2->virt == 0) {
  934. kfree(mp2);
  935. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  936. kfree(mp1);
  937. spin_lock_irq(phba->host->host_lock);
  938. lpfc_sli_release_iocbq(phba, iocb);
  939. spin_unlock_irq(phba->host->host_lock);
  940. pring->missbufcnt = cnt;
  941. return cnt;
  942. }
  943. INIT_LIST_HEAD(&mp2->list);
  944. } else {
  945. mp2 = NULL;
  946. }
  947. icmd->un.cont64[0].addrHigh = putPaddrHigh(mp1->phys);
  948. icmd->un.cont64[0].addrLow = putPaddrLow(mp1->phys);
  949. icmd->un.cont64[0].tus.f.bdeSize = FCELSSIZE;
  950. icmd->ulpBdeCount = 1;
  951. cnt--;
  952. if (mp2) {
  953. icmd->un.cont64[1].addrHigh = putPaddrHigh(mp2->phys);
  954. icmd->un.cont64[1].addrLow = putPaddrLow(mp2->phys);
  955. icmd->un.cont64[1].tus.f.bdeSize = FCELSSIZE;
  956. cnt--;
  957. icmd->ulpBdeCount = 2;
  958. }
  959. icmd->ulpCommand = CMD_QUE_RING_BUF64_CN;
  960. icmd->ulpLe = 1;
  961. spin_lock_irq(phba->host->host_lock);
  962. if (lpfc_sli_issue_iocb(phba, pring, iocb, 0) == IOCB_ERROR) {
  963. lpfc_mbuf_free(phba, mp1->virt, mp1->phys);
  964. kfree(mp1);
  965. cnt++;
  966. if (mp2) {
  967. lpfc_mbuf_free(phba, mp2->virt, mp2->phys);
  968. kfree(mp2);
  969. cnt++;
  970. }
  971. lpfc_sli_release_iocbq(phba, iocb);
  972. pring->missbufcnt = cnt;
  973. spin_unlock_irq(phba->host->host_lock);
  974. return cnt;
  975. }
  976. spin_unlock_irq(phba->host->host_lock);
  977. lpfc_sli_ringpostbuf_put(phba, pring, mp1);
  978. if (mp2) {
  979. lpfc_sli_ringpostbuf_put(phba, pring, mp2);
  980. }
  981. }
  982. pring->missbufcnt = 0;
  983. return 0;
  984. }
  985. /************************************************************************/
  986. /* */
  987. /* lpfc_post_rcv_buf */
  988. /* This routine post initial rcv buffers to the configured rings */
  989. /* */
  990. /************************************************************************/
  991. static int
  992. lpfc_post_rcv_buf(struct lpfc_hba * phba)
  993. {
  994. struct lpfc_sli *psli = &phba->sli;
  995. /* Ring 0, ELS / CT buffers */
  996. lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], LPFC_BUF_RING0, 1);
  997. /* Ring 2 - FCP no buffers needed */
  998. return 0;
  999. }
  1000. #define S(N,V) (((V)<<(N))|((V)>>(32-(N))))
  1001. /************************************************************************/
  1002. /* */
  1003. /* lpfc_sha_init */
  1004. /* */
  1005. /************************************************************************/
  1006. static void
  1007. lpfc_sha_init(uint32_t * HashResultPointer)
  1008. {
  1009. HashResultPointer[0] = 0x67452301;
  1010. HashResultPointer[1] = 0xEFCDAB89;
  1011. HashResultPointer[2] = 0x98BADCFE;
  1012. HashResultPointer[3] = 0x10325476;
  1013. HashResultPointer[4] = 0xC3D2E1F0;
  1014. }
  1015. /************************************************************************/
  1016. /* */
  1017. /* lpfc_sha_iterate */
  1018. /* */
  1019. /************************************************************************/
  1020. static void
  1021. lpfc_sha_iterate(uint32_t * HashResultPointer, uint32_t * HashWorkingPointer)
  1022. {
  1023. int t;
  1024. uint32_t TEMP;
  1025. uint32_t A, B, C, D, E;
  1026. t = 16;
  1027. do {
  1028. HashWorkingPointer[t] =
  1029. S(1,
  1030. HashWorkingPointer[t - 3] ^ HashWorkingPointer[t -
  1031. 8] ^
  1032. HashWorkingPointer[t - 14] ^ HashWorkingPointer[t - 16]);
  1033. } while (++t <= 79);
  1034. t = 0;
  1035. A = HashResultPointer[0];
  1036. B = HashResultPointer[1];
  1037. C = HashResultPointer[2];
  1038. D = HashResultPointer[3];
  1039. E = HashResultPointer[4];
  1040. do {
  1041. if (t < 20) {
  1042. TEMP = ((B & C) | ((~B) & D)) + 0x5A827999;
  1043. } else if (t < 40) {
  1044. TEMP = (B ^ C ^ D) + 0x6ED9EBA1;
  1045. } else if (t < 60) {
  1046. TEMP = ((B & C) | (B & D) | (C & D)) + 0x8F1BBCDC;
  1047. } else {
  1048. TEMP = (B ^ C ^ D) + 0xCA62C1D6;
  1049. }
  1050. TEMP += S(5, A) + E + HashWorkingPointer[t];
  1051. E = D;
  1052. D = C;
  1053. C = S(30, B);
  1054. B = A;
  1055. A = TEMP;
  1056. } while (++t <= 79);
  1057. HashResultPointer[0] += A;
  1058. HashResultPointer[1] += B;
  1059. HashResultPointer[2] += C;
  1060. HashResultPointer[3] += D;
  1061. HashResultPointer[4] += E;
  1062. }
  1063. /************************************************************************/
  1064. /* */
  1065. /* lpfc_challenge_key */
  1066. /* */
  1067. /************************************************************************/
  1068. static void
  1069. lpfc_challenge_key(uint32_t * RandomChallenge, uint32_t * HashWorking)
  1070. {
  1071. *HashWorking = (*RandomChallenge ^ *HashWorking);
  1072. }
  1073. /************************************************************************/
  1074. /* */
  1075. /* lpfc_hba_init */
  1076. /* */
  1077. /************************************************************************/
  1078. void
  1079. lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
  1080. {
  1081. int t;
  1082. uint32_t *HashWorking;
  1083. uint32_t *pwwnn = phba->wwnn;
  1084. HashWorking = kmalloc(80 * sizeof(uint32_t), GFP_KERNEL);
  1085. if (!HashWorking)
  1086. return;
  1087. memset(HashWorking, 0, (80 * sizeof(uint32_t)));
  1088. HashWorking[0] = HashWorking[78] = *pwwnn++;
  1089. HashWorking[1] = HashWorking[79] = *pwwnn;
  1090. for (t = 0; t < 7; t++)
  1091. lpfc_challenge_key(phba->RandomData + t, HashWorking + t);
  1092. lpfc_sha_init(hbainit);
  1093. lpfc_sha_iterate(hbainit, HashWorking);
  1094. kfree(HashWorking);
  1095. }
  1096. static void
  1097. lpfc_cleanup(struct lpfc_hba * phba, uint32_t save_bind)
  1098. {
  1099. struct lpfc_nodelist *ndlp, *next_ndlp;
  1100. /* clean up phba - lpfc specific */
  1101. lpfc_can_disctmo(phba);
  1102. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list,
  1103. nlp_listp) {
  1104. lpfc_nlp_remove(phba, ndlp);
  1105. }
  1106. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
  1107. nlp_listp) {
  1108. lpfc_nlp_remove(phba, ndlp);
  1109. }
  1110. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
  1111. nlp_listp) {
  1112. lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
  1113. }
  1114. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
  1115. nlp_listp) {
  1116. lpfc_nlp_remove(phba, ndlp);
  1117. }
  1118. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
  1119. nlp_listp) {
  1120. lpfc_nlp_remove(phba, ndlp);
  1121. }
  1122. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_reglogin_list,
  1123. nlp_listp) {
  1124. lpfc_nlp_remove(phba, ndlp);
  1125. }
  1126. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
  1127. nlp_listp) {
  1128. lpfc_nlp_remove(phba, ndlp);
  1129. }
  1130. list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
  1131. nlp_listp) {
  1132. lpfc_nlp_remove(phba, ndlp);
  1133. }
  1134. INIT_LIST_HEAD(&phba->fc_nlpmap_list);
  1135. INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
  1136. INIT_LIST_HEAD(&phba->fc_unused_list);
  1137. INIT_LIST_HEAD(&phba->fc_plogi_list);
  1138. INIT_LIST_HEAD(&phba->fc_adisc_list);
  1139. INIT_LIST_HEAD(&phba->fc_reglogin_list);
  1140. INIT_LIST_HEAD(&phba->fc_prli_list);
  1141. INIT_LIST_HEAD(&phba->fc_npr_list);
  1142. phba->fc_map_cnt = 0;
  1143. phba->fc_unmap_cnt = 0;
  1144. phba->fc_plogi_cnt = 0;
  1145. phba->fc_adisc_cnt = 0;
  1146. phba->fc_reglogin_cnt = 0;
  1147. phba->fc_prli_cnt = 0;
  1148. phba->fc_npr_cnt = 0;
  1149. phba->fc_unused_cnt= 0;
  1150. return;
  1151. }
  1152. static void
  1153. lpfc_establish_link_tmo(unsigned long ptr)
  1154. {
  1155. struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
  1156. unsigned long iflag;
  1157. /* Re-establishing Link, timer expired */
  1158. lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
  1159. "%d:1300 Re-establishing Link, timer expired "
  1160. "Data: x%x x%x\n",
  1161. phba->brd_no, phba->fc_flag, phba->hba_state);
  1162. spin_lock_irqsave(phba->host->host_lock, iflag);
  1163. phba->fc_flag &= ~FC_ESTABLISH_LINK;
  1164. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1165. }
  1166. static int
  1167. lpfc_stop_timer(struct lpfc_hba * phba)
  1168. {
  1169. struct lpfc_sli *psli = &phba->sli;
  1170. /* Instead of a timer, this has been converted to a
  1171. * deferred procedding list.
  1172. */
  1173. while (!list_empty(&phba->freebufList)) {
  1174. struct lpfc_dmabuf *mp = NULL;
  1175. list_remove_head((&phba->freebufList), mp,
  1176. struct lpfc_dmabuf, list);
  1177. if (mp) {
  1178. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1179. kfree(mp);
  1180. }
  1181. }
  1182. del_timer_sync(&phba->fcp_poll_timer);
  1183. del_timer_sync(&phba->fc_estabtmo);
  1184. del_timer_sync(&phba->fc_disctmo);
  1185. del_timer_sync(&phba->fc_fdmitmo);
  1186. del_timer_sync(&phba->els_tmofunc);
  1187. psli = &phba->sli;
  1188. del_timer_sync(&psli->mbox_tmo);
  1189. return(1);
  1190. }
  1191. int
  1192. lpfc_online(struct lpfc_hba * phba)
  1193. {
  1194. if (!phba)
  1195. return 0;
  1196. if (!(phba->fc_flag & FC_OFFLINE_MODE))
  1197. return 0;
  1198. lpfc_printf_log(phba,
  1199. KERN_WARNING,
  1200. LOG_INIT,
  1201. "%d:0458 Bring Adapter online\n",
  1202. phba->brd_no);
  1203. if (!lpfc_sli_queue_setup(phba))
  1204. return 1;
  1205. if (lpfc_sli_hba_setup(phba)) /* Initialize the HBA */
  1206. return 1;
  1207. spin_lock_irq(phba->host->host_lock);
  1208. phba->fc_flag &= ~FC_OFFLINE_MODE;
  1209. spin_unlock_irq(phba->host->host_lock);
  1210. return 0;
  1211. }
  1212. int
  1213. lpfc_offline(struct lpfc_hba * phba)
  1214. {
  1215. struct lpfc_sli_ring *pring;
  1216. struct lpfc_sli *psli;
  1217. unsigned long iflag;
  1218. int i;
  1219. int cnt = 0;
  1220. if (!phba)
  1221. return 0;
  1222. if (phba->fc_flag & FC_OFFLINE_MODE)
  1223. return 0;
  1224. psli = &phba->sli;
  1225. lpfc_linkdown(phba);
  1226. lpfc_sli_flush_mbox_queue(phba);
  1227. for (i = 0; i < psli->num_rings; i++) {
  1228. pring = &psli->ring[i];
  1229. /* The linkdown event takes 30 seconds to timeout. */
  1230. while (pring->txcmplq_cnt) {
  1231. mdelay(10);
  1232. if (cnt++ > 3000) {
  1233. lpfc_printf_log(phba,
  1234. KERN_WARNING, LOG_INIT,
  1235. "%d:0466 Outstanding IO when "
  1236. "bringing Adapter offline\n",
  1237. phba->brd_no);
  1238. break;
  1239. }
  1240. }
  1241. }
  1242. /* stop all timers associated with this hba */
  1243. lpfc_stop_timer(phba);
  1244. phba->work_hba_events = 0;
  1245. phba->work_ha = 0;
  1246. lpfc_printf_log(phba,
  1247. KERN_WARNING,
  1248. LOG_INIT,
  1249. "%d:0460 Bring Adapter offline\n",
  1250. phba->brd_no);
  1251. /* Bring down the SLI Layer and cleanup. The HBA is offline
  1252. now. */
  1253. lpfc_sli_hba_down(phba);
  1254. lpfc_cleanup(phba, 1);
  1255. spin_lock_irqsave(phba->host->host_lock, iflag);
  1256. phba->fc_flag |= FC_OFFLINE_MODE;
  1257. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1258. return 0;
  1259. }
  1260. /******************************************************************************
  1261. * Function name: lpfc_scsi_free
  1262. *
  1263. * Description: Called from lpfc_pci_remove_one free internal driver resources
  1264. *
  1265. ******************************************************************************/
  1266. static int
  1267. lpfc_scsi_free(struct lpfc_hba * phba)
  1268. {
  1269. struct lpfc_scsi_buf *sb, *sb_next;
  1270. struct lpfc_iocbq *io, *io_next;
  1271. spin_lock_irq(phba->host->host_lock);
  1272. /* Release all the lpfc_scsi_bufs maintained by this host. */
  1273. list_for_each_entry_safe(sb, sb_next, &phba->lpfc_scsi_buf_list, list) {
  1274. list_del(&sb->list);
  1275. pci_pool_free(phba->lpfc_scsi_dma_buf_pool, sb->data,
  1276. sb->dma_handle);
  1277. kfree(sb);
  1278. phba->total_scsi_bufs--;
  1279. }
  1280. /* Release all the lpfc_iocbq entries maintained by this host. */
  1281. list_for_each_entry_safe(io, io_next, &phba->lpfc_iocb_list, list) {
  1282. list_del(&io->list);
  1283. kfree(io);
  1284. phba->total_iocbq_bufs--;
  1285. }
  1286. spin_unlock_irq(phba->host->host_lock);
  1287. return 0;
  1288. }
  1289. static int __devinit
  1290. lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
  1291. {
  1292. struct Scsi_Host *host;
  1293. struct lpfc_hba *phba;
  1294. struct lpfc_sli *psli;
  1295. struct lpfc_iocbq *iocbq_entry = NULL, *iocbq_next = NULL;
  1296. unsigned long bar0map_len, bar2map_len;
  1297. int error = -ENODEV, retval;
  1298. int i;
  1299. uint16_t iotag;
  1300. if (pci_enable_device(pdev))
  1301. goto out;
  1302. if (pci_request_regions(pdev, LPFC_DRIVER_NAME))
  1303. goto out_disable_device;
  1304. host = scsi_host_alloc(&lpfc_template, sizeof (struct lpfc_hba));
  1305. if (!host)
  1306. goto out_release_regions;
  1307. phba = (struct lpfc_hba*)host->hostdata;
  1308. memset(phba, 0, sizeof (struct lpfc_hba));
  1309. phba->host = host;
  1310. phba->fc_flag |= FC_LOADING;
  1311. phba->pcidev = pdev;
  1312. /* Assign an unused board number */
  1313. if (!idr_pre_get(&lpfc_hba_index, GFP_KERNEL))
  1314. goto out_put_host;
  1315. error = idr_get_new(&lpfc_hba_index, NULL, &phba->brd_no);
  1316. if (error)
  1317. goto out_put_host;
  1318. host->unique_id = phba->brd_no;
  1319. INIT_LIST_HEAD(&phba->ctrspbuflist);
  1320. INIT_LIST_HEAD(&phba->rnidrspbuflist);
  1321. INIT_LIST_HEAD(&phba->freebufList);
  1322. /* Initialize timers used by driver */
  1323. init_timer(&phba->fc_estabtmo);
  1324. phba->fc_estabtmo.function = lpfc_establish_link_tmo;
  1325. phba->fc_estabtmo.data = (unsigned long)phba;
  1326. init_timer(&phba->fc_disctmo);
  1327. phba->fc_disctmo.function = lpfc_disc_timeout;
  1328. phba->fc_disctmo.data = (unsigned long)phba;
  1329. init_timer(&phba->fc_fdmitmo);
  1330. phba->fc_fdmitmo.function = lpfc_fdmi_tmo;
  1331. phba->fc_fdmitmo.data = (unsigned long)phba;
  1332. init_timer(&phba->els_tmofunc);
  1333. phba->els_tmofunc.function = lpfc_els_timeout;
  1334. phba->els_tmofunc.data = (unsigned long)phba;
  1335. psli = &phba->sli;
  1336. init_timer(&psli->mbox_tmo);
  1337. psli->mbox_tmo.function = lpfc_mbox_timeout;
  1338. psli->mbox_tmo.data = (unsigned long)phba;
  1339. init_timer(&phba->fcp_poll_timer);
  1340. phba->fcp_poll_timer.function = lpfc_poll_timeout;
  1341. phba->fcp_poll_timer.data = (unsigned long)phba;
  1342. /*
  1343. * Get all the module params for configuring this host and then
  1344. * establish the host parameters.
  1345. */
  1346. lpfc_get_cfgparam(phba);
  1347. host->max_id = LPFC_MAX_TARGET;
  1348. host->max_lun = phba->cfg_max_luns;
  1349. host->this_id = -1;
  1350. /* Initialize all internally managed lists. */
  1351. INIT_LIST_HEAD(&phba->fc_nlpmap_list);
  1352. INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
  1353. INIT_LIST_HEAD(&phba->fc_unused_list);
  1354. INIT_LIST_HEAD(&phba->fc_plogi_list);
  1355. INIT_LIST_HEAD(&phba->fc_adisc_list);
  1356. INIT_LIST_HEAD(&phba->fc_reglogin_list);
  1357. INIT_LIST_HEAD(&phba->fc_prli_list);
  1358. INIT_LIST_HEAD(&phba->fc_npr_list);
  1359. pci_set_master(pdev);
  1360. retval = pci_set_mwi(pdev);
  1361. if (retval)
  1362. dev_printk(KERN_WARNING, &pdev->dev,
  1363. "Warning: pci_set_mwi returned %d\n", retval);
  1364. if (pci_set_dma_mask(phba->pcidev, DMA_64BIT_MASK) != 0)
  1365. if (pci_set_dma_mask(phba->pcidev, DMA_32BIT_MASK) != 0)
  1366. goto out_idr_remove;
  1367. /*
  1368. * Get the bus address of Bar0 and Bar2 and the number of bytes
  1369. * required by each mapping.
  1370. */
  1371. phba->pci_bar0_map = pci_resource_start(phba->pcidev, 0);
  1372. bar0map_len = pci_resource_len(phba->pcidev, 0);
  1373. phba->pci_bar2_map = pci_resource_start(phba->pcidev, 2);
  1374. bar2map_len = pci_resource_len(phba->pcidev, 2);
  1375. /* Map HBA SLIM to a kernel virtual address. */
  1376. phba->slim_memmap_p = ioremap(phba->pci_bar0_map, bar0map_len);
  1377. if (!phba->slim_memmap_p) {
  1378. error = -ENODEV;
  1379. dev_printk(KERN_ERR, &pdev->dev,
  1380. "ioremap failed for SLIM memory.\n");
  1381. goto out_idr_remove;
  1382. }
  1383. /* Map HBA Control Registers to a kernel virtual address. */
  1384. phba->ctrl_regs_memmap_p = ioremap(phba->pci_bar2_map, bar2map_len);
  1385. if (!phba->ctrl_regs_memmap_p) {
  1386. error = -ENODEV;
  1387. dev_printk(KERN_ERR, &pdev->dev,
  1388. "ioremap failed for HBA control registers.\n");
  1389. goto out_iounmap_slim;
  1390. }
  1391. /* Allocate memory for SLI-2 structures */
  1392. phba->slim2p = dma_alloc_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
  1393. &phba->slim2p_mapping, GFP_KERNEL);
  1394. if (!phba->slim2p)
  1395. goto out_iounmap;
  1396. memset(phba->slim2p, 0, SLI2_SLIM_SIZE);
  1397. /* Initialize the SLI Layer to run with lpfc HBAs. */
  1398. lpfc_sli_setup(phba);
  1399. lpfc_sli_queue_setup(phba);
  1400. error = lpfc_mem_alloc(phba);
  1401. if (error)
  1402. goto out_free_slim;
  1403. /* Initialize and populate the iocb list per host. */
  1404. INIT_LIST_HEAD(&phba->lpfc_iocb_list);
  1405. for (i = 0; i < LPFC_IOCB_LIST_CNT; i++) {
  1406. iocbq_entry = kmalloc(sizeof(struct lpfc_iocbq), GFP_KERNEL);
  1407. if (iocbq_entry == NULL) {
  1408. printk(KERN_ERR "%s: only allocated %d iocbs of "
  1409. "expected %d count. Unloading driver.\n",
  1410. __FUNCTION__, i, LPFC_IOCB_LIST_CNT);
  1411. error = -ENOMEM;
  1412. goto out_free_iocbq;
  1413. }
  1414. memset(iocbq_entry, 0, sizeof(struct lpfc_iocbq));
  1415. iotag = lpfc_sli_next_iotag(phba, iocbq_entry);
  1416. if (iotag == 0) {
  1417. kfree (iocbq_entry);
  1418. printk(KERN_ERR "%s: failed to allocate IOTAG. "
  1419. "Unloading driver.\n",
  1420. __FUNCTION__);
  1421. error = -ENOMEM;
  1422. goto out_free_iocbq;
  1423. }
  1424. spin_lock_irq(phba->host->host_lock);
  1425. list_add(&iocbq_entry->list, &phba->lpfc_iocb_list);
  1426. phba->total_iocbq_bufs++;
  1427. spin_unlock_irq(phba->host->host_lock);
  1428. }
  1429. /* Initialize HBA structure */
  1430. phba->fc_edtov = FF_DEF_EDTOV;
  1431. phba->fc_ratov = FF_DEF_RATOV;
  1432. phba->fc_altov = FF_DEF_ALTOV;
  1433. phba->fc_arbtov = FF_DEF_ARBTOV;
  1434. INIT_LIST_HEAD(&phba->work_list);
  1435. phba->work_ha_mask = (HA_ERATT|HA_MBATT|HA_LATT);
  1436. phba->work_ha_mask |= (HA_RXMASK << (LPFC_ELS_RING * 4));
  1437. /* Startup the kernel thread for this host adapter. */
  1438. phba->worker_thread = kthread_run(lpfc_do_work, phba,
  1439. "lpfc_worker_%d", phba->brd_no);
  1440. if (IS_ERR(phba->worker_thread)) {
  1441. error = PTR_ERR(phba->worker_thread);
  1442. goto out_free_iocbq;
  1443. }
  1444. /*
  1445. * Set initial can_queue value since 0 is no longer supported and
  1446. * scsi_add_host will fail. This will be adjusted later based on the
  1447. * max xri value determined in hba setup.
  1448. */
  1449. host->can_queue = phba->cfg_hba_queue_depth - 10;
  1450. /* Tell the midlayer we support 16 byte commands */
  1451. host->max_cmd_len = 16;
  1452. /* Initialize the list of scsi buffers used by driver for scsi IO. */
  1453. spin_lock_init(&phba->scsi_buf_list_lock);
  1454. INIT_LIST_HEAD(&phba->lpfc_scsi_buf_list);
  1455. host->transportt = lpfc_transport_template;
  1456. pci_set_drvdata(pdev, host);
  1457. error = scsi_add_host(host, &pdev->dev);
  1458. if (error)
  1459. goto out_kthread_stop;
  1460. error = lpfc_alloc_sysfs_attr(phba);
  1461. if (error)
  1462. goto out_remove_host;
  1463. error = request_irq(phba->pcidev->irq, lpfc_intr_handler, IRQF_SHARED,
  1464. LPFC_DRIVER_NAME, phba);
  1465. if (error) {
  1466. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1467. "%d:0451 Enable interrupt handler failed\n",
  1468. phba->brd_no);
  1469. goto out_free_sysfs_attr;
  1470. }
  1471. phba->MBslimaddr = phba->slim_memmap_p;
  1472. phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
  1473. phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
  1474. phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
  1475. phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
  1476. error = lpfc_sli_hba_setup(phba);
  1477. if (error) {
  1478. error = -ENODEV;
  1479. goto out_free_irq;
  1480. }
  1481. /*
  1482. * hba setup may have changed the hba_queue_depth so we need to adjust
  1483. * the value of can_queue.
  1484. */
  1485. host->can_queue = phba->cfg_hba_queue_depth - 10;
  1486. lpfc_discovery_wait(phba);
  1487. if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
  1488. spin_lock_irq(phba->host->host_lock);
  1489. lpfc_poll_start_timer(phba);
  1490. spin_unlock_irq(phba->host->host_lock);
  1491. }
  1492. /*
  1493. * set fixed host attributes
  1494. * Must done after lpfc_sli_hba_setup()
  1495. */
  1496. fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.u.wwn);
  1497. fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.u.wwn);
  1498. fc_host_supported_classes(host) = FC_COS_CLASS3;
  1499. memset(fc_host_supported_fc4s(host), 0,
  1500. sizeof(fc_host_supported_fc4s(host)));
  1501. fc_host_supported_fc4s(host)[2] = 1;
  1502. fc_host_supported_fc4s(host)[7] = 1;
  1503. lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(host));
  1504. fc_host_supported_speeds(host) = 0;
  1505. if (phba->lmt & LMT_10Gb)
  1506. fc_host_supported_speeds(host) |= FC_PORTSPEED_10GBIT;
  1507. if (phba->lmt & LMT_4Gb)
  1508. fc_host_supported_speeds(host) |= FC_PORTSPEED_4GBIT;
  1509. if (phba->lmt & LMT_2Gb)
  1510. fc_host_supported_speeds(host) |= FC_PORTSPEED_2GBIT;
  1511. if (phba->lmt & LMT_1Gb)
  1512. fc_host_supported_speeds(host) |= FC_PORTSPEED_1GBIT;
  1513. fc_host_maxframe_size(host) =
  1514. ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
  1515. (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb);
  1516. /* This value is also unchanging */
  1517. memset(fc_host_active_fc4s(host), 0,
  1518. sizeof(fc_host_active_fc4s(host)));
  1519. fc_host_active_fc4s(host)[2] = 1;
  1520. fc_host_active_fc4s(host)[7] = 1;
  1521. spin_lock_irq(phba->host->host_lock);
  1522. phba->fc_flag &= ~FC_LOADING;
  1523. spin_unlock_irq(phba->host->host_lock);
  1524. return 0;
  1525. out_free_irq:
  1526. lpfc_stop_timer(phba);
  1527. phba->work_hba_events = 0;
  1528. free_irq(phba->pcidev->irq, phba);
  1529. out_free_sysfs_attr:
  1530. lpfc_free_sysfs_attr(phba);
  1531. out_remove_host:
  1532. fc_remove_host(phba->host);
  1533. scsi_remove_host(phba->host);
  1534. out_kthread_stop:
  1535. kthread_stop(phba->worker_thread);
  1536. out_free_iocbq:
  1537. list_for_each_entry_safe(iocbq_entry, iocbq_next,
  1538. &phba->lpfc_iocb_list, list) {
  1539. spin_lock_irq(phba->host->host_lock);
  1540. kfree(iocbq_entry);
  1541. phba->total_iocbq_bufs--;
  1542. spin_unlock_irq(phba->host->host_lock);
  1543. }
  1544. lpfc_mem_free(phba);
  1545. out_free_slim:
  1546. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE, phba->slim2p,
  1547. phba->slim2p_mapping);
  1548. out_iounmap:
  1549. iounmap(phba->ctrl_regs_memmap_p);
  1550. out_iounmap_slim:
  1551. iounmap(phba->slim_memmap_p);
  1552. out_idr_remove:
  1553. idr_remove(&lpfc_hba_index, phba->brd_no);
  1554. out_put_host:
  1555. phba->host = NULL;
  1556. scsi_host_put(host);
  1557. out_release_regions:
  1558. pci_release_regions(pdev);
  1559. out_disable_device:
  1560. pci_disable_device(pdev);
  1561. out:
  1562. pci_set_drvdata(pdev, NULL);
  1563. return error;
  1564. }
  1565. static void __devexit
  1566. lpfc_pci_remove_one(struct pci_dev *pdev)
  1567. {
  1568. struct Scsi_Host *host = pci_get_drvdata(pdev);
  1569. struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
  1570. unsigned long iflag;
  1571. lpfc_free_sysfs_attr(phba);
  1572. spin_lock_irqsave(phba->host->host_lock, iflag);
  1573. phba->fc_flag |= FC_UNLOADING;
  1574. spin_unlock_irqrestore(phba->host->host_lock, iflag);
  1575. fc_remove_host(phba->host);
  1576. scsi_remove_host(phba->host);
  1577. kthread_stop(phba->worker_thread);
  1578. /*
  1579. * Bring down the SLI Layer. This step disable all interrupts,
  1580. * clears the rings, discards all mailbox commands, and resets
  1581. * the HBA.
  1582. */
  1583. lpfc_sli_hba_down(phba);
  1584. lpfc_sli_brdrestart(phba);
  1585. /* Release the irq reservation */
  1586. free_irq(phba->pcidev->irq, phba);
  1587. lpfc_cleanup(phba, 0);
  1588. lpfc_stop_timer(phba);
  1589. phba->work_hba_events = 0;
  1590. /*
  1591. * Call scsi_free before mem_free since scsi bufs are released to their
  1592. * corresponding pools here.
  1593. */
  1594. lpfc_scsi_free(phba);
  1595. lpfc_mem_free(phba);
  1596. /* Free resources associated with SLI2 interface */
  1597. dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
  1598. phba->slim2p, phba->slim2p_mapping);
  1599. /* unmap adapter SLIM and Control Registers */
  1600. iounmap(phba->ctrl_regs_memmap_p);
  1601. iounmap(phba->slim_memmap_p);
  1602. pci_release_regions(phba->pcidev);
  1603. pci_disable_device(phba->pcidev);
  1604. idr_remove(&lpfc_hba_index, phba->brd_no);
  1605. scsi_host_put(phba->host);
  1606. pci_set_drvdata(pdev, NULL);
  1607. }
  1608. static struct pci_device_id lpfc_id_table[] = {
  1609. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_VIPER,
  1610. PCI_ANY_ID, PCI_ANY_ID, },
  1611. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_FIREFLY,
  1612. PCI_ANY_ID, PCI_ANY_ID, },
  1613. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_THOR,
  1614. PCI_ANY_ID, PCI_ANY_ID, },
  1615. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PEGASUS,
  1616. PCI_ANY_ID, PCI_ANY_ID, },
  1617. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_CENTAUR,
  1618. PCI_ANY_ID, PCI_ANY_ID, },
  1619. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_DRAGONFLY,
  1620. PCI_ANY_ID, PCI_ANY_ID, },
  1621. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SUPERFLY,
  1622. PCI_ANY_ID, PCI_ANY_ID, },
  1623. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_RFLY,
  1624. PCI_ANY_ID, PCI_ANY_ID, },
  1625. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_PFLY,
  1626. PCI_ANY_ID, PCI_ANY_ID, },
  1627. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE,
  1628. PCI_ANY_ID, PCI_ANY_ID, },
  1629. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_SCSP,
  1630. PCI_ANY_ID, PCI_ANY_ID, },
  1631. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_NEPTUNE_DCSP,
  1632. PCI_ANY_ID, PCI_ANY_ID, },
  1633. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS,
  1634. PCI_ANY_ID, PCI_ANY_ID, },
  1635. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_SCSP,
  1636. PCI_ANY_ID, PCI_ANY_ID, },
  1637. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_HELIOS_DCSP,
  1638. PCI_ANY_ID, PCI_ANY_ID, },
  1639. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BMID,
  1640. PCI_ANY_ID, PCI_ANY_ID, },
  1641. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_BSMB,
  1642. PCI_ANY_ID, PCI_ANY_ID, },
  1643. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR,
  1644. PCI_ANY_ID, PCI_ANY_ID, },
  1645. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_SCSP,
  1646. PCI_ANY_ID, PCI_ANY_ID, },
  1647. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZEPHYR_DCSP,
  1648. PCI_ANY_ID, PCI_ANY_ID, },
  1649. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZMID,
  1650. PCI_ANY_ID, PCI_ANY_ID, },
  1651. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_ZSMB,
  1652. PCI_ANY_ID, PCI_ANY_ID, },
  1653. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_TFLY,
  1654. PCI_ANY_ID, PCI_ANY_ID, },
  1655. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP101,
  1656. PCI_ANY_ID, PCI_ANY_ID, },
  1657. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP10000S,
  1658. PCI_ANY_ID, PCI_ANY_ID, },
  1659. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LP11000S,
  1660. PCI_ANY_ID, PCI_ANY_ID, },
  1661. {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
  1662. PCI_ANY_ID, PCI_ANY_ID, },
  1663. { 0 }
  1664. };
  1665. MODULE_DEVICE_TABLE(pci, lpfc_id_table);
  1666. static struct pci_driver lpfc_driver = {
  1667. .name = LPFC_DRIVER_NAME,
  1668. .id_table = lpfc_id_table,
  1669. .probe = lpfc_pci_probe_one,
  1670. .remove = __devexit_p(lpfc_pci_remove_one),
  1671. };
  1672. static int __init
  1673. lpfc_init(void)
  1674. {
  1675. int error = 0;
  1676. printk(LPFC_MODULE_DESC "\n");
  1677. printk(LPFC_COPYRIGHT "\n");
  1678. lpfc_transport_template =
  1679. fc_attach_transport(&lpfc_transport_functions);
  1680. if (!lpfc_transport_template)
  1681. return -ENOMEM;
  1682. error = pci_register_driver(&lpfc_driver);
  1683. if (error)
  1684. fc_release_transport(lpfc_transport_template);
  1685. return error;
  1686. }
  1687. static void __exit
  1688. lpfc_exit(void)
  1689. {
  1690. pci_unregister_driver(&lpfc_driver);
  1691. fc_release_transport(lpfc_transport_template);
  1692. }
  1693. module_init(lpfc_init);
  1694. module_exit(lpfc_exit);
  1695. MODULE_LICENSE("GPL");
  1696. MODULE_DESCRIPTION(LPFC_MODULE_DESC);
  1697. MODULE_AUTHOR("Emulex Corporation - tech.support@emulex.com");
  1698. MODULE_VERSION("0:" LPFC_DRIVER_VERSION);