lpfc_init.c 65 KB

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