lpfc_init.c 67 KB

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