lpfc_ct.c 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2016 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or *
  9. * modify it under the terms of version 2 of the GNU General *
  10. * Public License as published by the Free Software Foundation. *
  11. * This program is distributed in the hope that it will be useful. *
  12. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  13. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  14. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  15. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  16. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  17. * more details, a copy of which can be found in the file COPYING *
  18. * included with this package. *
  19. *******************************************************************/
  20. /*
  21. * Fibre Channel SCSI LAN Device Driver CT support: FC Generic Services FC-GS
  22. */
  23. #include <linux/blkdev.h>
  24. #include <linux/pci.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/slab.h>
  27. #include <linux/utsname.h>
  28. #include <scsi/scsi.h>
  29. #include <scsi/scsi_device.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_transport_fc.h>
  32. #include <scsi/fc/fc_fs.h>
  33. #include "lpfc_hw4.h"
  34. #include "lpfc_hw.h"
  35. #include "lpfc_sli.h"
  36. #include "lpfc_sli4.h"
  37. #include "lpfc_nl.h"
  38. #include "lpfc_disc.h"
  39. #include "lpfc_scsi.h"
  40. #include "lpfc.h"
  41. #include "lpfc_logmsg.h"
  42. #include "lpfc_crtn.h"
  43. #include "lpfc_version.h"
  44. #include "lpfc_vport.h"
  45. #include "lpfc_debugfs.h"
  46. /* FDMI Port Speed definitions - FC-GS-7 */
  47. #define HBA_PORTSPEED_1GFC 0x00000001 /* 1G FC */
  48. #define HBA_PORTSPEED_2GFC 0x00000002 /* 2G FC */
  49. #define HBA_PORTSPEED_4GFC 0x00000008 /* 4G FC */
  50. #define HBA_PORTSPEED_10GFC 0x00000004 /* 10G FC */
  51. #define HBA_PORTSPEED_8GFC 0x00000010 /* 8G FC */
  52. #define HBA_PORTSPEED_16GFC 0x00000020 /* 16G FC */
  53. #define HBA_PORTSPEED_32GFC 0x00000040 /* 32G FC */
  54. #define HBA_PORTSPEED_20GFC 0x00000080 /* 20G FC */
  55. #define HBA_PORTSPEED_40GFC 0x00000100 /* 40G FC */
  56. #define HBA_PORTSPEED_128GFC 0x00000200 /* 128G FC */
  57. #define HBA_PORTSPEED_64GFC 0x00000400 /* 64G FC */
  58. #define HBA_PORTSPEED_256GFC 0x00000800 /* 256G FC */
  59. #define HBA_PORTSPEED_UNKNOWN 0x00008000 /* Unknown */
  60. #define HBA_PORTSPEED_10GE 0x00010000 /* 10G E */
  61. #define HBA_PORTSPEED_40GE 0x00020000 /* 40G E */
  62. #define HBA_PORTSPEED_100GE 0x00040000 /* 100G E */
  63. #define HBA_PORTSPEED_25GE 0x00080000 /* 25G E */
  64. #define HBA_PORTSPEED_50GE 0x00100000 /* 50G E */
  65. #define HBA_PORTSPEED_400GE 0x00200000 /* 400G E */
  66. #define FOURBYTES 4
  67. static char *lpfc_release_version = LPFC_DRIVER_VERSION;
  68. static void
  69. lpfc_ct_ignore_hbq_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  70. struct lpfc_dmabuf *mp, uint32_t size)
  71. {
  72. if (!mp) {
  73. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  74. "0146 Ignoring unsolicited CT No HBQ "
  75. "status = x%x\n",
  76. piocbq->iocb.ulpStatus);
  77. }
  78. lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
  79. "0145 Ignoring unsolicted CT HBQ Size:%d "
  80. "status = x%x\n",
  81. size, piocbq->iocb.ulpStatus);
  82. }
  83. static void
  84. lpfc_ct_unsol_buffer(struct lpfc_hba *phba, struct lpfc_iocbq *piocbq,
  85. struct lpfc_dmabuf *mp, uint32_t size)
  86. {
  87. lpfc_ct_ignore_hbq_buffer(phba, piocbq, mp, size);
  88. }
  89. void
  90. lpfc_ct_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
  91. struct lpfc_iocbq *piocbq)
  92. {
  93. struct lpfc_dmabuf *mp = NULL;
  94. IOCB_t *icmd = &piocbq->iocb;
  95. int i;
  96. struct lpfc_iocbq *iocbq;
  97. dma_addr_t paddr;
  98. uint32_t size;
  99. struct list_head head;
  100. struct lpfc_dmabuf *bdeBuf;
  101. if (lpfc_bsg_ct_unsol_event(phba, pring, piocbq) == 0)
  102. return;
  103. if (unlikely(icmd->ulpStatus == IOSTAT_NEED_BUFFER)) {
  104. lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
  105. } else if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  106. ((icmd->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  107. IOERR_RCV_BUFFER_WAITING)) {
  108. /* Not enough posted buffers; Try posting more buffers */
  109. phba->fc_stat.NoRcvBuf++;
  110. if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
  111. lpfc_post_buffer(phba, pring, 2);
  112. return;
  113. }
  114. /* If there are no BDEs associated with this IOCB,
  115. * there is nothing to do.
  116. */
  117. if (icmd->ulpBdeCount == 0)
  118. return;
  119. if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
  120. INIT_LIST_HEAD(&head);
  121. list_add_tail(&head, &piocbq->list);
  122. list_for_each_entry(iocbq, &head, list) {
  123. icmd = &iocbq->iocb;
  124. if (icmd->ulpBdeCount == 0)
  125. continue;
  126. bdeBuf = iocbq->context2;
  127. iocbq->context2 = NULL;
  128. size = icmd->un.cont64[0].tus.f.bdeSize;
  129. lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf, size);
  130. lpfc_in_buf_free(phba, bdeBuf);
  131. if (icmd->ulpBdeCount == 2) {
  132. bdeBuf = iocbq->context3;
  133. iocbq->context3 = NULL;
  134. size = icmd->unsli3.rcvsli3.bde2.tus.f.bdeSize;
  135. lpfc_ct_unsol_buffer(phba, piocbq, bdeBuf,
  136. size);
  137. lpfc_in_buf_free(phba, bdeBuf);
  138. }
  139. }
  140. list_del(&head);
  141. } else {
  142. INIT_LIST_HEAD(&head);
  143. list_add_tail(&head, &piocbq->list);
  144. list_for_each_entry(iocbq, &head, list) {
  145. icmd = &iocbq->iocb;
  146. if (icmd->ulpBdeCount == 0)
  147. lpfc_ct_unsol_buffer(phba, iocbq, NULL, 0);
  148. for (i = 0; i < icmd->ulpBdeCount; i++) {
  149. paddr = getPaddr(icmd->un.cont64[i].addrHigh,
  150. icmd->un.cont64[i].addrLow);
  151. mp = lpfc_sli_ringpostbuf_get(phba, pring,
  152. paddr);
  153. size = icmd->un.cont64[i].tus.f.bdeSize;
  154. lpfc_ct_unsol_buffer(phba, iocbq, mp, size);
  155. lpfc_in_buf_free(phba, mp);
  156. }
  157. lpfc_post_buffer(phba, pring, i);
  158. }
  159. list_del(&head);
  160. }
  161. }
  162. /**
  163. * lpfc_ct_handle_unsol_abort - ct upper level protocol abort handler
  164. * @phba: Pointer to HBA context object.
  165. * @dmabuf: pointer to a dmabuf that describes the FC sequence
  166. *
  167. * This function serves as the upper level protocol abort handler for CT
  168. * protocol.
  169. *
  170. * Return 1 if abort has been handled, 0 otherwise.
  171. **/
  172. int
  173. lpfc_ct_handle_unsol_abort(struct lpfc_hba *phba, struct hbq_dmabuf *dmabuf)
  174. {
  175. int handled;
  176. /* CT upper level goes through BSG */
  177. handled = lpfc_bsg_ct_unsol_abort(phba, dmabuf);
  178. return handled;
  179. }
  180. static void
  181. lpfc_free_ct_rsp(struct lpfc_hba *phba, struct lpfc_dmabuf *mlist)
  182. {
  183. struct lpfc_dmabuf *mlast, *next_mlast;
  184. list_for_each_entry_safe(mlast, next_mlast, &mlist->list, list) {
  185. lpfc_mbuf_free(phba, mlast->virt, mlast->phys);
  186. list_del(&mlast->list);
  187. kfree(mlast);
  188. }
  189. lpfc_mbuf_free(phba, mlist->virt, mlist->phys);
  190. kfree(mlist);
  191. return;
  192. }
  193. static struct lpfc_dmabuf *
  194. lpfc_alloc_ct_rsp(struct lpfc_hba *phba, int cmdcode, struct ulp_bde64 *bpl,
  195. uint32_t size, int *entries)
  196. {
  197. struct lpfc_dmabuf *mlist = NULL;
  198. struct lpfc_dmabuf *mp;
  199. int cnt, i = 0;
  200. /* We get chunks of FCELSSIZE */
  201. cnt = size > FCELSSIZE ? FCELSSIZE: size;
  202. while (size) {
  203. /* Allocate buffer for rsp payload */
  204. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  205. if (!mp) {
  206. if (mlist)
  207. lpfc_free_ct_rsp(phba, mlist);
  208. return NULL;
  209. }
  210. INIT_LIST_HEAD(&mp->list);
  211. if (cmdcode == be16_to_cpu(SLI_CTNS_GID_FT) ||
  212. cmdcode == be16_to_cpu(SLI_CTNS_GFF_ID))
  213. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  214. else
  215. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  216. if (!mp->virt) {
  217. kfree(mp);
  218. if (mlist)
  219. lpfc_free_ct_rsp(phba, mlist);
  220. return NULL;
  221. }
  222. /* Queue it to a linked list */
  223. if (!mlist)
  224. mlist = mp;
  225. else
  226. list_add_tail(&mp->list, &mlist->list);
  227. bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64I;
  228. /* build buffer ptr list for IOCB */
  229. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  230. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  231. bpl->tus.f.bdeSize = (uint16_t) cnt;
  232. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  233. bpl++;
  234. i++;
  235. size -= cnt;
  236. }
  237. *entries = i;
  238. return mlist;
  239. }
  240. int
  241. lpfc_ct_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *ctiocb)
  242. {
  243. struct lpfc_dmabuf *buf_ptr;
  244. if (ctiocb->context_un.ndlp) {
  245. lpfc_nlp_put(ctiocb->context_un.ndlp);
  246. ctiocb->context_un.ndlp = NULL;
  247. }
  248. if (ctiocb->context1) {
  249. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context1;
  250. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  251. kfree(buf_ptr);
  252. ctiocb->context1 = NULL;
  253. }
  254. if (ctiocb->context2) {
  255. lpfc_free_ct_rsp(phba, (struct lpfc_dmabuf *) ctiocb->context2);
  256. ctiocb->context2 = NULL;
  257. }
  258. if (ctiocb->context3) {
  259. buf_ptr = (struct lpfc_dmabuf *) ctiocb->context3;
  260. lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
  261. kfree(buf_ptr);
  262. ctiocb->context3 = NULL;
  263. }
  264. lpfc_sli_release_iocbq(phba, ctiocb);
  265. return 0;
  266. }
  267. /**
  268. * lpfc_gen_req - Build and issue a GEN_REQUEST command to the SLI Layer
  269. * @vport: pointer to a host virtual N_Port data structure.
  270. * @bmp: Pointer to BPL for SLI command
  271. * @inp: Pointer to data buffer for response data.
  272. * @outp: Pointer to data buffer that hold the CT command.
  273. * @cmpl: completion routine to call when command completes
  274. * @ndlp: Destination NPort nodelist entry
  275. *
  276. * This function as the final part for issuing a CT command.
  277. */
  278. static int
  279. lpfc_gen_req(struct lpfc_vport *vport, struct lpfc_dmabuf *bmp,
  280. struct lpfc_dmabuf *inp, struct lpfc_dmabuf *outp,
  281. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  282. struct lpfc_iocbq *),
  283. struct lpfc_nodelist *ndlp, uint32_t usr_flg, uint32_t num_entry,
  284. uint32_t tmo, uint8_t retry)
  285. {
  286. struct lpfc_hba *phba = vport->phba;
  287. IOCB_t *icmd;
  288. struct lpfc_iocbq *geniocb;
  289. int rc;
  290. /* Allocate buffer for command iocb */
  291. geniocb = lpfc_sli_get_iocbq(phba);
  292. if (geniocb == NULL)
  293. return 1;
  294. icmd = &geniocb->iocb;
  295. icmd->un.genreq64.bdl.ulpIoTag32 = 0;
  296. icmd->un.genreq64.bdl.addrHigh = putPaddrHigh(bmp->phys);
  297. icmd->un.genreq64.bdl.addrLow = putPaddrLow(bmp->phys);
  298. icmd->un.genreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
  299. icmd->un.genreq64.bdl.bdeSize = (num_entry * sizeof(struct ulp_bde64));
  300. if (usr_flg)
  301. geniocb->context3 = NULL;
  302. else
  303. geniocb->context3 = (uint8_t *) bmp;
  304. /* Save for completion so we can release these resources */
  305. geniocb->context1 = (uint8_t *) inp;
  306. geniocb->context2 = (uint8_t *) outp;
  307. geniocb->context_un.ndlp = lpfc_nlp_get(ndlp);
  308. /* Fill in payload, bp points to frame payload */
  309. icmd->ulpCommand = CMD_GEN_REQUEST64_CR;
  310. /* Fill in rest of iocb */
  311. icmd->un.genreq64.w5.hcsw.Fctl = (SI | LA);
  312. icmd->un.genreq64.w5.hcsw.Dfctl = 0;
  313. icmd->un.genreq64.w5.hcsw.Rctl = FC_RCTL_DD_UNSOL_CTL;
  314. icmd->un.genreq64.w5.hcsw.Type = FC_TYPE_CT;
  315. if (!tmo) {
  316. /* FC spec states we need 3 * ratov for CT requests */
  317. tmo = (3 * phba->fc_ratov);
  318. }
  319. icmd->ulpTimeout = tmo;
  320. icmd->ulpBdeCount = 1;
  321. icmd->ulpLe = 1;
  322. icmd->ulpClass = CLASS3;
  323. icmd->ulpContext = ndlp->nlp_rpi;
  324. if (phba->sli_rev == LPFC_SLI_REV4)
  325. icmd->ulpContext = phba->sli4_hba.rpi_ids[ndlp->nlp_rpi];
  326. if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
  327. /* For GEN_REQUEST64_CR, use the RPI */
  328. icmd->ulpCt_h = 0;
  329. icmd->ulpCt_l = 0;
  330. }
  331. /* Issue GEN REQ IOCB for NPORT <did> */
  332. lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
  333. "0119 Issue GEN REQ IOCB to NPORT x%x "
  334. "Data: x%x x%x\n",
  335. ndlp->nlp_DID, icmd->ulpIoTag,
  336. vport->port_state);
  337. geniocb->iocb_cmpl = cmpl;
  338. geniocb->drvrTimeout = icmd->ulpTimeout + LPFC_DRVR_TIMEOUT;
  339. geniocb->vport = vport;
  340. geniocb->retry = retry;
  341. rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, geniocb, 0);
  342. if (rc == IOCB_ERROR) {
  343. lpfc_sli_release_iocbq(phba, geniocb);
  344. return 1;
  345. }
  346. return 0;
  347. }
  348. /**
  349. * lpfc_ct_cmd - Build and issue a CT command
  350. * @vport: pointer to a host virtual N_Port data structure.
  351. * @inmp: Pointer to data buffer for response data.
  352. * @bmp: Pointer to BPL for SLI command
  353. * @ndlp: Destination NPort nodelist entry
  354. * @cmpl: completion routine to call when command completes
  355. *
  356. * This function is called for issuing a CT command.
  357. */
  358. static int
  359. lpfc_ct_cmd(struct lpfc_vport *vport, struct lpfc_dmabuf *inmp,
  360. struct lpfc_dmabuf *bmp, struct lpfc_nodelist *ndlp,
  361. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  362. struct lpfc_iocbq *),
  363. uint32_t rsp_size, uint8_t retry)
  364. {
  365. struct lpfc_hba *phba = vport->phba;
  366. struct ulp_bde64 *bpl = (struct ulp_bde64 *) bmp->virt;
  367. struct lpfc_dmabuf *outmp;
  368. int cnt = 0, status;
  369. int cmdcode = ((struct lpfc_sli_ct_request *) inmp->virt)->
  370. CommandResponse.bits.CmdRsp;
  371. bpl++; /* Skip past ct request */
  372. /* Put buffer(s) for ct rsp in bpl */
  373. outmp = lpfc_alloc_ct_rsp(phba, cmdcode, bpl, rsp_size, &cnt);
  374. if (!outmp)
  375. return -ENOMEM;
  376. /*
  377. * Form the CT IOCB. The total number of BDEs in this IOCB
  378. * is the single command plus response count from
  379. * lpfc_alloc_ct_rsp.
  380. */
  381. cnt += 1;
  382. status = lpfc_gen_req(vport, bmp, inmp, outmp, cmpl, ndlp, 0,
  383. cnt, 0, retry);
  384. if (status) {
  385. lpfc_free_ct_rsp(phba, outmp);
  386. return -ENOMEM;
  387. }
  388. return 0;
  389. }
  390. struct lpfc_vport *
  391. lpfc_find_vport_by_did(struct lpfc_hba *phba, uint32_t did) {
  392. struct lpfc_vport *vport_curr;
  393. unsigned long flags;
  394. spin_lock_irqsave(&phba->hbalock, flags);
  395. list_for_each_entry(vport_curr, &phba->port_list, listentry) {
  396. if ((vport_curr->fc_myDID) && (vport_curr->fc_myDID == did)) {
  397. spin_unlock_irqrestore(&phba->hbalock, flags);
  398. return vport_curr;
  399. }
  400. }
  401. spin_unlock_irqrestore(&phba->hbalock, flags);
  402. return NULL;
  403. }
  404. static int
  405. lpfc_ns_rsp(struct lpfc_vport *vport, struct lpfc_dmabuf *mp, uint32_t Size)
  406. {
  407. struct lpfc_hba *phba = vport->phba;
  408. struct lpfc_sli_ct_request *Response =
  409. (struct lpfc_sli_ct_request *) mp->virt;
  410. struct lpfc_nodelist *ndlp = NULL;
  411. struct lpfc_dmabuf *mlast, *next_mp;
  412. uint32_t *ctptr = (uint32_t *) & Response->un.gid.PortType;
  413. uint32_t Did, CTentry;
  414. int Cnt;
  415. struct list_head head;
  416. lpfc_set_disctmo(vport);
  417. vport->num_disc_nodes = 0;
  418. vport->fc_ns_retry = 0;
  419. list_add_tail(&head, &mp->list);
  420. list_for_each_entry_safe(mp, next_mp, &head, list) {
  421. mlast = mp;
  422. Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
  423. Size -= Cnt;
  424. if (!ctptr) {
  425. ctptr = (uint32_t *) mlast->virt;
  426. } else
  427. Cnt -= 16; /* subtract length of CT header */
  428. /* Loop through entire NameServer list of DIDs */
  429. while (Cnt >= sizeof(uint32_t)) {
  430. /* Get next DID from NameServer List */
  431. CTentry = *ctptr++;
  432. Did = ((be32_to_cpu(CTentry)) & Mask_DID);
  433. ndlp = NULL;
  434. /*
  435. * Check for rscn processing or not
  436. * To conserve rpi's, filter out addresses for other
  437. * vports on the same physical HBAs.
  438. */
  439. if ((Did != vport->fc_myDID) &&
  440. ((lpfc_find_vport_by_did(phba, Did) == NULL) ||
  441. vport->cfg_peer_port_login)) {
  442. if ((vport->port_type != LPFC_NPIV_PORT) ||
  443. (!(vport->ct_flags & FC_CT_RFF_ID)) ||
  444. (!vport->cfg_restrict_login)) {
  445. ndlp = lpfc_setup_disc_node(vport, Did);
  446. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  447. lpfc_debugfs_disc_trc(vport,
  448. LPFC_DISC_TRC_CT,
  449. "Parse GID_FTrsp: "
  450. "did:x%x flg:x%x x%x",
  451. Did, ndlp->nlp_flag,
  452. vport->fc_flag);
  453. lpfc_printf_vlog(vport,
  454. KERN_INFO,
  455. LOG_DISCOVERY,
  456. "0238 Process "
  457. "x%x NameServer Rsp"
  458. "Data: x%x x%x x%x\n",
  459. Did, ndlp->nlp_flag,
  460. vport->fc_flag,
  461. vport->fc_rscn_id_cnt);
  462. } else {
  463. lpfc_debugfs_disc_trc(vport,
  464. LPFC_DISC_TRC_CT,
  465. "Skip1 GID_FTrsp: "
  466. "did:x%x flg:x%x cnt:%d",
  467. Did, vport->fc_flag,
  468. vport->fc_rscn_id_cnt);
  469. lpfc_printf_vlog(vport,
  470. KERN_INFO,
  471. LOG_DISCOVERY,
  472. "0239 Skip x%x "
  473. "NameServer Rsp Data: "
  474. "x%x x%x\n",
  475. Did, vport->fc_flag,
  476. vport->fc_rscn_id_cnt);
  477. }
  478. } else {
  479. if (!(vport->fc_flag & FC_RSCN_MODE) ||
  480. (lpfc_rscn_payload_check(vport, Did))) {
  481. lpfc_debugfs_disc_trc(vport,
  482. LPFC_DISC_TRC_CT,
  483. "Query GID_FTrsp: "
  484. "did:x%x flg:x%x cnt:%d",
  485. Did, vport->fc_flag,
  486. vport->fc_rscn_id_cnt);
  487. /* This NPortID was previously
  488. * a FCP target, * Don't even
  489. * bother to send GFF_ID.
  490. */
  491. ndlp = lpfc_findnode_did(vport,
  492. Did);
  493. if (ndlp &&
  494. NLP_CHK_NODE_ACT(ndlp)
  495. && (ndlp->nlp_type &
  496. NLP_FCP_TARGET))
  497. lpfc_setup_disc_node
  498. (vport, Did);
  499. else if (lpfc_ns_cmd(vport,
  500. SLI_CTNS_GFF_ID,
  501. 0, Did) == 0)
  502. vport->num_disc_nodes++;
  503. else
  504. lpfc_setup_disc_node
  505. (vport, Did);
  506. }
  507. else {
  508. lpfc_debugfs_disc_trc(vport,
  509. LPFC_DISC_TRC_CT,
  510. "Skip2 GID_FTrsp: "
  511. "did:x%x flg:x%x cnt:%d",
  512. Did, vport->fc_flag,
  513. vport->fc_rscn_id_cnt);
  514. lpfc_printf_vlog(vport,
  515. KERN_INFO,
  516. LOG_DISCOVERY,
  517. "0245 Skip x%x "
  518. "NameServer Rsp Data: "
  519. "x%x x%x\n",
  520. Did, vport->fc_flag,
  521. vport->fc_rscn_id_cnt);
  522. }
  523. }
  524. }
  525. if (CTentry & (cpu_to_be32(SLI_CT_LAST_ENTRY)))
  526. goto nsout1;
  527. Cnt -= sizeof(uint32_t);
  528. }
  529. ctptr = NULL;
  530. }
  531. nsout1:
  532. list_del(&head);
  533. return 0;
  534. }
  535. static void
  536. lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  537. struct lpfc_iocbq *rspiocb)
  538. {
  539. struct lpfc_vport *vport = cmdiocb->vport;
  540. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  541. IOCB_t *irsp;
  542. struct lpfc_dmabuf *outp;
  543. struct lpfc_sli_ct_request *CTrsp;
  544. struct lpfc_nodelist *ndlp;
  545. int rc;
  546. /* First save ndlp, before we overwrite it */
  547. ndlp = cmdiocb->context_un.ndlp;
  548. /* we pass cmdiocb to state machine which needs rspiocb as well */
  549. cmdiocb->context_un.rsp_iocb = rspiocb;
  550. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  551. irsp = &rspiocb->iocb;
  552. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  553. "GID_FT cmpl: status:x%x/x%x rtry:%d",
  554. irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_ns_retry);
  555. /* Don't bother processing response if vport is being torn down. */
  556. if (vport->load_flag & FC_UNLOADING) {
  557. if (vport->fc_flag & FC_RSCN_MODE)
  558. lpfc_els_flush_rscn(vport);
  559. goto out;
  560. }
  561. if (lpfc_els_chk_latt(vport)) {
  562. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  563. "0216 Link event during NS query\n");
  564. if (vport->fc_flag & FC_RSCN_MODE)
  565. lpfc_els_flush_rscn(vport);
  566. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  567. goto out;
  568. }
  569. if (lpfc_error_lost_link(irsp)) {
  570. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  571. "0226 NS query failed due to link event\n");
  572. if (vport->fc_flag & FC_RSCN_MODE)
  573. lpfc_els_flush_rscn(vport);
  574. goto out;
  575. }
  576. if (irsp->ulpStatus) {
  577. /* Check for retry */
  578. if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
  579. if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
  580. (irsp->un.ulpWord[4] & IOERR_PARAM_MASK) !=
  581. IOERR_NO_RESOURCES)
  582. vport->fc_ns_retry++;
  583. /* CT command is being retried */
  584. rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
  585. vport->fc_ns_retry, 0);
  586. if (rc == 0)
  587. goto out;
  588. }
  589. if (vport->fc_flag & FC_RSCN_MODE)
  590. lpfc_els_flush_rscn(vport);
  591. lpfc_vport_set_state(vport, FC_VPORT_FAILED);
  592. lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
  593. "0257 GID_FT Query error: 0x%x 0x%x\n",
  594. irsp->ulpStatus, vport->fc_ns_retry);
  595. } else {
  596. /* Good status, continue checking */
  597. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  598. if (CTrsp->CommandResponse.bits.CmdRsp ==
  599. cpu_to_be16(SLI_CT_RESPONSE_FS_ACC)) {
  600. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  601. "0208 NameServer Rsp Data: x%x\n",
  602. vport->fc_flag);
  603. lpfc_ns_rsp(vport, outp,
  604. (uint32_t) (irsp->un.genreq64.bdl.bdeSize));
  605. } else if (CTrsp->CommandResponse.bits.CmdRsp ==
  606. be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
  607. /* NameServer Rsp Error */
  608. if ((CTrsp->ReasonCode == SLI_CT_UNABLE_TO_PERFORM_REQ)
  609. && (CTrsp->Explanation == SLI_CT_NO_FC4_TYPES)) {
  610. lpfc_printf_vlog(vport, KERN_INFO,
  611. LOG_DISCOVERY,
  612. "0269 No NameServer Entries "
  613. "Data: x%x x%x x%x x%x\n",
  614. CTrsp->CommandResponse.bits.CmdRsp,
  615. (uint32_t) CTrsp->ReasonCode,
  616. (uint32_t) CTrsp->Explanation,
  617. vport->fc_flag);
  618. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  619. "GID_FT no entry cmd:x%x rsn:x%x exp:x%x",
  620. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  621. (uint32_t) CTrsp->ReasonCode,
  622. (uint32_t) CTrsp->Explanation);
  623. } else {
  624. lpfc_printf_vlog(vport, KERN_INFO,
  625. LOG_DISCOVERY,
  626. "0240 NameServer Rsp Error "
  627. "Data: x%x x%x x%x x%x\n",
  628. CTrsp->CommandResponse.bits.CmdRsp,
  629. (uint32_t) CTrsp->ReasonCode,
  630. (uint32_t) CTrsp->Explanation,
  631. vport->fc_flag);
  632. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  633. "GID_FT rsp err1 cmd:x%x rsn:x%x exp:x%x",
  634. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  635. (uint32_t) CTrsp->ReasonCode,
  636. (uint32_t) CTrsp->Explanation);
  637. }
  638. } else {
  639. /* NameServer Rsp Error */
  640. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  641. "0241 NameServer Rsp Error "
  642. "Data: x%x x%x x%x x%x\n",
  643. CTrsp->CommandResponse.bits.CmdRsp,
  644. (uint32_t) CTrsp->ReasonCode,
  645. (uint32_t) CTrsp->Explanation,
  646. vport->fc_flag);
  647. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  648. "GID_FT rsp err2 cmd:x%x rsn:x%x exp:x%x",
  649. (uint32_t)CTrsp->CommandResponse.bits.CmdRsp,
  650. (uint32_t) CTrsp->ReasonCode,
  651. (uint32_t) CTrsp->Explanation);
  652. }
  653. }
  654. /* Link up / RSCN discovery */
  655. if (vport->num_disc_nodes == 0) {
  656. /*
  657. * The driver has cycled through all Nports in the RSCN payload.
  658. * Complete the handling by cleaning up and marking the
  659. * current driver state.
  660. */
  661. if (vport->port_state >= LPFC_DISC_AUTH) {
  662. if (vport->fc_flag & FC_RSCN_MODE) {
  663. lpfc_els_flush_rscn(vport);
  664. spin_lock_irq(shost->host_lock);
  665. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  666. spin_unlock_irq(shost->host_lock);
  667. }
  668. else
  669. lpfc_els_flush_rscn(vport);
  670. }
  671. lpfc_disc_start(vport);
  672. }
  673. out:
  674. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  675. lpfc_ct_free_iocb(phba, cmdiocb);
  676. return;
  677. }
  678. static void
  679. lpfc_cmpl_ct_cmd_gff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  680. struct lpfc_iocbq *rspiocb)
  681. {
  682. struct lpfc_vport *vport = cmdiocb->vport;
  683. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  684. IOCB_t *irsp = &rspiocb->iocb;
  685. struct lpfc_dmabuf *inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  686. struct lpfc_dmabuf *outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  687. struct lpfc_sli_ct_request *CTrsp;
  688. int did, rc, retry;
  689. uint8_t fbits;
  690. struct lpfc_nodelist *ndlp;
  691. did = ((struct lpfc_sli_ct_request *) inp->virt)->un.gff.PortId;
  692. did = be32_to_cpu(did);
  693. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  694. "GFF_ID cmpl: status:x%x/x%x did:x%x",
  695. irsp->ulpStatus, irsp->un.ulpWord[4], did);
  696. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  697. /* Good status, continue checking */
  698. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  699. fbits = CTrsp->un.gff_acc.fbits[FCP_TYPE_FEATURE_OFFSET];
  700. if (CTrsp->CommandResponse.bits.CmdRsp ==
  701. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC)) {
  702. if ((fbits & FC4_FEATURE_INIT) &&
  703. !(fbits & FC4_FEATURE_TARGET)) {
  704. lpfc_printf_vlog(vport, KERN_INFO,
  705. LOG_DISCOVERY,
  706. "0270 Skip x%x GFF "
  707. "NameServer Rsp Data: (init) "
  708. "x%x x%x\n", did, fbits,
  709. vport->fc_rscn_id_cnt);
  710. goto out;
  711. }
  712. }
  713. }
  714. else {
  715. /* Check for retry */
  716. if (cmdiocb->retry < LPFC_MAX_NS_RETRY) {
  717. retry = 1;
  718. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  719. switch ((irsp->un.ulpWord[4] &
  720. IOERR_PARAM_MASK)) {
  721. case IOERR_NO_RESOURCES:
  722. /* We don't increment the retry
  723. * count for this case.
  724. */
  725. break;
  726. case IOERR_LINK_DOWN:
  727. case IOERR_SLI_ABORTED:
  728. case IOERR_SLI_DOWN:
  729. retry = 0;
  730. break;
  731. default:
  732. cmdiocb->retry++;
  733. }
  734. }
  735. else
  736. cmdiocb->retry++;
  737. if (retry) {
  738. /* CT command is being retried */
  739. rc = lpfc_ns_cmd(vport, SLI_CTNS_GFF_ID,
  740. cmdiocb->retry, did);
  741. if (rc == 0) {
  742. /* success */
  743. lpfc_ct_free_iocb(phba, cmdiocb);
  744. return;
  745. }
  746. }
  747. }
  748. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  749. "0267 NameServer GFF Rsp "
  750. "x%x Error (%d %d) Data: x%x x%x\n",
  751. did, irsp->ulpStatus, irsp->un.ulpWord[4],
  752. vport->fc_flag, vport->fc_rscn_id_cnt);
  753. }
  754. /* This is a target port, unregistered port, or the GFF_ID failed */
  755. ndlp = lpfc_setup_disc_node(vport, did);
  756. if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
  757. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  758. "0242 Process x%x GFF "
  759. "NameServer Rsp Data: x%x x%x x%x\n",
  760. did, ndlp->nlp_flag, vport->fc_flag,
  761. vport->fc_rscn_id_cnt);
  762. } else {
  763. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  764. "0243 Skip x%x GFF "
  765. "NameServer Rsp Data: x%x x%x\n", did,
  766. vport->fc_flag, vport->fc_rscn_id_cnt);
  767. }
  768. out:
  769. /* Link up / RSCN discovery */
  770. if (vport->num_disc_nodes)
  771. vport->num_disc_nodes--;
  772. if (vport->num_disc_nodes == 0) {
  773. /*
  774. * The driver has cycled through all Nports in the RSCN payload.
  775. * Complete the handling by cleaning up and marking the
  776. * current driver state.
  777. */
  778. if (vport->port_state >= LPFC_DISC_AUTH) {
  779. if (vport->fc_flag & FC_RSCN_MODE) {
  780. lpfc_els_flush_rscn(vport);
  781. spin_lock_irq(shost->host_lock);
  782. vport->fc_flag |= FC_RSCN_MODE; /* RSCN still */
  783. spin_unlock_irq(shost->host_lock);
  784. }
  785. else
  786. lpfc_els_flush_rscn(vport);
  787. }
  788. lpfc_disc_start(vport);
  789. }
  790. lpfc_ct_free_iocb(phba, cmdiocb);
  791. return;
  792. }
  793. static void
  794. lpfc_cmpl_ct(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  795. struct lpfc_iocbq *rspiocb)
  796. {
  797. struct lpfc_vport *vport = cmdiocb->vport;
  798. struct lpfc_dmabuf *inp;
  799. struct lpfc_dmabuf *outp;
  800. IOCB_t *irsp;
  801. struct lpfc_sli_ct_request *CTrsp;
  802. struct lpfc_nodelist *ndlp;
  803. int cmdcode, rc;
  804. uint8_t retry;
  805. uint32_t latt;
  806. /* First save ndlp, before we overwrite it */
  807. ndlp = cmdiocb->context_un.ndlp;
  808. /* we pass cmdiocb to state machine which needs rspiocb as well */
  809. cmdiocb->context_un.rsp_iocb = rspiocb;
  810. inp = (struct lpfc_dmabuf *) cmdiocb->context1;
  811. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  812. irsp = &rspiocb->iocb;
  813. cmdcode = be16_to_cpu(((struct lpfc_sli_ct_request *) inp->virt)->
  814. CommandResponse.bits.CmdRsp);
  815. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  816. latt = lpfc_els_chk_latt(vport);
  817. /* RFT request completes status <ulpStatus> CmdRsp <CmdRsp> */
  818. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  819. "0209 CT Request completes, latt %d, "
  820. "ulpStatus x%x CmdRsp x%x, Context x%x, Tag x%x\n",
  821. latt, irsp->ulpStatus,
  822. CTrsp->CommandResponse.bits.CmdRsp,
  823. cmdiocb->iocb.ulpContext, cmdiocb->iocb.ulpIoTag);
  824. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  825. "CT cmd cmpl: status:x%x/x%x cmd:x%x",
  826. irsp->ulpStatus, irsp->un.ulpWord[4], cmdcode);
  827. if (irsp->ulpStatus) {
  828. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  829. "0268 NS cmd x%x Error (x%x x%x)\n",
  830. cmdcode, irsp->ulpStatus, irsp->un.ulpWord[4]);
  831. if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
  832. (((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  833. IOERR_SLI_DOWN) ||
  834. ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK) ==
  835. IOERR_SLI_ABORTED)))
  836. goto out;
  837. retry = cmdiocb->retry;
  838. if (retry >= LPFC_MAX_NS_RETRY)
  839. goto out;
  840. retry++;
  841. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  842. "0250 Retrying NS cmd %x\n", cmdcode);
  843. rc = lpfc_ns_cmd(vport, cmdcode, retry, 0);
  844. if (rc == 0)
  845. goto out;
  846. }
  847. out:
  848. cmdiocb->context_un.ndlp = ndlp; /* Now restore ndlp for free */
  849. lpfc_ct_free_iocb(phba, cmdiocb);
  850. return;
  851. }
  852. static void
  853. lpfc_cmpl_ct_cmd_rft_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  854. struct lpfc_iocbq *rspiocb)
  855. {
  856. IOCB_t *irsp = &rspiocb->iocb;
  857. struct lpfc_vport *vport = cmdiocb->vport;
  858. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  859. struct lpfc_dmabuf *outp;
  860. struct lpfc_sli_ct_request *CTrsp;
  861. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  862. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  863. if (CTrsp->CommandResponse.bits.CmdRsp ==
  864. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  865. vport->ct_flags |= FC_CT_RFT_ID;
  866. }
  867. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  868. return;
  869. }
  870. static void
  871. lpfc_cmpl_ct_cmd_rnn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  872. struct lpfc_iocbq *rspiocb)
  873. {
  874. IOCB_t *irsp = &rspiocb->iocb;
  875. struct lpfc_vport *vport = cmdiocb->vport;
  876. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  877. struct lpfc_dmabuf *outp;
  878. struct lpfc_sli_ct_request *CTrsp;
  879. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  880. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  881. if (CTrsp->CommandResponse.bits.CmdRsp ==
  882. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  883. vport->ct_flags |= FC_CT_RNN_ID;
  884. }
  885. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  886. return;
  887. }
  888. static void
  889. lpfc_cmpl_ct_cmd_rspn_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  890. struct lpfc_iocbq *rspiocb)
  891. {
  892. IOCB_t *irsp = &rspiocb->iocb;
  893. struct lpfc_vport *vport = cmdiocb->vport;
  894. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  895. struct lpfc_dmabuf *outp;
  896. struct lpfc_sli_ct_request *CTrsp;
  897. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  898. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  899. if (CTrsp->CommandResponse.bits.CmdRsp ==
  900. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  901. vport->ct_flags |= FC_CT_RSPN_ID;
  902. }
  903. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  904. return;
  905. }
  906. static void
  907. lpfc_cmpl_ct_cmd_rsnn_nn(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  908. struct lpfc_iocbq *rspiocb)
  909. {
  910. IOCB_t *irsp = &rspiocb->iocb;
  911. struct lpfc_vport *vport = cmdiocb->vport;
  912. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  913. struct lpfc_dmabuf *outp;
  914. struct lpfc_sli_ct_request *CTrsp;
  915. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  916. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  917. if (CTrsp->CommandResponse.bits.CmdRsp ==
  918. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  919. vport->ct_flags |= FC_CT_RSNN_NN;
  920. }
  921. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  922. return;
  923. }
  924. static void
  925. lpfc_cmpl_ct_cmd_da_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  926. struct lpfc_iocbq *rspiocb)
  927. {
  928. struct lpfc_vport *vport = cmdiocb->vport;
  929. /* even if it fails we will act as though it succeeded. */
  930. vport->ct_flags = 0;
  931. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  932. return;
  933. }
  934. static void
  935. lpfc_cmpl_ct_cmd_rff_id(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  936. struct lpfc_iocbq *rspiocb)
  937. {
  938. IOCB_t *irsp = &rspiocb->iocb;
  939. struct lpfc_vport *vport = cmdiocb->vport;
  940. if (irsp->ulpStatus == IOSTAT_SUCCESS) {
  941. struct lpfc_dmabuf *outp;
  942. struct lpfc_sli_ct_request *CTrsp;
  943. outp = (struct lpfc_dmabuf *) cmdiocb->context2;
  944. CTrsp = (struct lpfc_sli_ct_request *) outp->virt;
  945. if (CTrsp->CommandResponse.bits.CmdRsp ==
  946. be16_to_cpu(SLI_CT_RESPONSE_FS_ACC))
  947. vport->ct_flags |= FC_CT_RFF_ID;
  948. }
  949. lpfc_cmpl_ct(phba, cmdiocb, rspiocb);
  950. return;
  951. }
  952. int
  953. lpfc_vport_symbolic_port_name(struct lpfc_vport *vport, char *symbol,
  954. size_t size)
  955. {
  956. int n;
  957. uint8_t *wwn = vport->phba->wwpn;
  958. n = snprintf(symbol, size,
  959. "Emulex PPN-%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
  960. wwn[0], wwn[1], wwn[2], wwn[3],
  961. wwn[4], wwn[5], wwn[6], wwn[7]);
  962. if (vport->port_type == LPFC_PHYSICAL_PORT)
  963. return n;
  964. if (n < size)
  965. n += snprintf(symbol + n, size - n, " VPort-%d", vport->vpi);
  966. if (n < size &&
  967. strlen(vport->fc_vport->symbolic_name))
  968. n += snprintf(symbol + n, size - n, " VName-%s",
  969. vport->fc_vport->symbolic_name);
  970. return n;
  971. }
  972. int
  973. lpfc_vport_symbolic_node_name(struct lpfc_vport *vport, char *symbol,
  974. size_t size)
  975. {
  976. char fwrev[FW_REV_STR_SIZE];
  977. int n;
  978. lpfc_decode_firmware_rev(vport->phba, fwrev, 0);
  979. n = snprintf(symbol, size, "Emulex %s", vport->phba->ModelName);
  980. if (size < n)
  981. return n;
  982. n += snprintf(symbol + n, size - n, " FV%s", fwrev);
  983. if (size < n)
  984. return n;
  985. n += snprintf(symbol + n, size - n, " DV%s", lpfc_release_version);
  986. if (size < n)
  987. return n;
  988. n += snprintf(symbol + n, size - n, " HN:%s", init_utsname()->nodename);
  989. /* Note :- OS name is "Linux" */
  990. if (size < n)
  991. return n;
  992. n += snprintf(symbol + n, size - n, " OS:%s", init_utsname()->sysname);
  993. return n;
  994. }
  995. static uint32_t
  996. lpfc_find_map_node(struct lpfc_vport *vport)
  997. {
  998. struct lpfc_nodelist *ndlp, *next_ndlp;
  999. struct Scsi_Host *shost;
  1000. uint32_t cnt = 0;
  1001. shost = lpfc_shost_from_vport(vport);
  1002. spin_lock_irq(shost->host_lock);
  1003. list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
  1004. if (ndlp->nlp_type & NLP_FABRIC)
  1005. continue;
  1006. if ((ndlp->nlp_state == NLP_STE_MAPPED_NODE) ||
  1007. (ndlp->nlp_state == NLP_STE_UNMAPPED_NODE))
  1008. cnt++;
  1009. }
  1010. spin_unlock_irq(shost->host_lock);
  1011. return cnt;
  1012. }
  1013. /*
  1014. * lpfc_ns_cmd
  1015. * Description:
  1016. * Issue Cmd to NameServer
  1017. * SLI_CTNS_GID_FT
  1018. * LI_CTNS_RFT_ID
  1019. */
  1020. int
  1021. lpfc_ns_cmd(struct lpfc_vport *vport, int cmdcode,
  1022. uint8_t retry, uint32_t context)
  1023. {
  1024. struct lpfc_nodelist * ndlp;
  1025. struct lpfc_hba *phba = vport->phba;
  1026. struct lpfc_dmabuf *mp, *bmp;
  1027. struct lpfc_sli_ct_request *CtReq;
  1028. struct ulp_bde64 *bpl;
  1029. void (*cmpl) (struct lpfc_hba *, struct lpfc_iocbq *,
  1030. struct lpfc_iocbq *) = NULL;
  1031. uint32_t rsp_size = 1024;
  1032. size_t size;
  1033. int rc = 0;
  1034. ndlp = lpfc_findnode_did(vport, NameServer_DID);
  1035. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)
  1036. || ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) {
  1037. rc=1;
  1038. goto ns_cmd_exit;
  1039. }
  1040. /* fill in BDEs for command */
  1041. /* Allocate buffer for command payload */
  1042. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1043. if (!mp) {
  1044. rc=2;
  1045. goto ns_cmd_exit;
  1046. }
  1047. INIT_LIST_HEAD(&mp->list);
  1048. mp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(mp->phys));
  1049. if (!mp->virt) {
  1050. rc=3;
  1051. goto ns_cmd_free_mp;
  1052. }
  1053. /* Allocate buffer for Buffer ptr list */
  1054. bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  1055. if (!bmp) {
  1056. rc=4;
  1057. goto ns_cmd_free_mpvirt;
  1058. }
  1059. INIT_LIST_HEAD(&bmp->list);
  1060. bmp->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &(bmp->phys));
  1061. if (!bmp->virt) {
  1062. rc=5;
  1063. goto ns_cmd_free_bmp;
  1064. }
  1065. /* NameServer Req */
  1066. lpfc_printf_vlog(vport, KERN_INFO ,LOG_DISCOVERY,
  1067. "0236 NameServer Req Data: x%x x%x x%x\n",
  1068. cmdcode, vport->fc_flag, vport->fc_rscn_id_cnt);
  1069. bpl = (struct ulp_bde64 *) bmp->virt;
  1070. memset(bpl, 0, sizeof(struct ulp_bde64));
  1071. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys) );
  1072. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys) );
  1073. bpl->tus.f.bdeFlags = 0;
  1074. if (cmdcode == SLI_CTNS_GID_FT)
  1075. bpl->tus.f.bdeSize = GID_REQUEST_SZ;
  1076. else if (cmdcode == SLI_CTNS_GFF_ID)
  1077. bpl->tus.f.bdeSize = GFF_REQUEST_SZ;
  1078. else if (cmdcode == SLI_CTNS_RFT_ID)
  1079. bpl->tus.f.bdeSize = RFT_REQUEST_SZ;
  1080. else if (cmdcode == SLI_CTNS_RNN_ID)
  1081. bpl->tus.f.bdeSize = RNN_REQUEST_SZ;
  1082. else if (cmdcode == SLI_CTNS_RSPN_ID)
  1083. bpl->tus.f.bdeSize = RSPN_REQUEST_SZ;
  1084. else if (cmdcode == SLI_CTNS_RSNN_NN)
  1085. bpl->tus.f.bdeSize = RSNN_REQUEST_SZ;
  1086. else if (cmdcode == SLI_CTNS_DA_ID)
  1087. bpl->tus.f.bdeSize = DA_ID_REQUEST_SZ;
  1088. else if (cmdcode == SLI_CTNS_RFF_ID)
  1089. bpl->tus.f.bdeSize = RFF_REQUEST_SZ;
  1090. else
  1091. bpl->tus.f.bdeSize = 0;
  1092. bpl->tus.w = le32_to_cpu(bpl->tus.w);
  1093. CtReq = (struct lpfc_sli_ct_request *) mp->virt;
  1094. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  1095. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  1096. CtReq->RevisionId.bits.InId = 0;
  1097. CtReq->FsType = SLI_CT_DIRECTORY_SERVICE;
  1098. CtReq->FsSubType = SLI_CT_DIRECTORY_NAME_SERVER;
  1099. CtReq->CommandResponse.bits.Size = 0;
  1100. switch (cmdcode) {
  1101. case SLI_CTNS_GID_FT:
  1102. CtReq->CommandResponse.bits.CmdRsp =
  1103. cpu_to_be16(SLI_CTNS_GID_FT);
  1104. CtReq->un.gid.Fc4Type = SLI_CTPT_FCP;
  1105. if (vport->port_state < LPFC_NS_QRY)
  1106. vport->port_state = LPFC_NS_QRY;
  1107. lpfc_set_disctmo(vport);
  1108. cmpl = lpfc_cmpl_ct_cmd_gid_ft;
  1109. rsp_size = FC_MAX_NS_RSP;
  1110. break;
  1111. case SLI_CTNS_GFF_ID:
  1112. CtReq->CommandResponse.bits.CmdRsp =
  1113. cpu_to_be16(SLI_CTNS_GFF_ID);
  1114. CtReq->un.gff.PortId = cpu_to_be32(context);
  1115. cmpl = lpfc_cmpl_ct_cmd_gff_id;
  1116. break;
  1117. case SLI_CTNS_RFT_ID:
  1118. vport->ct_flags &= ~FC_CT_RFT_ID;
  1119. CtReq->CommandResponse.bits.CmdRsp =
  1120. cpu_to_be16(SLI_CTNS_RFT_ID);
  1121. CtReq->un.rft.PortId = cpu_to_be32(vport->fc_myDID);
  1122. CtReq->un.rft.fcpReg = 1;
  1123. cmpl = lpfc_cmpl_ct_cmd_rft_id;
  1124. break;
  1125. case SLI_CTNS_RNN_ID:
  1126. vport->ct_flags &= ~FC_CT_RNN_ID;
  1127. CtReq->CommandResponse.bits.CmdRsp =
  1128. cpu_to_be16(SLI_CTNS_RNN_ID);
  1129. CtReq->un.rnn.PortId = cpu_to_be32(vport->fc_myDID);
  1130. memcpy(CtReq->un.rnn.wwnn, &vport->fc_nodename,
  1131. sizeof(struct lpfc_name));
  1132. cmpl = lpfc_cmpl_ct_cmd_rnn_id;
  1133. break;
  1134. case SLI_CTNS_RSPN_ID:
  1135. vport->ct_flags &= ~FC_CT_RSPN_ID;
  1136. CtReq->CommandResponse.bits.CmdRsp =
  1137. cpu_to_be16(SLI_CTNS_RSPN_ID);
  1138. CtReq->un.rspn.PortId = cpu_to_be32(vport->fc_myDID);
  1139. size = sizeof(CtReq->un.rspn.symbname);
  1140. CtReq->un.rspn.len =
  1141. lpfc_vport_symbolic_port_name(vport,
  1142. CtReq->un.rspn.symbname, size);
  1143. cmpl = lpfc_cmpl_ct_cmd_rspn_id;
  1144. break;
  1145. case SLI_CTNS_RSNN_NN:
  1146. vport->ct_flags &= ~FC_CT_RSNN_NN;
  1147. CtReq->CommandResponse.bits.CmdRsp =
  1148. cpu_to_be16(SLI_CTNS_RSNN_NN);
  1149. memcpy(CtReq->un.rsnn.wwnn, &vport->fc_nodename,
  1150. sizeof(struct lpfc_name));
  1151. size = sizeof(CtReq->un.rsnn.symbname);
  1152. CtReq->un.rsnn.len =
  1153. lpfc_vport_symbolic_node_name(vport,
  1154. CtReq->un.rsnn.symbname, size);
  1155. cmpl = lpfc_cmpl_ct_cmd_rsnn_nn;
  1156. break;
  1157. case SLI_CTNS_DA_ID:
  1158. /* Implement DA_ID Nameserver request */
  1159. CtReq->CommandResponse.bits.CmdRsp =
  1160. cpu_to_be16(SLI_CTNS_DA_ID);
  1161. CtReq->un.da_id.port_id = cpu_to_be32(vport->fc_myDID);
  1162. cmpl = lpfc_cmpl_ct_cmd_da_id;
  1163. break;
  1164. case SLI_CTNS_RFF_ID:
  1165. vport->ct_flags &= ~FC_CT_RFF_ID;
  1166. CtReq->CommandResponse.bits.CmdRsp =
  1167. cpu_to_be16(SLI_CTNS_RFF_ID);
  1168. CtReq->un.rff.PortId = cpu_to_be32(vport->fc_myDID);
  1169. CtReq->un.rff.fbits = FC4_FEATURE_INIT;
  1170. CtReq->un.rff.type_code = FC_TYPE_FCP;
  1171. cmpl = lpfc_cmpl_ct_cmd_rff_id;
  1172. break;
  1173. }
  1174. /* The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  1175. * to hold ndlp reference for the corresponding callback function.
  1176. */
  1177. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, retry)) {
  1178. /* On success, The cmpl function will free the buffers */
  1179. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1180. "Issue CT cmd: cmd:x%x did:x%x",
  1181. cmdcode, ndlp->nlp_DID, 0);
  1182. return 0;
  1183. }
  1184. rc=6;
  1185. /* Decrement ndlp reference count to release ndlp reference held
  1186. * for the failed command's callback function.
  1187. */
  1188. lpfc_nlp_put(ndlp);
  1189. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  1190. ns_cmd_free_bmp:
  1191. kfree(bmp);
  1192. ns_cmd_free_mpvirt:
  1193. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  1194. ns_cmd_free_mp:
  1195. kfree(mp);
  1196. ns_cmd_exit:
  1197. lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
  1198. "0266 Issue NameServer Req x%x err %d Data: x%x x%x\n",
  1199. cmdcode, rc, vport->fc_flag, vport->fc_rscn_id_cnt);
  1200. return 1;
  1201. }
  1202. /**
  1203. * lpfc_cmpl_ct_disc_fdmi - Handle a discovery FDMI completion
  1204. * @phba: Pointer to HBA context object.
  1205. * @cmdiocb: Pointer to the command IOCBQ.
  1206. * @rspiocb: Pointer to the response IOCBQ.
  1207. *
  1208. * This function to handle the completion of a driver initiated FDMI
  1209. * CT command issued during discovery.
  1210. */
  1211. static void
  1212. lpfc_cmpl_ct_disc_fdmi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
  1213. struct lpfc_iocbq *rspiocb)
  1214. {
  1215. struct lpfc_vport *vport = cmdiocb->vport;
  1216. struct lpfc_dmabuf *inp = cmdiocb->context1;
  1217. struct lpfc_dmabuf *outp = cmdiocb->context2;
  1218. struct lpfc_sli_ct_request *CTcmd = inp->virt;
  1219. struct lpfc_sli_ct_request *CTrsp = outp->virt;
  1220. uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
  1221. uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
  1222. IOCB_t *irsp = &rspiocb->iocb;
  1223. struct lpfc_nodelist *ndlp;
  1224. uint32_t latt, cmd, err;
  1225. latt = lpfc_els_chk_latt(vport);
  1226. lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_CT,
  1227. "FDMI cmpl: status:x%x/x%x latt:%d",
  1228. irsp->ulpStatus, irsp->un.ulpWord[4], latt);
  1229. if (latt || irsp->ulpStatus) {
  1230. /* Look for a retryable error */
  1231. if (irsp->ulpStatus == IOSTAT_LOCAL_REJECT) {
  1232. switch ((irsp->un.ulpWord[4] & IOERR_PARAM_MASK)) {
  1233. case IOERR_SLI_ABORTED:
  1234. case IOERR_ABORT_IN_PROGRESS:
  1235. case IOERR_SEQUENCE_TIMEOUT:
  1236. case IOERR_ILLEGAL_FRAME:
  1237. case IOERR_NO_RESOURCES:
  1238. case IOERR_ILLEGAL_COMMAND:
  1239. cmdiocb->retry++;
  1240. if (cmdiocb->retry >= LPFC_FDMI_MAX_RETRY)
  1241. break;
  1242. /* Retry the same FDMI command */
  1243. err = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING,
  1244. cmdiocb, 0);
  1245. if (err == IOCB_ERROR)
  1246. break;
  1247. return;
  1248. default:
  1249. break;
  1250. }
  1251. }
  1252. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1253. "0229 FDMI cmd %04x failed, latt = %d "
  1254. "ulpStatus: x%x, rid x%x\n",
  1255. be16_to_cpu(fdmi_cmd), latt, irsp->ulpStatus,
  1256. irsp->un.ulpWord[4]);
  1257. }
  1258. lpfc_ct_free_iocb(phba, cmdiocb);
  1259. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1260. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1261. return;
  1262. /* Check for a CT LS_RJT response */
  1263. cmd = be16_to_cpu(fdmi_cmd);
  1264. if (fdmi_rsp == cpu_to_be16(SLI_CT_RESPONSE_FS_RJT)) {
  1265. /* FDMI rsp failed */
  1266. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  1267. "0220 FDMI cmd failed FS_RJT Data: x%x", cmd);
  1268. /* Should we fallback to FDMI-2 / FDMI-1 ? */
  1269. switch (cmd) {
  1270. case SLI_MGMT_RHBA:
  1271. if (vport->fdmi_hba_mask == LPFC_FDMI2_HBA_ATTR) {
  1272. /* Fallback to FDMI-1 */
  1273. vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
  1274. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  1275. /* Start over */
  1276. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  1277. }
  1278. return;
  1279. case SLI_MGMT_RPRT:
  1280. if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
  1281. /* Fallback to FDMI-1 */
  1282. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  1283. /* Start over */
  1284. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  1285. }
  1286. if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
  1287. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  1288. /* Retry the same command */
  1289. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  1290. }
  1291. return;
  1292. case SLI_MGMT_RPA:
  1293. if (vport->fdmi_port_mask == LPFC_FDMI2_PORT_ATTR) {
  1294. /* Fallback to FDMI-1 */
  1295. vport->fdmi_hba_mask = LPFC_FDMI1_HBA_ATTR;
  1296. vport->fdmi_port_mask = LPFC_FDMI1_PORT_ATTR;
  1297. /* Start over */
  1298. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA, 0);
  1299. }
  1300. if (vport->fdmi_port_mask == LPFC_FDMI2_SMART_ATTR) {
  1301. vport->fdmi_port_mask = LPFC_FDMI2_PORT_ATTR;
  1302. /* Retry the same command */
  1303. lpfc_fdmi_cmd(vport, ndlp, cmd, 0);
  1304. }
  1305. return;
  1306. }
  1307. }
  1308. /*
  1309. * On success, need to cycle thru FDMI registration for discovery
  1310. * DHBA -> DPRT -> RHBA -> RPA (physical port)
  1311. * DPRT -> RPRT (vports)
  1312. */
  1313. switch (cmd) {
  1314. case SLI_MGMT_RHBA:
  1315. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA, 0);
  1316. break;
  1317. case SLI_MGMT_DHBA:
  1318. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DPRT, 0);
  1319. break;
  1320. case SLI_MGMT_DPRT:
  1321. if (vport->port_type == LPFC_PHYSICAL_PORT)
  1322. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RHBA, 0);
  1323. else
  1324. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT, 0);
  1325. break;
  1326. }
  1327. return;
  1328. }
  1329. /**
  1330. * lpfc_fdmi_num_disc_check - Check how many mapped NPorts we are connected to
  1331. * @vport: pointer to a host virtual N_Port data structure.
  1332. *
  1333. * Called from hbeat timeout routine to check if the number of discovered
  1334. * ports has changed. If so, re-register thar port Attribute.
  1335. */
  1336. void
  1337. lpfc_fdmi_num_disc_check(struct lpfc_vport *vport)
  1338. {
  1339. struct lpfc_hba *phba = vport->phba;
  1340. struct lpfc_nodelist *ndlp;
  1341. uint16_t cnt;
  1342. if (!lpfc_is_link_up(phba))
  1343. return;
  1344. /* Must be connected to a Fabric */
  1345. if (!(vport->fc_flag & FC_FABRIC))
  1346. return;
  1347. if (!(vport->fdmi_port_mask & LPFC_FDMI_PORT_ATTR_num_disc))
  1348. return;
  1349. cnt = lpfc_find_map_node(vport);
  1350. if (cnt == vport->fdmi_num_disc)
  1351. return;
  1352. ndlp = lpfc_findnode_did(vport, FDMI_DID);
  1353. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  1354. return;
  1355. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  1356. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPA,
  1357. LPFC_FDMI_PORT_ATTR_num_disc);
  1358. } else {
  1359. lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_RPRT,
  1360. LPFC_FDMI_PORT_ATTR_num_disc);
  1361. }
  1362. }
  1363. /* Routines for all individual HBA attributes */
  1364. static int
  1365. lpfc_fdmi_hba_attr_wwnn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
  1366. {
  1367. struct lpfc_fdmi_attr_entry *ae;
  1368. uint32_t size;
  1369. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1370. memset(ae, 0, sizeof(struct lpfc_name));
  1371. memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
  1372. sizeof(struct lpfc_name));
  1373. size = FOURBYTES + sizeof(struct lpfc_name);
  1374. ad->AttrLen = cpu_to_be16(size);
  1375. ad->AttrType = cpu_to_be16(RHBA_NODENAME);
  1376. return size;
  1377. }
  1378. static int
  1379. lpfc_fdmi_hba_attr_manufacturer(struct lpfc_vport *vport,
  1380. struct lpfc_fdmi_attr_def *ad)
  1381. {
  1382. struct lpfc_fdmi_attr_entry *ae;
  1383. uint32_t len, size;
  1384. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1385. memset(ae, 0, 256);
  1386. strncpy(ae->un.AttrString,
  1387. "Emulex Corporation",
  1388. sizeof(ae->un.AttrString));
  1389. len = strnlen(ae->un.AttrString,
  1390. sizeof(ae->un.AttrString));
  1391. len += (len & 3) ? (4 - (len & 3)) : 4;
  1392. size = FOURBYTES + len;
  1393. ad->AttrLen = cpu_to_be16(size);
  1394. ad->AttrType = cpu_to_be16(RHBA_MANUFACTURER);
  1395. return size;
  1396. }
  1397. static int
  1398. lpfc_fdmi_hba_attr_sn(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad)
  1399. {
  1400. struct lpfc_hba *phba = vport->phba;
  1401. struct lpfc_fdmi_attr_entry *ae;
  1402. uint32_t len, size;
  1403. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1404. memset(ae, 0, 256);
  1405. strncpy(ae->un.AttrString, phba->SerialNumber,
  1406. sizeof(ae->un.AttrString));
  1407. len = strnlen(ae->un.AttrString,
  1408. sizeof(ae->un.AttrString));
  1409. len += (len & 3) ? (4 - (len & 3)) : 4;
  1410. size = FOURBYTES + len;
  1411. ad->AttrLen = cpu_to_be16(size);
  1412. ad->AttrType = cpu_to_be16(RHBA_SERIAL_NUMBER);
  1413. return size;
  1414. }
  1415. static int
  1416. lpfc_fdmi_hba_attr_model(struct lpfc_vport *vport,
  1417. struct lpfc_fdmi_attr_def *ad)
  1418. {
  1419. struct lpfc_hba *phba = vport->phba;
  1420. struct lpfc_fdmi_attr_entry *ae;
  1421. uint32_t len, size;
  1422. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1423. memset(ae, 0, 256);
  1424. strncpy(ae->un.AttrString, phba->ModelName,
  1425. sizeof(ae->un.AttrString));
  1426. len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
  1427. len += (len & 3) ? (4 - (len & 3)) : 4;
  1428. size = FOURBYTES + len;
  1429. ad->AttrLen = cpu_to_be16(size);
  1430. ad->AttrType = cpu_to_be16(RHBA_MODEL);
  1431. return size;
  1432. }
  1433. static int
  1434. lpfc_fdmi_hba_attr_description(struct lpfc_vport *vport,
  1435. struct lpfc_fdmi_attr_def *ad)
  1436. {
  1437. struct lpfc_hba *phba = vport->phba;
  1438. struct lpfc_fdmi_attr_entry *ae;
  1439. uint32_t len, size;
  1440. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1441. memset(ae, 0, 256);
  1442. strncpy(ae->un.AttrString, phba->ModelDesc,
  1443. sizeof(ae->un.AttrString));
  1444. len = strnlen(ae->un.AttrString,
  1445. sizeof(ae->un.AttrString));
  1446. len += (len & 3) ? (4 - (len & 3)) : 4;
  1447. size = FOURBYTES + len;
  1448. ad->AttrLen = cpu_to_be16(size);
  1449. ad->AttrType = cpu_to_be16(RHBA_MODEL_DESCRIPTION);
  1450. return size;
  1451. }
  1452. static int
  1453. lpfc_fdmi_hba_attr_hdw_ver(struct lpfc_vport *vport,
  1454. struct lpfc_fdmi_attr_def *ad)
  1455. {
  1456. struct lpfc_hba *phba = vport->phba;
  1457. lpfc_vpd_t *vp = &phba->vpd;
  1458. struct lpfc_fdmi_attr_entry *ae;
  1459. uint32_t i, j, incr, size;
  1460. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1461. memset(ae, 0, 256);
  1462. /* Convert JEDEC ID to ascii for hardware version */
  1463. incr = vp->rev.biuRev;
  1464. for (i = 0; i < 8; i++) {
  1465. j = (incr & 0xf);
  1466. if (j <= 9)
  1467. ae->un.AttrString[7 - i] =
  1468. (char)((uint8_t) 0x30 +
  1469. (uint8_t) j);
  1470. else
  1471. ae->un.AttrString[7 - i] =
  1472. (char)((uint8_t) 0x61 +
  1473. (uint8_t) (j - 10));
  1474. incr = (incr >> 4);
  1475. }
  1476. size = FOURBYTES + 8;
  1477. ad->AttrLen = cpu_to_be16(size);
  1478. ad->AttrType = cpu_to_be16(RHBA_HARDWARE_VERSION);
  1479. return size;
  1480. }
  1481. static int
  1482. lpfc_fdmi_hba_attr_drvr_ver(struct lpfc_vport *vport,
  1483. struct lpfc_fdmi_attr_def *ad)
  1484. {
  1485. struct lpfc_fdmi_attr_entry *ae;
  1486. uint32_t len, size;
  1487. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1488. memset(ae, 0, 256);
  1489. strncpy(ae->un.AttrString, lpfc_release_version,
  1490. sizeof(ae->un.AttrString));
  1491. len = strnlen(ae->un.AttrString,
  1492. sizeof(ae->un.AttrString));
  1493. len += (len & 3) ? (4 - (len & 3)) : 4;
  1494. size = FOURBYTES + len;
  1495. ad->AttrLen = cpu_to_be16(size);
  1496. ad->AttrType = cpu_to_be16(RHBA_DRIVER_VERSION);
  1497. return size;
  1498. }
  1499. static int
  1500. lpfc_fdmi_hba_attr_rom_ver(struct lpfc_vport *vport,
  1501. struct lpfc_fdmi_attr_def *ad)
  1502. {
  1503. struct lpfc_hba *phba = vport->phba;
  1504. struct lpfc_fdmi_attr_entry *ae;
  1505. uint32_t len, size;
  1506. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1507. memset(ae, 0, 256);
  1508. if (phba->sli_rev == LPFC_SLI_REV4)
  1509. lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
  1510. else
  1511. strncpy(ae->un.AttrString, phba->OptionROMVersion,
  1512. sizeof(ae->un.AttrString));
  1513. len = strnlen(ae->un.AttrString,
  1514. sizeof(ae->un.AttrString));
  1515. len += (len & 3) ? (4 - (len & 3)) : 4;
  1516. size = FOURBYTES + len;
  1517. ad->AttrLen = cpu_to_be16(size);
  1518. ad->AttrType = cpu_to_be16(RHBA_OPTION_ROM_VERSION);
  1519. return size;
  1520. }
  1521. static int
  1522. lpfc_fdmi_hba_attr_fmw_ver(struct lpfc_vport *vport,
  1523. struct lpfc_fdmi_attr_def *ad)
  1524. {
  1525. struct lpfc_hba *phba = vport->phba;
  1526. struct lpfc_fdmi_attr_entry *ae;
  1527. uint32_t len, size;
  1528. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1529. memset(ae, 0, 256);
  1530. lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
  1531. len = strnlen(ae->un.AttrString,
  1532. sizeof(ae->un.AttrString));
  1533. len += (len & 3) ? (4 - (len & 3)) : 4;
  1534. size = FOURBYTES + len;
  1535. ad->AttrLen = cpu_to_be16(size);
  1536. ad->AttrType = cpu_to_be16(RHBA_FIRMWARE_VERSION);
  1537. return size;
  1538. }
  1539. static int
  1540. lpfc_fdmi_hba_attr_os_ver(struct lpfc_vport *vport,
  1541. struct lpfc_fdmi_attr_def *ad)
  1542. {
  1543. struct lpfc_fdmi_attr_entry *ae;
  1544. uint32_t len, size;
  1545. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1546. memset(ae, 0, 256);
  1547. snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s %s %s",
  1548. init_utsname()->sysname,
  1549. init_utsname()->release,
  1550. init_utsname()->version);
  1551. len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
  1552. len += (len & 3) ? (4 - (len & 3)) : 4;
  1553. size = FOURBYTES + len;
  1554. ad->AttrLen = cpu_to_be16(size);
  1555. ad->AttrType = cpu_to_be16(RHBA_OS_NAME_VERSION);
  1556. return size;
  1557. }
  1558. static int
  1559. lpfc_fdmi_hba_attr_ct_len(struct lpfc_vport *vport,
  1560. struct lpfc_fdmi_attr_def *ad)
  1561. {
  1562. struct lpfc_fdmi_attr_entry *ae;
  1563. uint32_t size;
  1564. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1565. ae->un.AttrInt = cpu_to_be32(LPFC_MAX_CT_SIZE);
  1566. size = FOURBYTES + sizeof(uint32_t);
  1567. ad->AttrLen = cpu_to_be16(size);
  1568. ad->AttrType = cpu_to_be16(RHBA_MAX_CT_PAYLOAD_LEN);
  1569. return size;
  1570. }
  1571. static int
  1572. lpfc_fdmi_hba_attr_symbolic_name(struct lpfc_vport *vport,
  1573. struct lpfc_fdmi_attr_def *ad)
  1574. {
  1575. struct lpfc_fdmi_attr_entry *ae;
  1576. uint32_t len, size;
  1577. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1578. memset(ae, 0, 256);
  1579. len = lpfc_vport_symbolic_node_name(vport,
  1580. ae->un.AttrString, 256);
  1581. len += (len & 3) ? (4 - (len & 3)) : 4;
  1582. size = FOURBYTES + len;
  1583. ad->AttrLen = cpu_to_be16(size);
  1584. ad->AttrType = cpu_to_be16(RHBA_SYM_NODENAME);
  1585. return size;
  1586. }
  1587. static int
  1588. lpfc_fdmi_hba_attr_vendor_info(struct lpfc_vport *vport,
  1589. struct lpfc_fdmi_attr_def *ad)
  1590. {
  1591. struct lpfc_fdmi_attr_entry *ae;
  1592. uint32_t size;
  1593. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1594. /* Nothing is defined for this currently */
  1595. ae->un.AttrInt = cpu_to_be32(0);
  1596. size = FOURBYTES + sizeof(uint32_t);
  1597. ad->AttrLen = cpu_to_be16(size);
  1598. ad->AttrType = cpu_to_be16(RHBA_VENDOR_INFO);
  1599. return size;
  1600. }
  1601. static int
  1602. lpfc_fdmi_hba_attr_num_ports(struct lpfc_vport *vport,
  1603. struct lpfc_fdmi_attr_def *ad)
  1604. {
  1605. struct lpfc_fdmi_attr_entry *ae;
  1606. uint32_t size;
  1607. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1608. /* Each driver instance corresponds to a single port */
  1609. ae->un.AttrInt = cpu_to_be32(1);
  1610. size = FOURBYTES + sizeof(uint32_t);
  1611. ad->AttrLen = cpu_to_be16(size);
  1612. ad->AttrType = cpu_to_be16(RHBA_NUM_PORTS);
  1613. return size;
  1614. }
  1615. static int
  1616. lpfc_fdmi_hba_attr_fabric_wwnn(struct lpfc_vport *vport,
  1617. struct lpfc_fdmi_attr_def *ad)
  1618. {
  1619. struct lpfc_fdmi_attr_entry *ae;
  1620. uint32_t size;
  1621. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1622. memset(ae, 0, sizeof(struct lpfc_name));
  1623. memcpy(&ae->un.AttrWWN, &vport->fabric_nodename,
  1624. sizeof(struct lpfc_name));
  1625. size = FOURBYTES + sizeof(struct lpfc_name);
  1626. ad->AttrLen = cpu_to_be16(size);
  1627. ad->AttrType = cpu_to_be16(RHBA_FABRIC_WWNN);
  1628. return size;
  1629. }
  1630. static int
  1631. lpfc_fdmi_hba_attr_bios_ver(struct lpfc_vport *vport,
  1632. struct lpfc_fdmi_attr_def *ad)
  1633. {
  1634. struct lpfc_hba *phba = vport->phba;
  1635. struct lpfc_fdmi_attr_entry *ae;
  1636. uint32_t len, size;
  1637. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1638. memset(ae, 0, 256);
  1639. lpfc_decode_firmware_rev(phba, ae->un.AttrString, 1);
  1640. len = strnlen(ae->un.AttrString,
  1641. sizeof(ae->un.AttrString));
  1642. len += (len & 3) ? (4 - (len & 3)) : 4;
  1643. size = FOURBYTES + len;
  1644. ad->AttrLen = cpu_to_be16(size);
  1645. ad->AttrType = cpu_to_be16(RHBA_BIOS_VERSION);
  1646. return size;
  1647. }
  1648. static int
  1649. lpfc_fdmi_hba_attr_bios_state(struct lpfc_vport *vport,
  1650. struct lpfc_fdmi_attr_def *ad)
  1651. {
  1652. struct lpfc_fdmi_attr_entry *ae;
  1653. uint32_t size;
  1654. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1655. /* Driver doesn't have access to this information */
  1656. ae->un.AttrInt = cpu_to_be32(0);
  1657. size = FOURBYTES + sizeof(uint32_t);
  1658. ad->AttrLen = cpu_to_be16(size);
  1659. ad->AttrType = cpu_to_be16(RHBA_BIOS_STATE);
  1660. return size;
  1661. }
  1662. static int
  1663. lpfc_fdmi_hba_attr_vendor_id(struct lpfc_vport *vport,
  1664. struct lpfc_fdmi_attr_def *ad)
  1665. {
  1666. struct lpfc_fdmi_attr_entry *ae;
  1667. uint32_t len, size;
  1668. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1669. memset(ae, 0, 256);
  1670. strncpy(ae->un.AttrString, "EMULEX",
  1671. sizeof(ae->un.AttrString));
  1672. len = strnlen(ae->un.AttrString,
  1673. sizeof(ae->un.AttrString));
  1674. len += (len & 3) ? (4 - (len & 3)) : 4;
  1675. size = FOURBYTES + len;
  1676. ad->AttrLen = cpu_to_be16(size);
  1677. ad->AttrType = cpu_to_be16(RHBA_VENDOR_ID);
  1678. return size;
  1679. }
  1680. /* Routines for all individual PORT attributes */
  1681. static int
  1682. lpfc_fdmi_port_attr_fc4type(struct lpfc_vport *vport,
  1683. struct lpfc_fdmi_attr_def *ad)
  1684. {
  1685. struct lpfc_fdmi_attr_entry *ae;
  1686. uint32_t size;
  1687. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1688. memset(ae, 0, 32);
  1689. ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
  1690. ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
  1691. ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
  1692. size = FOURBYTES + 32;
  1693. ad->AttrLen = cpu_to_be16(size);
  1694. ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_FC4_TYPES);
  1695. return size;
  1696. }
  1697. static int
  1698. lpfc_fdmi_port_attr_support_speed(struct lpfc_vport *vport,
  1699. struct lpfc_fdmi_attr_def *ad)
  1700. {
  1701. struct lpfc_hba *phba = vport->phba;
  1702. struct lpfc_fdmi_attr_entry *ae;
  1703. uint32_t size;
  1704. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1705. ae->un.AttrInt = 0;
  1706. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  1707. if (phba->lmt & LMT_32Gb)
  1708. ae->un.AttrInt |= HBA_PORTSPEED_32GFC;
  1709. if (phba->lmt & LMT_16Gb)
  1710. ae->un.AttrInt |= HBA_PORTSPEED_16GFC;
  1711. if (phba->lmt & LMT_10Gb)
  1712. ae->un.AttrInt |= HBA_PORTSPEED_10GFC;
  1713. if (phba->lmt & LMT_8Gb)
  1714. ae->un.AttrInt |= HBA_PORTSPEED_8GFC;
  1715. if (phba->lmt & LMT_4Gb)
  1716. ae->un.AttrInt |= HBA_PORTSPEED_4GFC;
  1717. if (phba->lmt & LMT_2Gb)
  1718. ae->un.AttrInt |= HBA_PORTSPEED_2GFC;
  1719. if (phba->lmt & LMT_1Gb)
  1720. ae->un.AttrInt |= HBA_PORTSPEED_1GFC;
  1721. } else {
  1722. /* FCoE links support only one speed */
  1723. switch (phba->fc_linkspeed) {
  1724. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  1725. ae->un.AttrInt = HBA_PORTSPEED_10GE;
  1726. break;
  1727. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  1728. ae->un.AttrInt = HBA_PORTSPEED_25GE;
  1729. break;
  1730. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  1731. ae->un.AttrInt = HBA_PORTSPEED_40GE;
  1732. break;
  1733. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  1734. ae->un.AttrInt = HBA_PORTSPEED_100GE;
  1735. break;
  1736. }
  1737. }
  1738. ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
  1739. size = FOURBYTES + sizeof(uint32_t);
  1740. ad->AttrLen = cpu_to_be16(size);
  1741. ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_SPEED);
  1742. return size;
  1743. }
  1744. static int
  1745. lpfc_fdmi_port_attr_speed(struct lpfc_vport *vport,
  1746. struct lpfc_fdmi_attr_def *ad)
  1747. {
  1748. struct lpfc_hba *phba = vport->phba;
  1749. struct lpfc_fdmi_attr_entry *ae;
  1750. uint32_t size;
  1751. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1752. if (!(phba->hba_flag & HBA_FCOE_MODE)) {
  1753. switch (phba->fc_linkspeed) {
  1754. case LPFC_LINK_SPEED_1GHZ:
  1755. ae->un.AttrInt = HBA_PORTSPEED_1GFC;
  1756. break;
  1757. case LPFC_LINK_SPEED_2GHZ:
  1758. ae->un.AttrInt = HBA_PORTSPEED_2GFC;
  1759. break;
  1760. case LPFC_LINK_SPEED_4GHZ:
  1761. ae->un.AttrInt = HBA_PORTSPEED_4GFC;
  1762. break;
  1763. case LPFC_LINK_SPEED_8GHZ:
  1764. ae->un.AttrInt = HBA_PORTSPEED_8GFC;
  1765. break;
  1766. case LPFC_LINK_SPEED_10GHZ:
  1767. ae->un.AttrInt = HBA_PORTSPEED_10GFC;
  1768. break;
  1769. case LPFC_LINK_SPEED_16GHZ:
  1770. ae->un.AttrInt = HBA_PORTSPEED_16GFC;
  1771. break;
  1772. case LPFC_LINK_SPEED_32GHZ:
  1773. ae->un.AttrInt = HBA_PORTSPEED_32GFC;
  1774. break;
  1775. default:
  1776. ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
  1777. break;
  1778. }
  1779. } else {
  1780. switch (phba->fc_linkspeed) {
  1781. case LPFC_ASYNC_LINK_SPEED_10GBPS:
  1782. ae->un.AttrInt = HBA_PORTSPEED_10GE;
  1783. break;
  1784. case LPFC_ASYNC_LINK_SPEED_25GBPS:
  1785. ae->un.AttrInt = HBA_PORTSPEED_25GE;
  1786. break;
  1787. case LPFC_ASYNC_LINK_SPEED_40GBPS:
  1788. ae->un.AttrInt = HBA_PORTSPEED_40GE;
  1789. break;
  1790. case LPFC_ASYNC_LINK_SPEED_100GBPS:
  1791. ae->un.AttrInt = HBA_PORTSPEED_100GE;
  1792. break;
  1793. default:
  1794. ae->un.AttrInt = HBA_PORTSPEED_UNKNOWN;
  1795. break;
  1796. }
  1797. }
  1798. ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
  1799. size = FOURBYTES + sizeof(uint32_t);
  1800. ad->AttrLen = cpu_to_be16(size);
  1801. ad->AttrType = cpu_to_be16(RPRT_PORT_SPEED);
  1802. return size;
  1803. }
  1804. static int
  1805. lpfc_fdmi_port_attr_max_frame(struct lpfc_vport *vport,
  1806. struct lpfc_fdmi_attr_def *ad)
  1807. {
  1808. struct serv_parm *hsp;
  1809. struct lpfc_fdmi_attr_entry *ae;
  1810. uint32_t size;
  1811. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1812. hsp = (struct serv_parm *)&vport->fc_sparam;
  1813. ae->un.AttrInt = (((uint32_t) hsp->cmn.bbRcvSizeMsb) << 8) |
  1814. (uint32_t) hsp->cmn.bbRcvSizeLsb;
  1815. ae->un.AttrInt = cpu_to_be32(ae->un.AttrInt);
  1816. size = FOURBYTES + sizeof(uint32_t);
  1817. ad->AttrLen = cpu_to_be16(size);
  1818. ad->AttrType = cpu_to_be16(RPRT_MAX_FRAME_SIZE);
  1819. return size;
  1820. }
  1821. static int
  1822. lpfc_fdmi_port_attr_os_devname(struct lpfc_vport *vport,
  1823. struct lpfc_fdmi_attr_def *ad)
  1824. {
  1825. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1826. struct lpfc_fdmi_attr_entry *ae;
  1827. uint32_t len, size;
  1828. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1829. memset(ae, 0, 256);
  1830. snprintf(ae->un.AttrString, sizeof(ae->un.AttrString),
  1831. "/sys/class/scsi_host/host%d", shost->host_no);
  1832. len = strnlen((char *)ae->un.AttrString,
  1833. sizeof(ae->un.AttrString));
  1834. len += (len & 3) ? (4 - (len & 3)) : 4;
  1835. size = FOURBYTES + len;
  1836. ad->AttrLen = cpu_to_be16(size);
  1837. ad->AttrType = cpu_to_be16(RPRT_OS_DEVICE_NAME);
  1838. return size;
  1839. }
  1840. static int
  1841. lpfc_fdmi_port_attr_host_name(struct lpfc_vport *vport,
  1842. struct lpfc_fdmi_attr_def *ad)
  1843. {
  1844. struct lpfc_fdmi_attr_entry *ae;
  1845. uint32_t len, size;
  1846. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1847. memset(ae, 0, 256);
  1848. snprintf(ae->un.AttrString, sizeof(ae->un.AttrString), "%s",
  1849. init_utsname()->nodename);
  1850. len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
  1851. len += (len & 3) ? (4 - (len & 3)) : 4;
  1852. size = FOURBYTES + len;
  1853. ad->AttrLen = cpu_to_be16(size);
  1854. ad->AttrType = cpu_to_be16(RPRT_HOST_NAME);
  1855. return size;
  1856. }
  1857. static int
  1858. lpfc_fdmi_port_attr_wwnn(struct lpfc_vport *vport,
  1859. struct lpfc_fdmi_attr_def *ad)
  1860. {
  1861. struct lpfc_fdmi_attr_entry *ae;
  1862. uint32_t size;
  1863. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1864. memset(ae, 0, sizeof(struct lpfc_name));
  1865. memcpy(&ae->un.AttrWWN, &vport->fc_sparam.nodeName,
  1866. sizeof(struct lpfc_name));
  1867. size = FOURBYTES + sizeof(struct lpfc_name);
  1868. ad->AttrLen = cpu_to_be16(size);
  1869. ad->AttrType = cpu_to_be16(RPRT_NODENAME);
  1870. return size;
  1871. }
  1872. static int
  1873. lpfc_fdmi_port_attr_wwpn(struct lpfc_vport *vport,
  1874. struct lpfc_fdmi_attr_def *ad)
  1875. {
  1876. struct lpfc_fdmi_attr_entry *ae;
  1877. uint32_t size;
  1878. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1879. memset(ae, 0, sizeof(struct lpfc_name));
  1880. memcpy(&ae->un.AttrWWN, &vport->fc_sparam.portName,
  1881. sizeof(struct lpfc_name));
  1882. size = FOURBYTES + sizeof(struct lpfc_name);
  1883. ad->AttrLen = cpu_to_be16(size);
  1884. ad->AttrType = cpu_to_be16(RPRT_PORTNAME);
  1885. return size;
  1886. }
  1887. static int
  1888. lpfc_fdmi_port_attr_symbolic_name(struct lpfc_vport *vport,
  1889. struct lpfc_fdmi_attr_def *ad)
  1890. {
  1891. struct lpfc_fdmi_attr_entry *ae;
  1892. uint32_t len, size;
  1893. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1894. memset(ae, 0, 256);
  1895. len = lpfc_vport_symbolic_port_name(vport, ae->un.AttrString, 256);
  1896. len += (len & 3) ? (4 - (len & 3)) : 4;
  1897. size = FOURBYTES + len;
  1898. ad->AttrLen = cpu_to_be16(size);
  1899. ad->AttrType = cpu_to_be16(RPRT_SYM_PORTNAME);
  1900. return size;
  1901. }
  1902. static int
  1903. lpfc_fdmi_port_attr_port_type(struct lpfc_vport *vport,
  1904. struct lpfc_fdmi_attr_def *ad)
  1905. {
  1906. struct lpfc_hba *phba = vport->phba;
  1907. struct lpfc_fdmi_attr_entry *ae;
  1908. uint32_t size;
  1909. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1910. if (phba->fc_topology == LPFC_TOPOLOGY_LOOP)
  1911. ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NLPORT);
  1912. else
  1913. ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTTYPE_NPORT);
  1914. size = FOURBYTES + sizeof(uint32_t);
  1915. ad->AttrLen = cpu_to_be16(size);
  1916. ad->AttrType = cpu_to_be16(RPRT_PORT_TYPE);
  1917. return size;
  1918. }
  1919. static int
  1920. lpfc_fdmi_port_attr_class(struct lpfc_vport *vport,
  1921. struct lpfc_fdmi_attr_def *ad)
  1922. {
  1923. struct lpfc_fdmi_attr_entry *ae;
  1924. uint32_t size;
  1925. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1926. ae->un.AttrInt = cpu_to_be32(FC_COS_CLASS2 | FC_COS_CLASS3);
  1927. size = FOURBYTES + sizeof(uint32_t);
  1928. ad->AttrLen = cpu_to_be16(size);
  1929. ad->AttrType = cpu_to_be16(RPRT_SUPPORTED_CLASS);
  1930. return size;
  1931. }
  1932. static int
  1933. lpfc_fdmi_port_attr_fabric_wwpn(struct lpfc_vport *vport,
  1934. struct lpfc_fdmi_attr_def *ad)
  1935. {
  1936. struct lpfc_fdmi_attr_entry *ae;
  1937. uint32_t size;
  1938. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1939. memset(ae, 0, sizeof(struct lpfc_name));
  1940. memcpy(&ae->un.AttrWWN, &vport->fabric_portname,
  1941. sizeof(struct lpfc_name));
  1942. size = FOURBYTES + sizeof(struct lpfc_name);
  1943. ad->AttrLen = cpu_to_be16(size);
  1944. ad->AttrType = cpu_to_be16(RPRT_FABRICNAME);
  1945. return size;
  1946. }
  1947. static int
  1948. lpfc_fdmi_port_attr_active_fc4type(struct lpfc_vport *vport,
  1949. struct lpfc_fdmi_attr_def *ad)
  1950. {
  1951. struct lpfc_fdmi_attr_entry *ae;
  1952. uint32_t size;
  1953. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1954. memset(ae, 0, 32);
  1955. ae->un.AttrTypes[3] = 0x02; /* Type 1 - ELS */
  1956. ae->un.AttrTypes[2] = 0x01; /* Type 8 - FCP */
  1957. ae->un.AttrTypes[7] = 0x01; /* Type 32 - CT */
  1958. size = FOURBYTES + 32;
  1959. ad->AttrLen = cpu_to_be16(size);
  1960. ad->AttrType = cpu_to_be16(RPRT_ACTIVE_FC4_TYPES);
  1961. return size;
  1962. }
  1963. static int
  1964. lpfc_fdmi_port_attr_port_state(struct lpfc_vport *vport,
  1965. struct lpfc_fdmi_attr_def *ad)
  1966. {
  1967. struct lpfc_fdmi_attr_entry *ae;
  1968. uint32_t size;
  1969. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1970. /* Link Up - operational */
  1971. ae->un.AttrInt = cpu_to_be32(LPFC_FDMI_PORTSTATE_ONLINE);
  1972. size = FOURBYTES + sizeof(uint32_t);
  1973. ad->AttrLen = cpu_to_be16(size);
  1974. ad->AttrType = cpu_to_be16(RPRT_PORT_STATE);
  1975. return size;
  1976. }
  1977. static int
  1978. lpfc_fdmi_port_attr_num_disc(struct lpfc_vport *vport,
  1979. struct lpfc_fdmi_attr_def *ad)
  1980. {
  1981. struct lpfc_fdmi_attr_entry *ae;
  1982. uint32_t size;
  1983. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1984. vport->fdmi_num_disc = lpfc_find_map_node(vport);
  1985. ae->un.AttrInt = cpu_to_be32(vport->fdmi_num_disc);
  1986. size = FOURBYTES + sizeof(uint32_t);
  1987. ad->AttrLen = cpu_to_be16(size);
  1988. ad->AttrType = cpu_to_be16(RPRT_DISC_PORT);
  1989. return size;
  1990. }
  1991. static int
  1992. lpfc_fdmi_port_attr_nportid(struct lpfc_vport *vport,
  1993. struct lpfc_fdmi_attr_def *ad)
  1994. {
  1995. struct lpfc_fdmi_attr_entry *ae;
  1996. uint32_t size;
  1997. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  1998. ae->un.AttrInt = cpu_to_be32(vport->fc_myDID);
  1999. size = FOURBYTES + sizeof(uint32_t);
  2000. ad->AttrLen = cpu_to_be16(size);
  2001. ad->AttrType = cpu_to_be16(RPRT_PORT_ID);
  2002. return size;
  2003. }
  2004. static int
  2005. lpfc_fdmi_smart_attr_service(struct lpfc_vport *vport,
  2006. struct lpfc_fdmi_attr_def *ad)
  2007. {
  2008. struct lpfc_fdmi_attr_entry *ae;
  2009. uint32_t len, size;
  2010. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2011. memset(ae, 0, 256);
  2012. strncpy(ae->un.AttrString, "Smart SAN Initiator",
  2013. sizeof(ae->un.AttrString));
  2014. len = strnlen(ae->un.AttrString,
  2015. sizeof(ae->un.AttrString));
  2016. len += (len & 3) ? (4 - (len & 3)) : 4;
  2017. size = FOURBYTES + len;
  2018. ad->AttrLen = cpu_to_be16(size);
  2019. ad->AttrType = cpu_to_be16(RPRT_SMART_SERVICE);
  2020. return size;
  2021. }
  2022. static int
  2023. lpfc_fdmi_smart_attr_guid(struct lpfc_vport *vport,
  2024. struct lpfc_fdmi_attr_def *ad)
  2025. {
  2026. struct lpfc_fdmi_attr_entry *ae;
  2027. uint32_t size;
  2028. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2029. memset(ae, 0, 256);
  2030. memcpy(&ae->un.AttrString, &vport->fc_sparam.nodeName,
  2031. sizeof(struct lpfc_name));
  2032. memcpy((((uint8_t *)&ae->un.AttrString) +
  2033. sizeof(struct lpfc_name)),
  2034. &vport->fc_sparam.portName, sizeof(struct lpfc_name));
  2035. size = FOURBYTES + (2 * sizeof(struct lpfc_name));
  2036. ad->AttrLen = cpu_to_be16(size);
  2037. ad->AttrType = cpu_to_be16(RPRT_SMART_GUID);
  2038. return size;
  2039. }
  2040. static int
  2041. lpfc_fdmi_smart_attr_version(struct lpfc_vport *vport,
  2042. struct lpfc_fdmi_attr_def *ad)
  2043. {
  2044. struct lpfc_fdmi_attr_entry *ae;
  2045. uint32_t len, size;
  2046. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2047. memset(ae, 0, 256);
  2048. strncpy(ae->un.AttrString, "Smart SAN Version 2.0",
  2049. sizeof(ae->un.AttrString));
  2050. len = strnlen(ae->un.AttrString,
  2051. sizeof(ae->un.AttrString));
  2052. len += (len & 3) ? (4 - (len & 3)) : 4;
  2053. size = FOURBYTES + len;
  2054. ad->AttrLen = cpu_to_be16(size);
  2055. ad->AttrType = cpu_to_be16(RPRT_SMART_VERSION);
  2056. return size;
  2057. }
  2058. static int
  2059. lpfc_fdmi_smart_attr_model(struct lpfc_vport *vport,
  2060. struct lpfc_fdmi_attr_def *ad)
  2061. {
  2062. struct lpfc_hba *phba = vport->phba;
  2063. struct lpfc_fdmi_attr_entry *ae;
  2064. uint32_t len, size;
  2065. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2066. memset(ae, 0, 256);
  2067. strncpy(ae->un.AttrString, phba->ModelName,
  2068. sizeof(ae->un.AttrString));
  2069. len = strnlen(ae->un.AttrString, sizeof(ae->un.AttrString));
  2070. len += (len & 3) ? (4 - (len & 3)) : 4;
  2071. size = FOURBYTES + len;
  2072. ad->AttrLen = cpu_to_be16(size);
  2073. ad->AttrType = cpu_to_be16(RPRT_SMART_MODEL);
  2074. return size;
  2075. }
  2076. static int
  2077. lpfc_fdmi_smart_attr_port_info(struct lpfc_vport *vport,
  2078. struct lpfc_fdmi_attr_def *ad)
  2079. {
  2080. struct lpfc_fdmi_attr_entry *ae;
  2081. uint32_t size;
  2082. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2083. /* SRIOV (type 3) is not supported */
  2084. if (vport->vpi)
  2085. ae->un.AttrInt = cpu_to_be32(2); /* NPIV */
  2086. else
  2087. ae->un.AttrInt = cpu_to_be32(1); /* Physical */
  2088. size = FOURBYTES + sizeof(uint32_t);
  2089. ad->AttrLen = cpu_to_be16(size);
  2090. ad->AttrType = cpu_to_be16(RPRT_SMART_PORT_INFO);
  2091. return size;
  2092. }
  2093. static int
  2094. lpfc_fdmi_smart_attr_qos(struct lpfc_vport *vport,
  2095. struct lpfc_fdmi_attr_def *ad)
  2096. {
  2097. struct lpfc_fdmi_attr_entry *ae;
  2098. uint32_t size;
  2099. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2100. ae->un.AttrInt = cpu_to_be32(0);
  2101. size = FOURBYTES + sizeof(uint32_t);
  2102. ad->AttrLen = cpu_to_be16(size);
  2103. ad->AttrType = cpu_to_be16(RPRT_SMART_QOS);
  2104. return size;
  2105. }
  2106. static int
  2107. lpfc_fdmi_smart_attr_security(struct lpfc_vport *vport,
  2108. struct lpfc_fdmi_attr_def *ad)
  2109. {
  2110. struct lpfc_fdmi_attr_entry *ae;
  2111. uint32_t size;
  2112. ae = (struct lpfc_fdmi_attr_entry *)&ad->AttrValue;
  2113. ae->un.AttrInt = cpu_to_be32(1);
  2114. size = FOURBYTES + sizeof(uint32_t);
  2115. ad->AttrLen = cpu_to_be16(size);
  2116. ad->AttrType = cpu_to_be16(RPRT_SMART_SECURITY);
  2117. return size;
  2118. }
  2119. /* RHBA attribute jump table */
  2120. int (*lpfc_fdmi_hba_action[])
  2121. (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
  2122. /* Action routine Mask bit Attribute type */
  2123. lpfc_fdmi_hba_attr_wwnn, /* bit0 RHBA_NODENAME */
  2124. lpfc_fdmi_hba_attr_manufacturer, /* bit1 RHBA_MANUFACTURER */
  2125. lpfc_fdmi_hba_attr_sn, /* bit2 RHBA_SERIAL_NUMBER */
  2126. lpfc_fdmi_hba_attr_model, /* bit3 RHBA_MODEL */
  2127. lpfc_fdmi_hba_attr_description, /* bit4 RHBA_MODEL_DESCRIPTION */
  2128. lpfc_fdmi_hba_attr_hdw_ver, /* bit5 RHBA_HARDWARE_VERSION */
  2129. lpfc_fdmi_hba_attr_drvr_ver, /* bit6 RHBA_DRIVER_VERSION */
  2130. lpfc_fdmi_hba_attr_rom_ver, /* bit7 RHBA_OPTION_ROM_VERSION */
  2131. lpfc_fdmi_hba_attr_fmw_ver, /* bit8 RHBA_FIRMWARE_VERSION */
  2132. lpfc_fdmi_hba_attr_os_ver, /* bit9 RHBA_OS_NAME_VERSION */
  2133. lpfc_fdmi_hba_attr_ct_len, /* bit10 RHBA_MAX_CT_PAYLOAD_LEN */
  2134. lpfc_fdmi_hba_attr_symbolic_name, /* bit11 RHBA_SYM_NODENAME */
  2135. lpfc_fdmi_hba_attr_vendor_info, /* bit12 RHBA_VENDOR_INFO */
  2136. lpfc_fdmi_hba_attr_num_ports, /* bit13 RHBA_NUM_PORTS */
  2137. lpfc_fdmi_hba_attr_fabric_wwnn, /* bit14 RHBA_FABRIC_WWNN */
  2138. lpfc_fdmi_hba_attr_bios_ver, /* bit15 RHBA_BIOS_VERSION */
  2139. lpfc_fdmi_hba_attr_bios_state, /* bit16 RHBA_BIOS_STATE */
  2140. lpfc_fdmi_hba_attr_vendor_id, /* bit17 RHBA_VENDOR_ID */
  2141. };
  2142. /* RPA / RPRT attribute jump table */
  2143. int (*lpfc_fdmi_port_action[])
  2144. (struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad) = {
  2145. /* Action routine Mask bit Attribute type */
  2146. lpfc_fdmi_port_attr_fc4type, /* bit0 RPRT_SUPPORT_FC4_TYPES */
  2147. lpfc_fdmi_port_attr_support_speed, /* bit1 RPRT_SUPPORTED_SPEED */
  2148. lpfc_fdmi_port_attr_speed, /* bit2 RPRT_PORT_SPEED */
  2149. lpfc_fdmi_port_attr_max_frame, /* bit3 RPRT_MAX_FRAME_SIZE */
  2150. lpfc_fdmi_port_attr_os_devname, /* bit4 RPRT_OS_DEVICE_NAME */
  2151. lpfc_fdmi_port_attr_host_name, /* bit5 RPRT_HOST_NAME */
  2152. lpfc_fdmi_port_attr_wwnn, /* bit6 RPRT_NODENAME */
  2153. lpfc_fdmi_port_attr_wwpn, /* bit7 RPRT_PORTNAME */
  2154. lpfc_fdmi_port_attr_symbolic_name, /* bit8 RPRT_SYM_PORTNAME */
  2155. lpfc_fdmi_port_attr_port_type, /* bit9 RPRT_PORT_TYPE */
  2156. lpfc_fdmi_port_attr_class, /* bit10 RPRT_SUPPORTED_CLASS */
  2157. lpfc_fdmi_port_attr_fabric_wwpn, /* bit11 RPRT_FABRICNAME */
  2158. lpfc_fdmi_port_attr_active_fc4type, /* bit12 RPRT_ACTIVE_FC4_TYPES */
  2159. lpfc_fdmi_port_attr_port_state, /* bit13 RPRT_PORT_STATE */
  2160. lpfc_fdmi_port_attr_num_disc, /* bit14 RPRT_DISC_PORT */
  2161. lpfc_fdmi_port_attr_nportid, /* bit15 RPRT_PORT_ID */
  2162. lpfc_fdmi_smart_attr_service, /* bit16 RPRT_SMART_SERVICE */
  2163. lpfc_fdmi_smart_attr_guid, /* bit17 RPRT_SMART_GUID */
  2164. lpfc_fdmi_smart_attr_version, /* bit18 RPRT_SMART_VERSION */
  2165. lpfc_fdmi_smart_attr_model, /* bit19 RPRT_SMART_MODEL */
  2166. lpfc_fdmi_smart_attr_port_info, /* bit20 RPRT_SMART_PORT_INFO */
  2167. lpfc_fdmi_smart_attr_qos, /* bit21 RPRT_SMART_QOS */
  2168. lpfc_fdmi_smart_attr_security, /* bit22 RPRT_SMART_SECURITY */
  2169. };
  2170. /**
  2171. * lpfc_fdmi_cmd - Build and send a FDMI cmd to the specified NPort
  2172. * @vport: pointer to a host virtual N_Port data structure.
  2173. * @ndlp: ndlp to send FDMI cmd to (if NULL use FDMI_DID)
  2174. * cmdcode: FDMI command to send
  2175. * mask: Mask of HBA or PORT Attributes to send
  2176. *
  2177. * Builds and sends a FDMI command using the CT subsystem.
  2178. */
  2179. int
  2180. lpfc_fdmi_cmd(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
  2181. int cmdcode, uint32_t new_mask)
  2182. {
  2183. struct lpfc_hba *phba = vport->phba;
  2184. struct lpfc_dmabuf *mp, *bmp;
  2185. struct lpfc_sli_ct_request *CtReq;
  2186. struct ulp_bde64 *bpl;
  2187. uint32_t bit_pos;
  2188. uint32_t size;
  2189. uint32_t rsp_size;
  2190. uint32_t mask;
  2191. struct lpfc_fdmi_reg_hba *rh;
  2192. struct lpfc_fdmi_port_entry *pe;
  2193. struct lpfc_fdmi_reg_portattr *pab = NULL;
  2194. struct lpfc_fdmi_attr_block *ab = NULL;
  2195. int (*func)(struct lpfc_vport *vport, struct lpfc_fdmi_attr_def *ad);
  2196. void (*cmpl)(struct lpfc_hba *, struct lpfc_iocbq *,
  2197. struct lpfc_iocbq *);
  2198. if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
  2199. return 0;
  2200. cmpl = lpfc_cmpl_ct_disc_fdmi; /* called from discovery */
  2201. /* fill in BDEs for command */
  2202. /* Allocate buffer for command payload */
  2203. mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  2204. if (!mp)
  2205. goto fdmi_cmd_exit;
  2206. mp->virt = lpfc_mbuf_alloc(phba, 0, &(mp->phys));
  2207. if (!mp->virt)
  2208. goto fdmi_cmd_free_mp;
  2209. /* Allocate buffer for Buffer ptr list */
  2210. bmp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
  2211. if (!bmp)
  2212. goto fdmi_cmd_free_mpvirt;
  2213. bmp->virt = lpfc_mbuf_alloc(phba, 0, &(bmp->phys));
  2214. if (!bmp->virt)
  2215. goto fdmi_cmd_free_bmp;
  2216. INIT_LIST_HEAD(&mp->list);
  2217. INIT_LIST_HEAD(&bmp->list);
  2218. /* FDMI request */
  2219. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2220. "0218 FDMI Request Data: x%x x%x x%x\n",
  2221. vport->fc_flag, vport->port_state, cmdcode);
  2222. CtReq = (struct lpfc_sli_ct_request *)mp->virt;
  2223. /* First populate the CT_IU preamble */
  2224. memset(CtReq, 0, sizeof(struct lpfc_sli_ct_request));
  2225. CtReq->RevisionId.bits.Revision = SLI_CT_REVISION;
  2226. CtReq->RevisionId.bits.InId = 0;
  2227. CtReq->FsType = SLI_CT_MANAGEMENT_SERVICE;
  2228. CtReq->FsSubType = SLI_CT_FDMI_Subtypes;
  2229. CtReq->CommandResponse.bits.CmdRsp = cpu_to_be16(cmdcode);
  2230. rsp_size = LPFC_BPL_SIZE;
  2231. size = 0;
  2232. /* Next fill in the specific FDMI cmd information */
  2233. switch (cmdcode) {
  2234. case SLI_MGMT_RHAT:
  2235. case SLI_MGMT_RHBA:
  2236. rh = (struct lpfc_fdmi_reg_hba *)&CtReq->un.PortID;
  2237. /* HBA Identifier */
  2238. memcpy(&rh->hi.PortName, &phba->pport->fc_sparam.portName,
  2239. sizeof(struct lpfc_name));
  2240. if (cmdcode == SLI_MGMT_RHBA) {
  2241. /* Registered Port List */
  2242. /* One entry (port) per adapter */
  2243. rh->rpl.EntryCnt = cpu_to_be32(1);
  2244. memcpy(&rh->rpl.pe, &phba->pport->fc_sparam.portName,
  2245. sizeof(struct lpfc_name));
  2246. /* point to the HBA attribute block */
  2247. size = 2 * sizeof(struct lpfc_name) +
  2248. FOURBYTES;
  2249. } else {
  2250. size = sizeof(struct lpfc_name);
  2251. }
  2252. ab = (struct lpfc_fdmi_attr_block *)((uint8_t *)rh + size);
  2253. ab->EntryCnt = 0;
  2254. size += FOURBYTES;
  2255. bit_pos = 0;
  2256. if (new_mask)
  2257. mask = new_mask;
  2258. else
  2259. mask = vport->fdmi_hba_mask;
  2260. /* Mask will dictate what attributes to build in the request */
  2261. while (mask) {
  2262. if (mask & 0x1) {
  2263. func = lpfc_fdmi_hba_action[bit_pos];
  2264. size += func(vport,
  2265. (struct lpfc_fdmi_attr_def *)
  2266. ((uint8_t *)rh + size));
  2267. ab->EntryCnt++;
  2268. if ((size + 256) >
  2269. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  2270. goto hba_out;
  2271. }
  2272. mask = mask >> 1;
  2273. bit_pos++;
  2274. }
  2275. hba_out:
  2276. ab->EntryCnt = cpu_to_be32(ab->EntryCnt);
  2277. /* Total size */
  2278. size = GID_REQUEST_SZ - 4 + size;
  2279. break;
  2280. case SLI_MGMT_RPRT:
  2281. case SLI_MGMT_RPA:
  2282. pab = (struct lpfc_fdmi_reg_portattr *)&CtReq->un.PortID;
  2283. if (cmdcode == SLI_MGMT_RPRT) {
  2284. rh = (struct lpfc_fdmi_reg_hba *)pab;
  2285. /* HBA Identifier */
  2286. memcpy(&rh->hi.PortName,
  2287. &phba->pport->fc_sparam.portName,
  2288. sizeof(struct lpfc_name));
  2289. pab = (struct lpfc_fdmi_reg_portattr *)
  2290. ((uint8_t *)pab + sizeof(struct lpfc_name));
  2291. }
  2292. memcpy((uint8_t *)&pab->PortName,
  2293. (uint8_t *)&vport->fc_sparam.portName,
  2294. sizeof(struct lpfc_name));
  2295. size += sizeof(struct lpfc_name) + FOURBYTES;
  2296. pab->ab.EntryCnt = 0;
  2297. bit_pos = 0;
  2298. if (new_mask)
  2299. mask = new_mask;
  2300. else
  2301. mask = vport->fdmi_port_mask;
  2302. /* Mask will dictate what attributes to build in the request */
  2303. while (mask) {
  2304. if (mask & 0x1) {
  2305. func = lpfc_fdmi_port_action[bit_pos];
  2306. size += func(vport,
  2307. (struct lpfc_fdmi_attr_def *)
  2308. ((uint8_t *)pab + size));
  2309. pab->ab.EntryCnt++;
  2310. if ((size + 256) >
  2311. (LPFC_BPL_SIZE - LPFC_CT_PREAMBLE))
  2312. goto port_out;
  2313. }
  2314. mask = mask >> 1;
  2315. bit_pos++;
  2316. }
  2317. port_out:
  2318. pab->ab.EntryCnt = cpu_to_be32(pab->ab.EntryCnt);
  2319. /* Total size */
  2320. if (cmdcode == SLI_MGMT_RPRT)
  2321. size += sizeof(struct lpfc_name);
  2322. size = GID_REQUEST_SZ - 4 + size;
  2323. break;
  2324. case SLI_MGMT_GHAT:
  2325. case SLI_MGMT_GRPL:
  2326. rsp_size = FC_MAX_NS_RSP;
  2327. case SLI_MGMT_DHBA:
  2328. case SLI_MGMT_DHAT:
  2329. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
  2330. memcpy((uint8_t *)&pe->PortName,
  2331. (uint8_t *)&vport->fc_sparam.portName,
  2332. sizeof(struct lpfc_name));
  2333. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  2334. break;
  2335. case SLI_MGMT_GPAT:
  2336. case SLI_MGMT_GPAS:
  2337. rsp_size = FC_MAX_NS_RSP;
  2338. case SLI_MGMT_DPRT:
  2339. case SLI_MGMT_DPA:
  2340. pe = (struct lpfc_fdmi_port_entry *)&CtReq->un.PortID;
  2341. memcpy((uint8_t *)&pe->PortName,
  2342. (uint8_t *)&vport->fc_sparam.portName,
  2343. sizeof(struct lpfc_name));
  2344. size = GID_REQUEST_SZ - 4 + sizeof(struct lpfc_name);
  2345. break;
  2346. case SLI_MGMT_GRHL:
  2347. size = GID_REQUEST_SZ - 4;
  2348. break;
  2349. default:
  2350. lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
  2351. "0298 FDMI cmdcode x%x not supported\n",
  2352. cmdcode);
  2353. goto fdmi_cmd_free_bmpvirt;
  2354. }
  2355. CtReq->CommandResponse.bits.Size = cpu_to_be16(rsp_size);
  2356. bpl = (struct ulp_bde64 *)bmp->virt;
  2357. bpl->addrHigh = le32_to_cpu(putPaddrHigh(mp->phys));
  2358. bpl->addrLow = le32_to_cpu(putPaddrLow(mp->phys));
  2359. bpl->tus.f.bdeFlags = 0;
  2360. bpl->tus.f.bdeSize = size;
  2361. /*
  2362. * The lpfc_ct_cmd/lpfc_get_req shall increment ndlp reference count
  2363. * to hold ndlp reference for the corresponding callback function.
  2364. */
  2365. if (!lpfc_ct_cmd(vport, mp, bmp, ndlp, cmpl, rsp_size, 0))
  2366. return 0;
  2367. /*
  2368. * Decrement ndlp reference count to release ndlp reference held
  2369. * for the failed command's callback function.
  2370. */
  2371. lpfc_nlp_put(ndlp);
  2372. fdmi_cmd_free_bmpvirt:
  2373. lpfc_mbuf_free(phba, bmp->virt, bmp->phys);
  2374. fdmi_cmd_free_bmp:
  2375. kfree(bmp);
  2376. fdmi_cmd_free_mpvirt:
  2377. lpfc_mbuf_free(phba, mp->virt, mp->phys);
  2378. fdmi_cmd_free_mp:
  2379. kfree(mp);
  2380. fdmi_cmd_exit:
  2381. /* Issue FDMI request failed */
  2382. lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
  2383. "0244 Issue FDMI request failed Data: x%x\n",
  2384. cmdcode);
  2385. return 1;
  2386. }
  2387. /**
  2388. * lpfc_delayed_disc_tmo - Timeout handler for delayed discovery timer.
  2389. * @ptr - Context object of the timer.
  2390. *
  2391. * This function set the WORKER_DELAYED_DISC_TMO flag and wake up
  2392. * the worker thread.
  2393. **/
  2394. void
  2395. lpfc_delayed_disc_tmo(unsigned long ptr)
  2396. {
  2397. struct lpfc_vport *vport = (struct lpfc_vport *)ptr;
  2398. struct lpfc_hba *phba = vport->phba;
  2399. uint32_t tmo_posted;
  2400. unsigned long iflag;
  2401. spin_lock_irqsave(&vport->work_port_lock, iflag);
  2402. tmo_posted = vport->work_port_events & WORKER_DELAYED_DISC_TMO;
  2403. if (!tmo_posted)
  2404. vport->work_port_events |= WORKER_DELAYED_DISC_TMO;
  2405. spin_unlock_irqrestore(&vport->work_port_lock, iflag);
  2406. if (!tmo_posted)
  2407. lpfc_worker_wake_up(phba);
  2408. return;
  2409. }
  2410. /**
  2411. * lpfc_delayed_disc_timeout_handler - Function called by worker thread to
  2412. * handle delayed discovery.
  2413. * @vport: pointer to a host virtual N_Port data structure.
  2414. *
  2415. * This function start nport discovery of the vport.
  2416. **/
  2417. void
  2418. lpfc_delayed_disc_timeout_handler(struct lpfc_vport *vport)
  2419. {
  2420. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  2421. spin_lock_irq(shost->host_lock);
  2422. if (!(vport->fc_flag & FC_DISC_DELAYED)) {
  2423. spin_unlock_irq(shost->host_lock);
  2424. return;
  2425. }
  2426. vport->fc_flag &= ~FC_DISC_DELAYED;
  2427. spin_unlock_irq(shost->host_lock);
  2428. lpfc_do_scr_ns_plogi(vport->phba, vport);
  2429. }
  2430. void
  2431. lpfc_decode_firmware_rev(struct lpfc_hba *phba, char *fwrevision, int flag)
  2432. {
  2433. struct lpfc_sli *psli = &phba->sli;
  2434. lpfc_vpd_t *vp = &phba->vpd;
  2435. uint32_t b1, b2, b3, b4, i, rev;
  2436. char c;
  2437. uint32_t *ptr, str[4];
  2438. uint8_t *fwname;
  2439. if (phba->sli_rev == LPFC_SLI_REV4)
  2440. snprintf(fwrevision, FW_REV_STR_SIZE, "%s", vp->rev.opFwName);
  2441. else if (vp->rev.rBit) {
  2442. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  2443. rev = vp->rev.sli2FwRev;
  2444. else
  2445. rev = vp->rev.sli1FwRev;
  2446. b1 = (rev & 0x0000f000) >> 12;
  2447. b2 = (rev & 0x00000f00) >> 8;
  2448. b3 = (rev & 0x000000c0) >> 6;
  2449. b4 = (rev & 0x00000030) >> 4;
  2450. switch (b4) {
  2451. case 0:
  2452. c = 'N';
  2453. break;
  2454. case 1:
  2455. c = 'A';
  2456. break;
  2457. case 2:
  2458. c = 'B';
  2459. break;
  2460. case 3:
  2461. c = 'X';
  2462. break;
  2463. default:
  2464. c = 0;
  2465. break;
  2466. }
  2467. b4 = (rev & 0x0000000f);
  2468. if (psli->sli_flag & LPFC_SLI_ACTIVE)
  2469. fwname = vp->rev.sli2FwName;
  2470. else
  2471. fwname = vp->rev.sli1FwName;
  2472. for (i = 0; i < 16; i++)
  2473. if (fwname[i] == 0x20)
  2474. fwname[i] = 0;
  2475. ptr = (uint32_t*)fwname;
  2476. for (i = 0; i < 3; i++)
  2477. str[i] = be32_to_cpu(*ptr++);
  2478. if (c == 0) {
  2479. if (flag)
  2480. sprintf(fwrevision, "%d.%d%d (%s)",
  2481. b1, b2, b3, (char *)str);
  2482. else
  2483. sprintf(fwrevision, "%d.%d%d", b1,
  2484. b2, b3);
  2485. } else {
  2486. if (flag)
  2487. sprintf(fwrevision, "%d.%d%d%c%d (%s)",
  2488. b1, b2, b3, c,
  2489. b4, (char *)str);
  2490. else
  2491. sprintf(fwrevision, "%d.%d%d%c%d",
  2492. b1, b2, b3, c, b4);
  2493. }
  2494. } else {
  2495. rev = vp->rev.smFwRev;
  2496. b1 = (rev & 0xff000000) >> 24;
  2497. b2 = (rev & 0x00f00000) >> 20;
  2498. b3 = (rev & 0x000f0000) >> 16;
  2499. c = (rev & 0x0000ff00) >> 8;
  2500. b4 = (rev & 0x000000ff);
  2501. sprintf(fwrevision, "%d.%d%d%c%d", b1, b2, b3, c, b4);
  2502. }
  2503. return;
  2504. }