lpfc_attr.c 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2008 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * Portions Copyright (C) 2004-2005 Christoph Hellwig *
  8. * *
  9. * This program is free software; you can redistribute it and/or *
  10. * modify it under the terms of version 2 of the GNU General *
  11. * Public License as published by the Free Software Foundation. *
  12. * This program is distributed in the hope that it will be useful. *
  13. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  14. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  15. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  16. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  17. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  18. * more details, a copy of which can be found in the file COPYING *
  19. * included with this package. *
  20. *******************************************************************/
  21. #include <linux/ctype.h>
  22. #include <linux/delay.h>
  23. #include <linux/pci.h>
  24. #include <linux/interrupt.h>
  25. #include <scsi/scsi.h>
  26. #include <scsi/scsi_device.h>
  27. #include <scsi/scsi_host.h>
  28. #include <scsi/scsi_tcq.h>
  29. #include <scsi/scsi_transport_fc.h>
  30. #include "lpfc_hw.h"
  31. #include "lpfc_sli.h"
  32. #include "lpfc_disc.h"
  33. #include "lpfc_scsi.h"
  34. #include "lpfc.h"
  35. #include "lpfc_logmsg.h"
  36. #include "lpfc_version.h"
  37. #include "lpfc_compat.h"
  38. #include "lpfc_crtn.h"
  39. #include "lpfc_vport.h"
  40. #define LPFC_DEF_DEVLOSS_TMO 30
  41. #define LPFC_MIN_DEVLOSS_TMO 1
  42. #define LPFC_MAX_DEVLOSS_TMO 255
  43. #define LPFC_MAX_LINK_SPEED 8
  44. #define LPFC_LINK_SPEED_BITMAP 0x00000117
  45. #define LPFC_LINK_SPEED_STRING "0, 1, 2, 4, 8"
  46. static void
  47. lpfc_jedec_to_ascii(int incr, char hdw[])
  48. {
  49. int i, j;
  50. for (i = 0; i < 8; i++) {
  51. j = (incr & 0xf);
  52. if (j <= 9)
  53. hdw[7 - i] = 0x30 + j;
  54. else
  55. hdw[7 - i] = 0x61 + j - 10;
  56. incr = (incr >> 4);
  57. }
  58. hdw[8] = 0;
  59. return;
  60. }
  61. static ssize_t
  62. lpfc_drvr_version_show(struct device *dev, struct device_attribute *attr,
  63. char *buf)
  64. {
  65. return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
  66. }
  67. static ssize_t
  68. lpfc_info_show(struct device *dev, struct device_attribute *attr,
  69. char *buf)
  70. {
  71. struct Scsi_Host *host = class_to_shost(dev);
  72. return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
  73. }
  74. static ssize_t
  75. lpfc_serialnum_show(struct device *dev, struct device_attribute *attr,
  76. char *buf)
  77. {
  78. struct Scsi_Host *shost = class_to_shost(dev);
  79. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  80. struct lpfc_hba *phba = vport->phba;
  81. return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
  82. }
  83. static ssize_t
  84. lpfc_temp_sensor_show(struct device *dev, struct device_attribute *attr,
  85. char *buf)
  86. {
  87. struct Scsi_Host *shost = class_to_shost(dev);
  88. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  89. struct lpfc_hba *phba = vport->phba;
  90. return snprintf(buf, PAGE_SIZE, "%d\n",phba->temp_sensor_support);
  91. }
  92. static ssize_t
  93. lpfc_modeldesc_show(struct device *dev, struct device_attribute *attr,
  94. char *buf)
  95. {
  96. struct Scsi_Host *shost = class_to_shost(dev);
  97. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  98. struct lpfc_hba *phba = vport->phba;
  99. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
  100. }
  101. static ssize_t
  102. lpfc_modelname_show(struct device *dev, struct device_attribute *attr,
  103. char *buf)
  104. {
  105. struct Scsi_Host *shost = class_to_shost(dev);
  106. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  107. struct lpfc_hba *phba = vport->phba;
  108. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
  109. }
  110. static ssize_t
  111. lpfc_programtype_show(struct device *dev, struct device_attribute *attr,
  112. char *buf)
  113. {
  114. struct Scsi_Host *shost = class_to_shost(dev);
  115. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  116. struct lpfc_hba *phba = vport->phba;
  117. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
  118. }
  119. static ssize_t
  120. lpfc_vportnum_show(struct device *dev, struct device_attribute *attr,
  121. char *buf)
  122. {
  123. struct Scsi_Host *shost = class_to_shost(dev);
  124. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  125. struct lpfc_hba *phba = vport->phba;
  126. return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
  127. }
  128. static ssize_t
  129. lpfc_fwrev_show(struct device *dev, struct device_attribute *attr,
  130. char *buf)
  131. {
  132. struct Scsi_Host *shost = class_to_shost(dev);
  133. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  134. struct lpfc_hba *phba = vport->phba;
  135. char fwrev[32];
  136. lpfc_decode_firmware_rev(phba, fwrev, 1);
  137. return snprintf(buf, PAGE_SIZE, "%s, sli-%d\n", fwrev, phba->sli_rev);
  138. }
  139. static ssize_t
  140. lpfc_hdw_show(struct device *dev, struct device_attribute *attr, char *buf)
  141. {
  142. char hdw[9];
  143. struct Scsi_Host *shost = class_to_shost(dev);
  144. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  145. struct lpfc_hba *phba = vport->phba;
  146. lpfc_vpd_t *vp = &phba->vpd;
  147. lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
  148. return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
  149. }
  150. static ssize_t
  151. lpfc_option_rom_version_show(struct device *dev, struct device_attribute *attr,
  152. char *buf)
  153. {
  154. struct Scsi_Host *shost = class_to_shost(dev);
  155. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  156. struct lpfc_hba *phba = vport->phba;
  157. return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
  158. }
  159. static ssize_t
  160. lpfc_link_state_show(struct device *dev, struct device_attribute *attr,
  161. char *buf)
  162. {
  163. struct Scsi_Host *shost = class_to_shost(dev);
  164. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  165. struct lpfc_hba *phba = vport->phba;
  166. int len = 0;
  167. switch (phba->link_state) {
  168. case LPFC_LINK_UNKNOWN:
  169. case LPFC_WARM_START:
  170. case LPFC_INIT_START:
  171. case LPFC_INIT_MBX_CMDS:
  172. case LPFC_LINK_DOWN:
  173. case LPFC_HBA_ERROR:
  174. len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
  175. break;
  176. case LPFC_LINK_UP:
  177. case LPFC_CLEAR_LA:
  178. case LPFC_HBA_READY:
  179. len += snprintf(buf + len, PAGE_SIZE-len, "Link Up - ");
  180. switch (vport->port_state) {
  181. case LPFC_LOCAL_CFG_LINK:
  182. len += snprintf(buf + len, PAGE_SIZE-len,
  183. "Configuring Link\n");
  184. break;
  185. case LPFC_FDISC:
  186. case LPFC_FLOGI:
  187. case LPFC_FABRIC_CFG_LINK:
  188. case LPFC_NS_REG:
  189. case LPFC_NS_QRY:
  190. case LPFC_BUILD_DISC_LIST:
  191. case LPFC_DISC_AUTH:
  192. len += snprintf(buf + len, PAGE_SIZE - len,
  193. "Discovery\n");
  194. break;
  195. case LPFC_VPORT_READY:
  196. len += snprintf(buf + len, PAGE_SIZE - len, "Ready\n");
  197. break;
  198. case LPFC_VPORT_FAILED:
  199. len += snprintf(buf + len, PAGE_SIZE - len, "Failed\n");
  200. break;
  201. case LPFC_VPORT_UNKNOWN:
  202. len += snprintf(buf + len, PAGE_SIZE - len,
  203. "Unknown\n");
  204. break;
  205. }
  206. if (phba->fc_topology == TOPOLOGY_LOOP) {
  207. if (vport->fc_flag & FC_PUBLIC_LOOP)
  208. len += snprintf(buf + len, PAGE_SIZE-len,
  209. " Public Loop\n");
  210. else
  211. len += snprintf(buf + len, PAGE_SIZE-len,
  212. " Private Loop\n");
  213. } else {
  214. if (vport->fc_flag & FC_FABRIC)
  215. len += snprintf(buf + len, PAGE_SIZE-len,
  216. " Fabric\n");
  217. else
  218. len += snprintf(buf + len, PAGE_SIZE-len,
  219. " Point-2-Point\n");
  220. }
  221. }
  222. return len;
  223. }
  224. static ssize_t
  225. lpfc_num_discovered_ports_show(struct device *dev,
  226. struct device_attribute *attr, char *buf)
  227. {
  228. struct Scsi_Host *shost = class_to_shost(dev);
  229. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  230. return snprintf(buf, PAGE_SIZE, "%d\n",
  231. vport->fc_map_cnt + vport->fc_unmap_cnt);
  232. }
  233. static int
  234. lpfc_issue_lip(struct Scsi_Host *shost)
  235. {
  236. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  237. struct lpfc_hba *phba = vport->phba;
  238. LPFC_MBOXQ_t *pmboxq;
  239. int mbxstatus = MBXERR_ERROR;
  240. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  241. (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO))
  242. return -EPERM;
  243. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  244. if (!pmboxq)
  245. return -ENOMEM;
  246. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  247. pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
  248. pmboxq->mb.mbxOwner = OWN_HOST;
  249. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, LPFC_MBOX_TMO * 2);
  250. if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
  251. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  252. lpfc_init_link(phba, pmboxq, phba->cfg_topology,
  253. phba->cfg_link_speed);
  254. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
  255. phba->fc_ratov * 2);
  256. }
  257. lpfc_set_loopback_flag(phba);
  258. if (mbxstatus != MBX_TIMEOUT)
  259. mempool_free(pmboxq, phba->mbox_mem_pool);
  260. if (mbxstatus == MBXERR_ERROR)
  261. return -EIO;
  262. return 0;
  263. }
  264. static int
  265. lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
  266. {
  267. struct completion online_compl;
  268. struct lpfc_sli_ring *pring;
  269. struct lpfc_sli *psli;
  270. int status = 0;
  271. int cnt = 0;
  272. int i;
  273. init_completion(&online_compl);
  274. lpfc_workq_post_event(phba, &status, &online_compl,
  275. LPFC_EVT_OFFLINE_PREP);
  276. wait_for_completion(&online_compl);
  277. if (status != 0)
  278. return -EIO;
  279. psli = &phba->sli;
  280. /* Wait a little for things to settle down, but not
  281. * long enough for dev loss timeout to expire.
  282. */
  283. for (i = 0; i < psli->num_rings; i++) {
  284. pring = &psli->ring[i];
  285. while (pring->txcmplq_cnt) {
  286. msleep(10);
  287. if (cnt++ > 500) { /* 5 secs */
  288. lpfc_printf_log(phba,
  289. KERN_WARNING, LOG_INIT,
  290. "0466 Outstanding IO when "
  291. "bringing Adapter offline\n");
  292. break;
  293. }
  294. }
  295. }
  296. init_completion(&online_compl);
  297. lpfc_workq_post_event(phba, &status, &online_compl, type);
  298. wait_for_completion(&online_compl);
  299. if (status != 0)
  300. return -EIO;
  301. return 0;
  302. }
  303. static int
  304. lpfc_selective_reset(struct lpfc_hba *phba)
  305. {
  306. struct completion online_compl;
  307. int status = 0;
  308. if (!phba->cfg_enable_hba_reset)
  309. return -EIO;
  310. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  311. if (status != 0)
  312. return status;
  313. init_completion(&online_compl);
  314. lpfc_workq_post_event(phba, &status, &online_compl,
  315. LPFC_EVT_ONLINE);
  316. wait_for_completion(&online_compl);
  317. if (status != 0)
  318. return -EIO;
  319. return 0;
  320. }
  321. static ssize_t
  322. lpfc_issue_reset(struct device *dev, struct device_attribute *attr,
  323. const char *buf, size_t count)
  324. {
  325. struct Scsi_Host *shost = class_to_shost(dev);
  326. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  327. struct lpfc_hba *phba = vport->phba;
  328. int status = -EINVAL;
  329. if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
  330. status = lpfc_selective_reset(phba);
  331. if (status == 0)
  332. return strlen(buf);
  333. else
  334. return status;
  335. }
  336. static ssize_t
  337. lpfc_nport_evt_cnt_show(struct device *dev, struct device_attribute *attr,
  338. char *buf)
  339. {
  340. struct Scsi_Host *shost = class_to_shost(dev);
  341. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  342. struct lpfc_hba *phba = vport->phba;
  343. return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
  344. }
  345. static ssize_t
  346. lpfc_board_mode_show(struct device *dev, struct device_attribute *attr,
  347. char *buf)
  348. {
  349. struct Scsi_Host *shost = class_to_shost(dev);
  350. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  351. struct lpfc_hba *phba = vport->phba;
  352. char * state;
  353. if (phba->link_state == LPFC_HBA_ERROR)
  354. state = "error";
  355. else if (phba->link_state == LPFC_WARM_START)
  356. state = "warm start";
  357. else if (phba->link_state == LPFC_INIT_START)
  358. state = "offline";
  359. else
  360. state = "online";
  361. return snprintf(buf, PAGE_SIZE, "%s\n", state);
  362. }
  363. static ssize_t
  364. lpfc_board_mode_store(struct device *dev, struct device_attribute *attr,
  365. const char *buf, size_t count)
  366. {
  367. struct Scsi_Host *shost = class_to_shost(dev);
  368. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  369. struct lpfc_hba *phba = vport->phba;
  370. struct completion online_compl;
  371. int status=0;
  372. if (!phba->cfg_enable_hba_reset)
  373. return -EACCES;
  374. init_completion(&online_compl);
  375. if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
  376. lpfc_workq_post_event(phba, &status, &online_compl,
  377. LPFC_EVT_ONLINE);
  378. wait_for_completion(&online_compl);
  379. } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
  380. status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  381. else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
  382. status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
  383. else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
  384. status = lpfc_do_offline(phba, LPFC_EVT_KILL);
  385. else
  386. return -EINVAL;
  387. if (!status)
  388. return strlen(buf);
  389. else
  390. return -EIO;
  391. }
  392. static int
  393. lpfc_get_hba_info(struct lpfc_hba *phba,
  394. uint32_t *mxri, uint32_t *axri,
  395. uint32_t *mrpi, uint32_t *arpi,
  396. uint32_t *mvpi, uint32_t *avpi)
  397. {
  398. struct lpfc_sli *psli = &phba->sli;
  399. LPFC_MBOXQ_t *pmboxq;
  400. MAILBOX_t *pmb;
  401. int rc = 0;
  402. /*
  403. * prevent udev from issuing mailbox commands until the port is
  404. * configured.
  405. */
  406. if (phba->link_state < LPFC_LINK_DOWN ||
  407. !phba->mbox_mem_pool ||
  408. (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
  409. return 0;
  410. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  411. return 0;
  412. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  413. if (!pmboxq)
  414. return 0;
  415. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  416. pmb = &pmboxq->mb;
  417. pmb->mbxCommand = MBX_READ_CONFIG;
  418. pmb->mbxOwner = OWN_HOST;
  419. pmboxq->context1 = NULL;
  420. if ((phba->pport->fc_flag & FC_OFFLINE_MODE) ||
  421. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  422. rc = MBX_NOT_FINISHED;
  423. else
  424. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  425. if (rc != MBX_SUCCESS) {
  426. if (rc != MBX_TIMEOUT)
  427. mempool_free(pmboxq, phba->mbox_mem_pool);
  428. return 0;
  429. }
  430. if (mrpi)
  431. *mrpi = pmb->un.varRdConfig.max_rpi;
  432. if (arpi)
  433. *arpi = pmb->un.varRdConfig.avail_rpi;
  434. if (mxri)
  435. *mxri = pmb->un.varRdConfig.max_xri;
  436. if (axri)
  437. *axri = pmb->un.varRdConfig.avail_xri;
  438. if (mvpi)
  439. *mvpi = pmb->un.varRdConfig.max_vpi;
  440. if (avpi)
  441. *avpi = pmb->un.varRdConfig.avail_vpi;
  442. mempool_free(pmboxq, phba->mbox_mem_pool);
  443. return 1;
  444. }
  445. static ssize_t
  446. lpfc_max_rpi_show(struct device *dev, struct device_attribute *attr,
  447. char *buf)
  448. {
  449. struct Scsi_Host *shost = class_to_shost(dev);
  450. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  451. struct lpfc_hba *phba = vport->phba;
  452. uint32_t cnt;
  453. if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, NULL, NULL, NULL))
  454. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  455. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  456. }
  457. static ssize_t
  458. lpfc_used_rpi_show(struct device *dev, struct device_attribute *attr,
  459. char *buf)
  460. {
  461. struct Scsi_Host *shost = class_to_shost(dev);
  462. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  463. struct lpfc_hba *phba = vport->phba;
  464. uint32_t cnt, acnt;
  465. if (lpfc_get_hba_info(phba, NULL, NULL, &cnt, &acnt, NULL, NULL))
  466. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  467. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  468. }
  469. static ssize_t
  470. lpfc_max_xri_show(struct device *dev, struct device_attribute *attr,
  471. char *buf)
  472. {
  473. struct Scsi_Host *shost = class_to_shost(dev);
  474. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  475. struct lpfc_hba *phba = vport->phba;
  476. uint32_t cnt;
  477. if (lpfc_get_hba_info(phba, &cnt, NULL, NULL, NULL, NULL, NULL))
  478. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  479. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  480. }
  481. static ssize_t
  482. lpfc_used_xri_show(struct device *dev, struct device_attribute *attr,
  483. char *buf)
  484. {
  485. struct Scsi_Host *shost = class_to_shost(dev);
  486. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  487. struct lpfc_hba *phba = vport->phba;
  488. uint32_t cnt, acnt;
  489. if (lpfc_get_hba_info(phba, &cnt, &acnt, NULL, NULL, NULL, NULL))
  490. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  491. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  492. }
  493. static ssize_t
  494. lpfc_max_vpi_show(struct device *dev, struct device_attribute *attr,
  495. char *buf)
  496. {
  497. struct Scsi_Host *shost = class_to_shost(dev);
  498. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  499. struct lpfc_hba *phba = vport->phba;
  500. uint32_t cnt;
  501. if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, NULL))
  502. return snprintf(buf, PAGE_SIZE, "%d\n", cnt);
  503. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  504. }
  505. static ssize_t
  506. lpfc_used_vpi_show(struct device *dev, struct device_attribute *attr,
  507. char *buf)
  508. {
  509. struct Scsi_Host *shost = class_to_shost(dev);
  510. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  511. struct lpfc_hba *phba = vport->phba;
  512. uint32_t cnt, acnt;
  513. if (lpfc_get_hba_info(phba, NULL, NULL, NULL, NULL, &cnt, &acnt))
  514. return snprintf(buf, PAGE_SIZE, "%d\n", (cnt - acnt));
  515. return snprintf(buf, PAGE_SIZE, "Unknown\n");
  516. }
  517. static ssize_t
  518. lpfc_npiv_info_show(struct device *dev, struct device_attribute *attr,
  519. char *buf)
  520. {
  521. struct Scsi_Host *shost = class_to_shost(dev);
  522. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  523. struct lpfc_hba *phba = vport->phba;
  524. if (!(phba->max_vpi))
  525. return snprintf(buf, PAGE_SIZE, "NPIV Not Supported\n");
  526. if (vport->port_type == LPFC_PHYSICAL_PORT)
  527. return snprintf(buf, PAGE_SIZE, "NPIV Physical\n");
  528. return snprintf(buf, PAGE_SIZE, "NPIV Virtual (VPI %d)\n", vport->vpi);
  529. }
  530. static ssize_t
  531. lpfc_poll_show(struct device *dev, struct device_attribute *attr,
  532. char *buf)
  533. {
  534. struct Scsi_Host *shost = class_to_shost(dev);
  535. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  536. struct lpfc_hba *phba = vport->phba;
  537. return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
  538. }
  539. static ssize_t
  540. lpfc_poll_store(struct device *dev, struct device_attribute *attr,
  541. const char *buf, size_t count)
  542. {
  543. struct Scsi_Host *shost = class_to_shost(dev);
  544. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  545. struct lpfc_hba *phba = vport->phba;
  546. uint32_t creg_val;
  547. uint32_t old_val;
  548. int val=0;
  549. if (!isdigit(buf[0]))
  550. return -EINVAL;
  551. if (sscanf(buf, "%i", &val) != 1)
  552. return -EINVAL;
  553. if ((val & 0x3) != val)
  554. return -EINVAL;
  555. spin_lock_irq(&phba->hbalock);
  556. old_val = phba->cfg_poll;
  557. if (val & ENABLE_FCP_RING_POLLING) {
  558. if ((val & DISABLE_FCP_RING_INT) &&
  559. !(old_val & DISABLE_FCP_RING_INT)) {
  560. creg_val = readl(phba->HCregaddr);
  561. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  562. writel(creg_val, phba->HCregaddr);
  563. readl(phba->HCregaddr); /* flush */
  564. lpfc_poll_start_timer(phba);
  565. }
  566. } else if (val != 0x0) {
  567. spin_unlock_irq(&phba->hbalock);
  568. return -EINVAL;
  569. }
  570. if (!(val & DISABLE_FCP_RING_INT) &&
  571. (old_val & DISABLE_FCP_RING_INT))
  572. {
  573. spin_unlock_irq(&phba->hbalock);
  574. del_timer(&phba->fcp_poll_timer);
  575. spin_lock_irq(&phba->hbalock);
  576. creg_val = readl(phba->HCregaddr);
  577. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  578. writel(creg_val, phba->HCregaddr);
  579. readl(phba->HCregaddr); /* flush */
  580. }
  581. phba->cfg_poll = val;
  582. spin_unlock_irq(&phba->hbalock);
  583. return strlen(buf);
  584. }
  585. #define lpfc_param_show(attr) \
  586. static ssize_t \
  587. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  588. char *buf) \
  589. { \
  590. struct Scsi_Host *shost = class_to_shost(dev);\
  591. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  592. struct lpfc_hba *phba = vport->phba;\
  593. int val = 0;\
  594. val = phba->cfg_##attr;\
  595. return snprintf(buf, PAGE_SIZE, "%d\n",\
  596. phba->cfg_##attr);\
  597. }
  598. #define lpfc_param_hex_show(attr) \
  599. static ssize_t \
  600. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  601. char *buf) \
  602. { \
  603. struct Scsi_Host *shost = class_to_shost(dev);\
  604. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  605. struct lpfc_hba *phba = vport->phba;\
  606. int val = 0;\
  607. val = phba->cfg_##attr;\
  608. return snprintf(buf, PAGE_SIZE, "%#x\n",\
  609. phba->cfg_##attr);\
  610. }
  611. #define lpfc_param_init(attr, default, minval, maxval) \
  612. static int \
  613. lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
  614. { \
  615. if (val >= minval && val <= maxval) {\
  616. phba->cfg_##attr = val;\
  617. return 0;\
  618. }\
  619. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  620. "0449 lpfc_"#attr" attribute cannot be set to %d, "\
  621. "allowed range is ["#minval", "#maxval"]\n", val); \
  622. phba->cfg_##attr = default;\
  623. return -EINVAL;\
  624. }
  625. #define lpfc_param_set(attr, default, minval, maxval) \
  626. static int \
  627. lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
  628. { \
  629. if (val >= minval && val <= maxval) {\
  630. phba->cfg_##attr = val;\
  631. return 0;\
  632. }\
  633. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  634. "0450 lpfc_"#attr" attribute cannot be set to %d, "\
  635. "allowed range is ["#minval", "#maxval"]\n", val); \
  636. return -EINVAL;\
  637. }
  638. #define lpfc_param_store(attr) \
  639. static ssize_t \
  640. lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
  641. const char *buf, size_t count) \
  642. { \
  643. struct Scsi_Host *shost = class_to_shost(dev);\
  644. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  645. struct lpfc_hba *phba = vport->phba;\
  646. int val=0;\
  647. if (!isdigit(buf[0]))\
  648. return -EINVAL;\
  649. if (sscanf(buf, "%i", &val) != 1)\
  650. return -EINVAL;\
  651. if (lpfc_##attr##_set(phba, val) == 0) \
  652. return strlen(buf);\
  653. else \
  654. return -EINVAL;\
  655. }
  656. #define lpfc_vport_param_show(attr) \
  657. static ssize_t \
  658. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  659. char *buf) \
  660. { \
  661. struct Scsi_Host *shost = class_to_shost(dev);\
  662. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  663. int val = 0;\
  664. val = vport->cfg_##attr;\
  665. return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_##attr);\
  666. }
  667. #define lpfc_vport_param_hex_show(attr) \
  668. static ssize_t \
  669. lpfc_##attr##_show(struct device *dev, struct device_attribute *attr, \
  670. char *buf) \
  671. { \
  672. struct Scsi_Host *shost = class_to_shost(dev);\
  673. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  674. int val = 0;\
  675. val = vport->cfg_##attr;\
  676. return snprintf(buf, PAGE_SIZE, "%#x\n", vport->cfg_##attr);\
  677. }
  678. #define lpfc_vport_param_init(attr, default, minval, maxval) \
  679. static int \
  680. lpfc_##attr##_init(struct lpfc_vport *vport, int val) \
  681. { \
  682. if (val >= minval && val <= maxval) {\
  683. vport->cfg_##attr = val;\
  684. return 0;\
  685. }\
  686. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  687. "0449 lpfc_"#attr" attribute cannot be set to %d, "\
  688. "allowed range is ["#minval", "#maxval"]\n", val); \
  689. vport->cfg_##attr = default;\
  690. return -EINVAL;\
  691. }
  692. #define lpfc_vport_param_set(attr, default, minval, maxval) \
  693. static int \
  694. lpfc_##attr##_set(struct lpfc_vport *vport, int val) \
  695. { \
  696. if (val >= minval && val <= maxval) {\
  697. vport->cfg_##attr = val;\
  698. return 0;\
  699. }\
  700. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT, \
  701. "0450 lpfc_"#attr" attribute cannot be set to %d, "\
  702. "allowed range is ["#minval", "#maxval"]\n", val); \
  703. return -EINVAL;\
  704. }
  705. #define lpfc_vport_param_store(attr) \
  706. static ssize_t \
  707. lpfc_##attr##_store(struct device *dev, struct device_attribute *attr, \
  708. const char *buf, size_t count) \
  709. { \
  710. struct Scsi_Host *shost = class_to_shost(dev);\
  711. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;\
  712. int val=0;\
  713. if (!isdigit(buf[0]))\
  714. return -EINVAL;\
  715. if (sscanf(buf, "%i", &val) != 1)\
  716. return -EINVAL;\
  717. if (lpfc_##attr##_set(vport, val) == 0) \
  718. return strlen(buf);\
  719. else \
  720. return -EINVAL;\
  721. }
  722. #define LPFC_ATTR(name, defval, minval, maxval, desc) \
  723. static int lpfc_##name = defval;\
  724. module_param(lpfc_##name, int, 0);\
  725. MODULE_PARM_DESC(lpfc_##name, desc);\
  726. lpfc_param_init(name, defval, minval, maxval)
  727. #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
  728. static int lpfc_##name = defval;\
  729. module_param(lpfc_##name, int, 0);\
  730. MODULE_PARM_DESC(lpfc_##name, desc);\
  731. lpfc_param_show(name)\
  732. lpfc_param_init(name, defval, minval, maxval)\
  733. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  734. #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
  735. static int lpfc_##name = defval;\
  736. module_param(lpfc_##name, int, 0);\
  737. MODULE_PARM_DESC(lpfc_##name, desc);\
  738. lpfc_param_show(name)\
  739. lpfc_param_init(name, defval, minval, maxval)\
  740. lpfc_param_set(name, defval, minval, maxval)\
  741. lpfc_param_store(name)\
  742. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  743. lpfc_##name##_show, lpfc_##name##_store)
  744. #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
  745. static int lpfc_##name = defval;\
  746. module_param(lpfc_##name, int, 0);\
  747. MODULE_PARM_DESC(lpfc_##name, desc);\
  748. lpfc_param_hex_show(name)\
  749. lpfc_param_init(name, defval, minval, maxval)\
  750. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  751. #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
  752. static int lpfc_##name = defval;\
  753. module_param(lpfc_##name, int, 0);\
  754. MODULE_PARM_DESC(lpfc_##name, desc);\
  755. lpfc_param_hex_show(name)\
  756. lpfc_param_init(name, defval, minval, maxval)\
  757. lpfc_param_set(name, defval, minval, maxval)\
  758. lpfc_param_store(name)\
  759. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  760. lpfc_##name##_show, lpfc_##name##_store)
  761. #define LPFC_VPORT_ATTR(name, defval, minval, maxval, desc) \
  762. static int lpfc_##name = defval;\
  763. module_param(lpfc_##name, int, 0);\
  764. MODULE_PARM_DESC(lpfc_##name, desc);\
  765. lpfc_vport_param_init(name, defval, minval, maxval)
  766. #define LPFC_VPORT_ATTR_R(name, defval, minval, maxval, desc) \
  767. static int lpfc_##name = defval;\
  768. module_param(lpfc_##name, int, 0);\
  769. MODULE_PARM_DESC(lpfc_##name, desc);\
  770. lpfc_vport_param_show(name)\
  771. lpfc_vport_param_init(name, defval, minval, maxval)\
  772. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  773. #define LPFC_VPORT_ATTR_RW(name, defval, minval, maxval, desc) \
  774. static int lpfc_##name = defval;\
  775. module_param(lpfc_##name, int, 0);\
  776. MODULE_PARM_DESC(lpfc_##name, desc);\
  777. lpfc_vport_param_show(name)\
  778. lpfc_vport_param_init(name, defval, minval, maxval)\
  779. lpfc_vport_param_set(name, defval, minval, maxval)\
  780. lpfc_vport_param_store(name)\
  781. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  782. lpfc_##name##_show, lpfc_##name##_store)
  783. #define LPFC_VPORT_ATTR_HEX_R(name, defval, minval, maxval, desc) \
  784. static int lpfc_##name = defval;\
  785. module_param(lpfc_##name, int, 0);\
  786. MODULE_PARM_DESC(lpfc_##name, desc);\
  787. lpfc_vport_param_hex_show(name)\
  788. lpfc_vport_param_init(name, defval, minval, maxval)\
  789. static DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  790. #define LPFC_VPORT_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
  791. static int lpfc_##name = defval;\
  792. module_param(lpfc_##name, int, 0);\
  793. MODULE_PARM_DESC(lpfc_##name, desc);\
  794. lpfc_vport_param_hex_show(name)\
  795. lpfc_vport_param_init(name, defval, minval, maxval)\
  796. lpfc_vport_param_set(name, defval, minval, maxval)\
  797. lpfc_vport_param_store(name)\
  798. static DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  799. lpfc_##name##_show, lpfc_##name##_store)
  800. static DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
  801. static DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
  802. static DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
  803. static DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
  804. static DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
  805. static DEVICE_ATTR(portnum, S_IRUGO, lpfc_vportnum_show, NULL);
  806. static DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
  807. static DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
  808. static DEVICE_ATTR(link_state, S_IRUGO, lpfc_link_state_show, NULL);
  809. static DEVICE_ATTR(option_rom_version, S_IRUGO,
  810. lpfc_option_rom_version_show, NULL);
  811. static DEVICE_ATTR(num_discovered_ports, S_IRUGO,
  812. lpfc_num_discovered_ports_show, NULL);
  813. static DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
  814. static DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show, NULL);
  815. static DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
  816. lpfc_board_mode_show, lpfc_board_mode_store);
  817. static DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
  818. static DEVICE_ATTR(max_vpi, S_IRUGO, lpfc_max_vpi_show, NULL);
  819. static DEVICE_ATTR(used_vpi, S_IRUGO, lpfc_used_vpi_show, NULL);
  820. static DEVICE_ATTR(max_rpi, S_IRUGO, lpfc_max_rpi_show, NULL);
  821. static DEVICE_ATTR(used_rpi, S_IRUGO, lpfc_used_rpi_show, NULL);
  822. static DEVICE_ATTR(max_xri, S_IRUGO, lpfc_max_xri_show, NULL);
  823. static DEVICE_ATTR(used_xri, S_IRUGO, lpfc_used_xri_show, NULL);
  824. static DEVICE_ATTR(npiv_info, S_IRUGO, lpfc_npiv_info_show, NULL);
  825. static DEVICE_ATTR(lpfc_temp_sensor, S_IRUGO, lpfc_temp_sensor_show, NULL);
  826. static char *lpfc_soft_wwn_key = "C99G71SL8032A";
  827. static ssize_t
  828. lpfc_soft_wwn_enable_store(struct device *dev, struct device_attribute *attr,
  829. const char *buf, size_t count)
  830. {
  831. struct Scsi_Host *shost = class_to_shost(dev);
  832. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  833. struct lpfc_hba *phba = vport->phba;
  834. unsigned int cnt = count;
  835. /*
  836. * We're doing a simple sanity check for soft_wwpn setting.
  837. * We require that the user write a specific key to enable
  838. * the soft_wwpn attribute to be settable. Once the attribute
  839. * is written, the enable key resets. If further updates are
  840. * desired, the key must be written again to re-enable the
  841. * attribute.
  842. *
  843. * The "key" is not secret - it is a hardcoded string shown
  844. * here. The intent is to protect against the random user or
  845. * application that is just writing attributes.
  846. */
  847. /* count may include a LF at end of string */
  848. if (buf[cnt-1] == '\n')
  849. cnt--;
  850. if ((cnt != strlen(lpfc_soft_wwn_key)) ||
  851. (strncmp(buf, lpfc_soft_wwn_key, strlen(lpfc_soft_wwn_key)) != 0))
  852. return -EINVAL;
  853. phba->soft_wwn_enable = 1;
  854. return count;
  855. }
  856. static DEVICE_ATTR(lpfc_soft_wwn_enable, S_IWUSR, NULL,
  857. lpfc_soft_wwn_enable_store);
  858. static ssize_t
  859. lpfc_soft_wwpn_show(struct device *dev, struct device_attribute *attr,
  860. char *buf)
  861. {
  862. struct Scsi_Host *shost = class_to_shost(dev);
  863. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  864. struct lpfc_hba *phba = vport->phba;
  865. return snprintf(buf, PAGE_SIZE, "0x%llx\n",
  866. (unsigned long long)phba->cfg_soft_wwpn);
  867. }
  868. static ssize_t
  869. lpfc_soft_wwpn_store(struct device *dev, struct device_attribute *attr,
  870. const char *buf, size_t count)
  871. {
  872. struct Scsi_Host *shost = class_to_shost(dev);
  873. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  874. struct lpfc_hba *phba = vport->phba;
  875. struct completion online_compl;
  876. int stat1=0, stat2=0;
  877. unsigned int i, j, cnt=count;
  878. u8 wwpn[8];
  879. if (!phba->cfg_enable_hba_reset)
  880. return -EACCES;
  881. spin_lock_irq(&phba->hbalock);
  882. if (phba->over_temp_state == HBA_OVER_TEMP) {
  883. spin_unlock_irq(&phba->hbalock);
  884. return -EACCES;
  885. }
  886. spin_unlock_irq(&phba->hbalock);
  887. /* count may include a LF at end of string */
  888. if (buf[cnt-1] == '\n')
  889. cnt--;
  890. if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
  891. ((cnt == 17) && (*buf++ != 'x')) ||
  892. ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
  893. return -EINVAL;
  894. phba->soft_wwn_enable = 0;
  895. memset(wwpn, 0, sizeof(wwpn));
  896. /* Validate and store the new name */
  897. for (i=0, j=0; i < 16; i++) {
  898. if ((*buf >= 'a') && (*buf <= 'f'))
  899. j = ((j << 4) | ((*buf++ -'a') + 10));
  900. else if ((*buf >= 'A') && (*buf <= 'F'))
  901. j = ((j << 4) | ((*buf++ -'A') + 10));
  902. else if ((*buf >= '0') && (*buf <= '9'))
  903. j = ((j << 4) | (*buf++ -'0'));
  904. else
  905. return -EINVAL;
  906. if (i % 2) {
  907. wwpn[i/2] = j & 0xff;
  908. j = 0;
  909. }
  910. }
  911. phba->cfg_soft_wwpn = wwn_to_u64(wwpn);
  912. fc_host_port_name(shost) = phba->cfg_soft_wwpn;
  913. if (phba->cfg_soft_wwnn)
  914. fc_host_node_name(shost) = phba->cfg_soft_wwnn;
  915. dev_printk(KERN_NOTICE, &phba->pcidev->dev,
  916. "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
  917. stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
  918. if (stat1)
  919. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  920. "0463 lpfc_soft_wwpn attribute set failed to "
  921. "reinit adapter - %d\n", stat1);
  922. init_completion(&online_compl);
  923. lpfc_workq_post_event(phba, &stat2, &online_compl, LPFC_EVT_ONLINE);
  924. wait_for_completion(&online_compl);
  925. if (stat2)
  926. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  927. "0464 lpfc_soft_wwpn attribute set failed to "
  928. "reinit adapter - %d\n", stat2);
  929. return (stat1 || stat2) ? -EIO : count;
  930. }
  931. static DEVICE_ATTR(lpfc_soft_wwpn, S_IRUGO | S_IWUSR,\
  932. lpfc_soft_wwpn_show, lpfc_soft_wwpn_store);
  933. static ssize_t
  934. lpfc_soft_wwnn_show(struct device *dev, struct device_attribute *attr,
  935. char *buf)
  936. {
  937. struct Scsi_Host *shost = class_to_shost(dev);
  938. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  939. return snprintf(buf, PAGE_SIZE, "0x%llx\n",
  940. (unsigned long long)phba->cfg_soft_wwnn);
  941. }
  942. static ssize_t
  943. lpfc_soft_wwnn_store(struct device *dev, struct device_attribute *attr,
  944. const char *buf, size_t count)
  945. {
  946. struct Scsi_Host *shost = class_to_shost(dev);
  947. struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
  948. unsigned int i, j, cnt=count;
  949. u8 wwnn[8];
  950. /* count may include a LF at end of string */
  951. if (buf[cnt-1] == '\n')
  952. cnt--;
  953. if (!phba->soft_wwn_enable || (cnt < 16) || (cnt > 18) ||
  954. ((cnt == 17) && (*buf++ != 'x')) ||
  955. ((cnt == 18) && ((*buf++ != '0') || (*buf++ != 'x'))))
  956. return -EINVAL;
  957. /*
  958. * Allow wwnn to be set many times, as long as the enable is set.
  959. * However, once the wwpn is set, everything locks.
  960. */
  961. memset(wwnn, 0, sizeof(wwnn));
  962. /* Validate and store the new name */
  963. for (i=0, j=0; i < 16; i++) {
  964. if ((*buf >= 'a') && (*buf <= 'f'))
  965. j = ((j << 4) | ((*buf++ -'a') + 10));
  966. else if ((*buf >= 'A') && (*buf <= 'F'))
  967. j = ((j << 4) | ((*buf++ -'A') + 10));
  968. else if ((*buf >= '0') && (*buf <= '9'))
  969. j = ((j << 4) | (*buf++ -'0'));
  970. else
  971. return -EINVAL;
  972. if (i % 2) {
  973. wwnn[i/2] = j & 0xff;
  974. j = 0;
  975. }
  976. }
  977. phba->cfg_soft_wwnn = wwn_to_u64(wwnn);
  978. dev_printk(KERN_NOTICE, &phba->pcidev->dev,
  979. "lpfc%d: soft_wwnn set. Value will take effect upon "
  980. "setting of the soft_wwpn\n", phba->brd_no);
  981. return count;
  982. }
  983. static DEVICE_ATTR(lpfc_soft_wwnn, S_IRUGO | S_IWUSR,\
  984. lpfc_soft_wwnn_show, lpfc_soft_wwnn_store);
  985. static int lpfc_poll = 0;
  986. module_param(lpfc_poll, int, 0);
  987. MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
  988. " 0 - none,"
  989. " 1 - poll with interrupts enabled"
  990. " 3 - poll and disable FCP ring interrupts");
  991. static DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
  992. lpfc_poll_show, lpfc_poll_store);
  993. int lpfc_sli_mode = 0;
  994. module_param(lpfc_sli_mode, int, 0);
  995. MODULE_PARM_DESC(lpfc_sli_mode, "SLI mode selector:"
  996. " 0 - auto (SLI-3 if supported),"
  997. " 2 - select SLI-2 even on SLI-3 capable HBAs,"
  998. " 3 - select SLI-3");
  999. int lpfc_enable_npiv = 0;
  1000. module_param(lpfc_enable_npiv, int, 0);
  1001. MODULE_PARM_DESC(lpfc_enable_npiv, "Enable NPIV functionality");
  1002. lpfc_param_show(enable_npiv);
  1003. lpfc_param_init(enable_npiv, 0, 0, 1);
  1004. static DEVICE_ATTR(lpfc_enable_npiv, S_IRUGO,
  1005. lpfc_enable_npiv_show, NULL);
  1006. /*
  1007. # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
  1008. # until the timer expires. Value range is [0,255]. Default value is 30.
  1009. */
  1010. static int lpfc_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
  1011. static int lpfc_devloss_tmo = LPFC_DEF_DEVLOSS_TMO;
  1012. module_param(lpfc_nodev_tmo, int, 0);
  1013. MODULE_PARM_DESC(lpfc_nodev_tmo,
  1014. "Seconds driver will hold I/O waiting "
  1015. "for a device to come back");
  1016. static ssize_t
  1017. lpfc_nodev_tmo_show(struct device *dev, struct device_attribute *attr,
  1018. char *buf)
  1019. {
  1020. struct Scsi_Host *shost = class_to_shost(dev);
  1021. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1022. int val = 0;
  1023. val = vport->cfg_devloss_tmo;
  1024. return snprintf(buf, PAGE_SIZE, "%d\n", vport->cfg_devloss_tmo);
  1025. }
  1026. static int
  1027. lpfc_nodev_tmo_init(struct lpfc_vport *vport, int val)
  1028. {
  1029. if (vport->cfg_devloss_tmo != LPFC_DEF_DEVLOSS_TMO) {
  1030. vport->cfg_nodev_tmo = vport->cfg_devloss_tmo;
  1031. if (val != LPFC_DEF_DEVLOSS_TMO)
  1032. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1033. "0402 Ignoring nodev_tmo module "
  1034. "parameter because devloss_tmo is "
  1035. "set.\n");
  1036. return 0;
  1037. }
  1038. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  1039. vport->cfg_nodev_tmo = val;
  1040. vport->cfg_devloss_tmo = val;
  1041. return 0;
  1042. }
  1043. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1044. "0400 lpfc_nodev_tmo attribute cannot be set to"
  1045. " %d, allowed range is [%d, %d]\n",
  1046. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  1047. vport->cfg_nodev_tmo = LPFC_DEF_DEVLOSS_TMO;
  1048. return -EINVAL;
  1049. }
  1050. static void
  1051. lpfc_update_rport_devloss_tmo(struct lpfc_vport *vport)
  1052. {
  1053. struct Scsi_Host *shost;
  1054. struct lpfc_nodelist *ndlp;
  1055. shost = lpfc_shost_from_vport(vport);
  1056. spin_lock_irq(shost->host_lock);
  1057. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp)
  1058. if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport)
  1059. ndlp->rport->dev_loss_tmo = vport->cfg_devloss_tmo;
  1060. spin_unlock_irq(shost->host_lock);
  1061. }
  1062. static int
  1063. lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
  1064. {
  1065. if (vport->dev_loss_tmo_changed ||
  1066. (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
  1067. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1068. "0401 Ignoring change to nodev_tmo "
  1069. "because devloss_tmo is set.\n");
  1070. return 0;
  1071. }
  1072. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  1073. vport->cfg_nodev_tmo = val;
  1074. vport->cfg_devloss_tmo = val;
  1075. lpfc_update_rport_devloss_tmo(vport);
  1076. return 0;
  1077. }
  1078. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1079. "0403 lpfc_nodev_tmo attribute cannot be set to"
  1080. "%d, allowed range is [%d, %d]\n",
  1081. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  1082. return -EINVAL;
  1083. }
  1084. lpfc_vport_param_store(nodev_tmo)
  1085. static DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
  1086. lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
  1087. /*
  1088. # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
  1089. # disappear until the timer expires. Value range is [0,255]. Default
  1090. # value is 30.
  1091. */
  1092. module_param(lpfc_devloss_tmo, int, 0);
  1093. MODULE_PARM_DESC(lpfc_devloss_tmo,
  1094. "Seconds driver will hold I/O waiting "
  1095. "for a device to come back");
  1096. lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
  1097. LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
  1098. lpfc_vport_param_show(devloss_tmo)
  1099. static int
  1100. lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
  1101. {
  1102. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  1103. vport->cfg_nodev_tmo = val;
  1104. vport->cfg_devloss_tmo = val;
  1105. vport->dev_loss_tmo_changed = 1;
  1106. lpfc_update_rport_devloss_tmo(vport);
  1107. return 0;
  1108. }
  1109. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1110. "0404 lpfc_devloss_tmo attribute cannot be set to"
  1111. " %d, allowed range is [%d, %d]\n",
  1112. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  1113. return -EINVAL;
  1114. }
  1115. lpfc_vport_param_store(devloss_tmo)
  1116. static DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
  1117. lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
  1118. /*
  1119. # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
  1120. # deluged with LOTS of information.
  1121. # You can set a bit mask to record specific types of verbose messages:
  1122. #
  1123. # LOG_ELS 0x1 ELS events
  1124. # LOG_DISCOVERY 0x2 Link discovery events
  1125. # LOG_MBOX 0x4 Mailbox events
  1126. # LOG_INIT 0x8 Initialization events
  1127. # LOG_LINK_EVENT 0x10 Link events
  1128. # LOG_FCP 0x40 FCP traffic history
  1129. # LOG_NODE 0x80 Node table events
  1130. # LOG_MISC 0x400 Miscellaneous events
  1131. # LOG_SLI 0x800 SLI events
  1132. # LOG_FCP_ERROR 0x1000 Only log FCP errors
  1133. # LOG_LIBDFC 0x2000 LIBDFC events
  1134. # LOG_ALL_MSG 0xffff LOG all messages
  1135. */
  1136. LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
  1137. "Verbose logging bit-mask");
  1138. /*
  1139. # lpfc_enable_da_id: This turns on the DA_ID CT command that deregisters
  1140. # objects that have been registered with the nameserver after login.
  1141. */
  1142. LPFC_VPORT_ATTR_R(enable_da_id, 0, 0, 1,
  1143. "Deregister nameserver objects before LOGO");
  1144. /*
  1145. # lun_queue_depth: This parameter is used to limit the number of outstanding
  1146. # commands per FCP LUN. Value range is [1,128]. Default value is 30.
  1147. */
  1148. LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
  1149. "Max number of FCP commands we can queue to a specific LUN");
  1150. /*
  1151. # hba_queue_depth: This parameter is used to limit the number of outstanding
  1152. # commands per lpfc HBA. Value range is [32,8192]. If this parameter
  1153. # value is greater than the maximum number of exchanges supported by the HBA,
  1154. # then maximum number of exchanges supported by the HBA is used to determine
  1155. # the hba_queue_depth.
  1156. */
  1157. LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
  1158. "Max number of FCP commands we can queue to a lpfc HBA");
  1159. /*
  1160. # peer_port_login: This parameter allows/prevents logins
  1161. # between peer ports hosted on the same physical port.
  1162. # When this parameter is set 0 peer ports of same physical port
  1163. # are not allowed to login to each other.
  1164. # When this parameter is set 1 peer ports of same physical port
  1165. # are allowed to login to each other.
  1166. # Default value of this parameter is 0.
  1167. */
  1168. LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
  1169. "Allow peer ports on the same physical port to login to each "
  1170. "other.");
  1171. /*
  1172. # restrict_login: This parameter allows/prevents logins
  1173. # between Virtual Ports and remote initiators.
  1174. # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
  1175. # other initiators and will attempt to PLOGI all remote ports.
  1176. # When this parameter is set (1) Virtual Ports will reject PLOGIs from
  1177. # remote ports and will not attempt to PLOGI to other initiators.
  1178. # This parameter does not restrict to the physical port.
  1179. # This parameter does not restrict logins to Fabric resident remote ports.
  1180. # Default value of this parameter is 1.
  1181. */
  1182. static int lpfc_restrict_login = 1;
  1183. module_param(lpfc_restrict_login, int, 0);
  1184. MODULE_PARM_DESC(lpfc_restrict_login,
  1185. "Restrict virtual ports login to remote initiators.");
  1186. lpfc_vport_param_show(restrict_login);
  1187. static int
  1188. lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
  1189. {
  1190. if (val < 0 || val > 1) {
  1191. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1192. "0449 lpfc_restrict_login attribute cannot "
  1193. "be set to %d, allowed range is [0, 1]\n",
  1194. val);
  1195. vport->cfg_restrict_login = 1;
  1196. return -EINVAL;
  1197. }
  1198. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  1199. vport->cfg_restrict_login = 0;
  1200. return 0;
  1201. }
  1202. vport->cfg_restrict_login = val;
  1203. return 0;
  1204. }
  1205. static int
  1206. lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
  1207. {
  1208. if (val < 0 || val > 1) {
  1209. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1210. "0450 lpfc_restrict_login attribute cannot "
  1211. "be set to %d, allowed range is [0, 1]\n",
  1212. val);
  1213. vport->cfg_restrict_login = 1;
  1214. return -EINVAL;
  1215. }
  1216. if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
  1217. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1218. "0468 lpfc_restrict_login must be 0 for "
  1219. "Physical ports.\n");
  1220. vport->cfg_restrict_login = 0;
  1221. return 0;
  1222. }
  1223. vport->cfg_restrict_login = val;
  1224. return 0;
  1225. }
  1226. lpfc_vport_param_store(restrict_login);
  1227. static DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
  1228. lpfc_restrict_login_show, lpfc_restrict_login_store);
  1229. /*
  1230. # Some disk devices have a "select ID" or "select Target" capability.
  1231. # From a protocol standpoint "select ID" usually means select the
  1232. # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
  1233. # annex" which contains a table that maps a "select ID" (a number
  1234. # between 0 and 7F) to an ALPA. By default, for compatibility with
  1235. # older drivers, the lpfc driver scans this table from low ALPA to high
  1236. # ALPA.
  1237. #
  1238. # Turning on the scan-down variable (on = 1, off = 0) will
  1239. # cause the lpfc driver to use an inverted table, effectively
  1240. # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
  1241. #
  1242. # (Note: This "select ID" functionality is a LOOP ONLY characteristic
  1243. # and will not work across a fabric. Also this parameter will take
  1244. # effect only in the case when ALPA map is not available.)
  1245. */
  1246. LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
  1247. "Start scanning for devices from highest ALPA to lowest");
  1248. /*
  1249. # lpfc_topology: link topology for init link
  1250. # 0x0 = attempt loop mode then point-to-point
  1251. # 0x01 = internal loopback mode
  1252. # 0x02 = attempt point-to-point mode only
  1253. # 0x04 = attempt loop mode only
  1254. # 0x06 = attempt point-to-point mode then loop
  1255. # Set point-to-point mode if you want to run as an N_Port.
  1256. # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
  1257. # Default value is 0.
  1258. */
  1259. static int
  1260. lpfc_topology_set(struct lpfc_hba *phba, int val)
  1261. {
  1262. int err;
  1263. uint32_t prev_val;
  1264. if (val >= 0 && val <= 6) {
  1265. prev_val = phba->cfg_topology;
  1266. phba->cfg_topology = val;
  1267. err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
  1268. if (err)
  1269. phba->cfg_topology = prev_val;
  1270. return err;
  1271. }
  1272. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1273. "%d:0467 lpfc_topology attribute cannot be set to %d, "
  1274. "allowed range is [0, 6]\n",
  1275. phba->brd_no, val);
  1276. return -EINVAL;
  1277. }
  1278. static int lpfc_topology = 0;
  1279. module_param(lpfc_topology, int, 0);
  1280. MODULE_PARM_DESC(lpfc_topology, "Select Fibre Channel topology");
  1281. lpfc_param_show(topology)
  1282. lpfc_param_init(topology, 0, 0, 6)
  1283. lpfc_param_store(topology)
  1284. static DEVICE_ATTR(lpfc_topology, S_IRUGO | S_IWUSR,
  1285. lpfc_topology_show, lpfc_topology_store);
  1286. /*
  1287. # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
  1288. # connection.
  1289. # 0 = auto select (default)
  1290. # 1 = 1 Gigabaud
  1291. # 2 = 2 Gigabaud
  1292. # 4 = 4 Gigabaud
  1293. # 8 = 8 Gigabaud
  1294. # Value range is [0,8]. Default value is 0.
  1295. */
  1296. static int
  1297. lpfc_link_speed_set(struct lpfc_hba *phba, int val)
  1298. {
  1299. int err;
  1300. uint32_t prev_val;
  1301. if (((val == LINK_SPEED_1G) && !(phba->lmt & LMT_1Gb)) ||
  1302. ((val == LINK_SPEED_2G) && !(phba->lmt & LMT_2Gb)) ||
  1303. ((val == LINK_SPEED_4G) && !(phba->lmt & LMT_4Gb)) ||
  1304. ((val == LINK_SPEED_8G) && !(phba->lmt & LMT_8Gb)) ||
  1305. ((val == LINK_SPEED_10G) && !(phba->lmt & LMT_10Gb)))
  1306. return -EINVAL;
  1307. if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
  1308. && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
  1309. prev_val = phba->cfg_link_speed;
  1310. phba->cfg_link_speed = val;
  1311. err = lpfc_issue_lip(lpfc_shost_from_vport(phba->pport));
  1312. if (err)
  1313. phba->cfg_link_speed = prev_val;
  1314. return err;
  1315. }
  1316. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1317. "%d:0469 lpfc_link_speed attribute cannot be set to %d, "
  1318. "allowed range is [0, 8]\n",
  1319. phba->brd_no, val);
  1320. return -EINVAL;
  1321. }
  1322. static int lpfc_link_speed = 0;
  1323. module_param(lpfc_link_speed, int, 0);
  1324. MODULE_PARM_DESC(lpfc_link_speed, "Select link speed");
  1325. lpfc_param_show(link_speed)
  1326. static int
  1327. lpfc_link_speed_init(struct lpfc_hba *phba, int val)
  1328. {
  1329. if ((val >= 0 && val <= LPFC_MAX_LINK_SPEED)
  1330. && (LPFC_LINK_SPEED_BITMAP & (1 << val))) {
  1331. phba->cfg_link_speed = val;
  1332. return 0;
  1333. }
  1334. lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
  1335. "0454 lpfc_link_speed attribute cannot "
  1336. "be set to %d, allowed values are "
  1337. "["LPFC_LINK_SPEED_STRING"]\n", val);
  1338. phba->cfg_link_speed = 0;
  1339. return -EINVAL;
  1340. }
  1341. lpfc_param_store(link_speed)
  1342. static DEVICE_ATTR(lpfc_link_speed, S_IRUGO | S_IWUSR,
  1343. lpfc_link_speed_show, lpfc_link_speed_store);
  1344. /*
  1345. # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
  1346. # Value range is [2,3]. Default value is 3.
  1347. */
  1348. LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
  1349. "Select Fibre Channel class of service for FCP sequences");
  1350. /*
  1351. # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
  1352. # is [0,1]. Default value is 0.
  1353. */
  1354. LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
  1355. "Use ADISC on rediscovery to authenticate FCP devices");
  1356. /*
  1357. # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
  1358. # range is [0,1]. Default value is 0.
  1359. */
  1360. LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
  1361. /*
  1362. # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
  1363. # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
  1364. # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
  1365. # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
  1366. # cr_delay is set to 0.
  1367. */
  1368. LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
  1369. "interrupt response is generated");
  1370. LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
  1371. "interrupt response is generated");
  1372. /*
  1373. # lpfc_multi_ring_support: Determines how many rings to spread available
  1374. # cmd/rsp IOCB entries across.
  1375. # Value range is [1,2]. Default value is 1.
  1376. */
  1377. LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
  1378. "SLI rings to spread IOCB entries across");
  1379. /*
  1380. # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
  1381. # identifies what rctl value to configure the additional ring for.
  1382. # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
  1383. */
  1384. LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
  1385. 255, "Identifies RCTL for additional ring configuration");
  1386. /*
  1387. # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
  1388. # identifies what type value to configure the additional ring for.
  1389. # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
  1390. */
  1391. LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
  1392. 255, "Identifies TYPE for additional ring configuration");
  1393. /*
  1394. # lpfc_fdmi_on: controls FDMI support.
  1395. # 0 = no FDMI support
  1396. # 1 = support FDMI without attribute of hostname
  1397. # 2 = support FDMI with attribute of hostname
  1398. # Value range [0,2]. Default value is 0.
  1399. */
  1400. LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
  1401. /*
  1402. # Specifies the maximum number of ELS cmds we can have outstanding (for
  1403. # discovery). Value range is [1,64]. Default value = 32.
  1404. */
  1405. LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
  1406. "during discovery");
  1407. /*
  1408. # lpfc_max_luns: maximum allowed LUN.
  1409. # Value range is [0,65535]. Default value is 255.
  1410. # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
  1411. */
  1412. LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
  1413. /*
  1414. # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
  1415. # Value range is [1,255], default value is 10.
  1416. */
  1417. LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
  1418. "Milliseconds driver will wait between polling FCP ring");
  1419. /*
  1420. # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
  1421. # support this feature
  1422. # 0 = MSI disabled (default)
  1423. # 1 = MSI enabled
  1424. # 2 = MSI-X enabled
  1425. # Value range is [0,2]. Default value is 0.
  1426. */
  1427. LPFC_ATTR_R(use_msi, 0, 0, 2, "Use Message Signaled Interrupts (1) or "
  1428. "MSI-X (2), if possible");
  1429. /*
  1430. # lpfc_enable_hba_reset: Allow or prevent HBA resets to the hardware.
  1431. # 0 = HBA resets disabled
  1432. # 1 = HBA resets enabled (default)
  1433. # Value range is [0,1]. Default value is 1.
  1434. */
  1435. LPFC_ATTR_R(enable_hba_reset, 1, 0, 1, "Enable HBA resets from the driver.");
  1436. /*
  1437. # lpfc_enable_hba_heartbeat: Enable HBA heartbeat timer..
  1438. # 0 = HBA Heartbeat disabled
  1439. # 1 = HBA Heartbeat enabled (default)
  1440. # Value range is [0,1]. Default value is 1.
  1441. */
  1442. LPFC_ATTR_R(enable_hba_heartbeat, 1, 0, 1, "Enable HBA Heartbeat.");
  1443. /*
  1444. * lpfc_sg_seg_cnt: Initial Maximum DMA Segment Count
  1445. * This value can be set to values between 64 and 256. The default value is
  1446. * 64, but may be increased to allow for larger Max I/O sizes. The scsi layer
  1447. * will be allowed to request I/Os of sizes up to (MAX_SEG_COUNT * SEG_SIZE).
  1448. */
  1449. LPFC_ATTR_R(sg_seg_cnt, LPFC_DEFAULT_SG_SEG_CNT, LPFC_DEFAULT_SG_SEG_CNT,
  1450. LPFC_MAX_SG_SEG_CNT, "Max Scatter Gather Segment Count");
  1451. struct device_attribute *lpfc_hba_attrs[] = {
  1452. &dev_attr_info,
  1453. &dev_attr_serialnum,
  1454. &dev_attr_modeldesc,
  1455. &dev_attr_modelname,
  1456. &dev_attr_programtype,
  1457. &dev_attr_portnum,
  1458. &dev_attr_fwrev,
  1459. &dev_attr_hdw,
  1460. &dev_attr_option_rom_version,
  1461. &dev_attr_link_state,
  1462. &dev_attr_num_discovered_ports,
  1463. &dev_attr_lpfc_drvr_version,
  1464. &dev_attr_lpfc_temp_sensor,
  1465. &dev_attr_lpfc_log_verbose,
  1466. &dev_attr_lpfc_lun_queue_depth,
  1467. &dev_attr_lpfc_hba_queue_depth,
  1468. &dev_attr_lpfc_peer_port_login,
  1469. &dev_attr_lpfc_nodev_tmo,
  1470. &dev_attr_lpfc_devloss_tmo,
  1471. &dev_attr_lpfc_fcp_class,
  1472. &dev_attr_lpfc_use_adisc,
  1473. &dev_attr_lpfc_ack0,
  1474. &dev_attr_lpfc_topology,
  1475. &dev_attr_lpfc_scan_down,
  1476. &dev_attr_lpfc_link_speed,
  1477. &dev_attr_lpfc_cr_delay,
  1478. &dev_attr_lpfc_cr_count,
  1479. &dev_attr_lpfc_multi_ring_support,
  1480. &dev_attr_lpfc_multi_ring_rctl,
  1481. &dev_attr_lpfc_multi_ring_type,
  1482. &dev_attr_lpfc_fdmi_on,
  1483. &dev_attr_lpfc_max_luns,
  1484. &dev_attr_lpfc_enable_npiv,
  1485. &dev_attr_nport_evt_cnt,
  1486. &dev_attr_board_mode,
  1487. &dev_attr_max_vpi,
  1488. &dev_attr_used_vpi,
  1489. &dev_attr_max_rpi,
  1490. &dev_attr_used_rpi,
  1491. &dev_attr_max_xri,
  1492. &dev_attr_used_xri,
  1493. &dev_attr_npiv_info,
  1494. &dev_attr_issue_reset,
  1495. &dev_attr_lpfc_poll,
  1496. &dev_attr_lpfc_poll_tmo,
  1497. &dev_attr_lpfc_use_msi,
  1498. &dev_attr_lpfc_soft_wwnn,
  1499. &dev_attr_lpfc_soft_wwpn,
  1500. &dev_attr_lpfc_soft_wwn_enable,
  1501. &dev_attr_lpfc_enable_hba_reset,
  1502. &dev_attr_lpfc_enable_hba_heartbeat,
  1503. &dev_attr_lpfc_sg_seg_cnt,
  1504. NULL,
  1505. };
  1506. struct device_attribute *lpfc_vport_attrs[] = {
  1507. &dev_attr_info,
  1508. &dev_attr_link_state,
  1509. &dev_attr_num_discovered_ports,
  1510. &dev_attr_lpfc_drvr_version,
  1511. &dev_attr_lpfc_log_verbose,
  1512. &dev_attr_lpfc_lun_queue_depth,
  1513. &dev_attr_lpfc_nodev_tmo,
  1514. &dev_attr_lpfc_devloss_tmo,
  1515. &dev_attr_lpfc_hba_queue_depth,
  1516. &dev_attr_lpfc_peer_port_login,
  1517. &dev_attr_lpfc_restrict_login,
  1518. &dev_attr_lpfc_fcp_class,
  1519. &dev_attr_lpfc_use_adisc,
  1520. &dev_attr_lpfc_fdmi_on,
  1521. &dev_attr_lpfc_max_luns,
  1522. &dev_attr_nport_evt_cnt,
  1523. &dev_attr_npiv_info,
  1524. &dev_attr_lpfc_enable_da_id,
  1525. NULL,
  1526. };
  1527. static ssize_t
  1528. sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
  1529. char *buf, loff_t off, size_t count)
  1530. {
  1531. size_t buf_off;
  1532. struct device *dev = container_of(kobj, struct device, kobj);
  1533. struct Scsi_Host *shost = class_to_shost(dev);
  1534. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1535. struct lpfc_hba *phba = vport->phba;
  1536. if ((off + count) > FF_REG_AREA_SIZE)
  1537. return -ERANGE;
  1538. if (count == 0) return 0;
  1539. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  1540. return -EINVAL;
  1541. if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
  1542. return -EPERM;
  1543. }
  1544. spin_lock_irq(&phba->hbalock);
  1545. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
  1546. writel(*((uint32_t *)(buf + buf_off)),
  1547. phba->ctrl_regs_memmap_p + off + buf_off);
  1548. spin_unlock_irq(&phba->hbalock);
  1549. return count;
  1550. }
  1551. static ssize_t
  1552. sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
  1553. char *buf, loff_t off, size_t count)
  1554. {
  1555. size_t buf_off;
  1556. uint32_t * tmp_ptr;
  1557. struct device *dev = container_of(kobj, struct device, kobj);
  1558. struct Scsi_Host *shost = class_to_shost(dev);
  1559. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1560. struct lpfc_hba *phba = vport->phba;
  1561. if (off > FF_REG_AREA_SIZE)
  1562. return -ERANGE;
  1563. if ((off + count) > FF_REG_AREA_SIZE)
  1564. count = FF_REG_AREA_SIZE - off;
  1565. if (count == 0) return 0;
  1566. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  1567. return -EINVAL;
  1568. spin_lock_irq(&phba->hbalock);
  1569. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
  1570. tmp_ptr = (uint32_t *)(buf + buf_off);
  1571. *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
  1572. }
  1573. spin_unlock_irq(&phba->hbalock);
  1574. return count;
  1575. }
  1576. static struct bin_attribute sysfs_ctlreg_attr = {
  1577. .attr = {
  1578. .name = "ctlreg",
  1579. .mode = S_IRUSR | S_IWUSR,
  1580. },
  1581. .size = 256,
  1582. .read = sysfs_ctlreg_read,
  1583. .write = sysfs_ctlreg_write,
  1584. };
  1585. static void
  1586. sysfs_mbox_idle(struct lpfc_hba *phba)
  1587. {
  1588. phba->sysfs_mbox.state = SMBOX_IDLE;
  1589. phba->sysfs_mbox.offset = 0;
  1590. if (phba->sysfs_mbox.mbox) {
  1591. mempool_free(phba->sysfs_mbox.mbox,
  1592. phba->mbox_mem_pool);
  1593. phba->sysfs_mbox.mbox = NULL;
  1594. }
  1595. }
  1596. static ssize_t
  1597. sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
  1598. char *buf, loff_t off, size_t count)
  1599. {
  1600. struct device *dev = container_of(kobj, struct device, kobj);
  1601. struct Scsi_Host *shost = class_to_shost(dev);
  1602. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1603. struct lpfc_hba *phba = vport->phba;
  1604. struct lpfcMboxq *mbox = NULL;
  1605. if ((count + off) > MAILBOX_CMD_SIZE)
  1606. return -ERANGE;
  1607. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  1608. return -EINVAL;
  1609. if (count == 0)
  1610. return 0;
  1611. if (off == 0) {
  1612. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1613. if (!mbox)
  1614. return -ENOMEM;
  1615. memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
  1616. }
  1617. spin_lock_irq(&phba->hbalock);
  1618. if (off == 0) {
  1619. if (phba->sysfs_mbox.mbox)
  1620. mempool_free(mbox, phba->mbox_mem_pool);
  1621. else
  1622. phba->sysfs_mbox.mbox = mbox;
  1623. phba->sysfs_mbox.state = SMBOX_WRITING;
  1624. } else {
  1625. if (phba->sysfs_mbox.state != SMBOX_WRITING ||
  1626. phba->sysfs_mbox.offset != off ||
  1627. phba->sysfs_mbox.mbox == NULL) {
  1628. sysfs_mbox_idle(phba);
  1629. spin_unlock_irq(&phba->hbalock);
  1630. return -EAGAIN;
  1631. }
  1632. }
  1633. memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
  1634. buf, count);
  1635. phba->sysfs_mbox.offset = off + count;
  1636. spin_unlock_irq(&phba->hbalock);
  1637. return count;
  1638. }
  1639. static ssize_t
  1640. sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
  1641. char *buf, loff_t off, size_t count)
  1642. {
  1643. struct device *dev = container_of(kobj, struct device, kobj);
  1644. struct Scsi_Host *shost = class_to_shost(dev);
  1645. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1646. struct lpfc_hba *phba = vport->phba;
  1647. int rc;
  1648. if (off > MAILBOX_CMD_SIZE)
  1649. return -ERANGE;
  1650. if ((count + off) > MAILBOX_CMD_SIZE)
  1651. count = MAILBOX_CMD_SIZE - off;
  1652. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  1653. return -EINVAL;
  1654. if (off && count == 0)
  1655. return 0;
  1656. spin_lock_irq(&phba->hbalock);
  1657. if (phba->over_temp_state == HBA_OVER_TEMP) {
  1658. sysfs_mbox_idle(phba);
  1659. spin_unlock_irq(&phba->hbalock);
  1660. return -EACCES;
  1661. }
  1662. if (off == 0 &&
  1663. phba->sysfs_mbox.state == SMBOX_WRITING &&
  1664. phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
  1665. switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
  1666. /* Offline only */
  1667. case MBX_INIT_LINK:
  1668. case MBX_DOWN_LINK:
  1669. case MBX_CONFIG_LINK:
  1670. case MBX_CONFIG_RING:
  1671. case MBX_RESET_RING:
  1672. case MBX_UNREG_LOGIN:
  1673. case MBX_CLEAR_LA:
  1674. case MBX_DUMP_CONTEXT:
  1675. case MBX_RUN_DIAGS:
  1676. case MBX_RESTART:
  1677. case MBX_SET_MASK:
  1678. case MBX_SET_DEBUG:
  1679. if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
  1680. printk(KERN_WARNING "mbox_read:Command 0x%x "
  1681. "is illegal in on-line state\n",
  1682. phba->sysfs_mbox.mbox->mb.mbxCommand);
  1683. sysfs_mbox_idle(phba);
  1684. spin_unlock_irq(&phba->hbalock);
  1685. return -EPERM;
  1686. }
  1687. case MBX_WRITE_NV:
  1688. case MBX_WRITE_VPARMS:
  1689. case MBX_LOAD_SM:
  1690. case MBX_READ_NV:
  1691. case MBX_READ_CONFIG:
  1692. case MBX_READ_RCONFIG:
  1693. case MBX_READ_STATUS:
  1694. case MBX_READ_XRI:
  1695. case MBX_READ_REV:
  1696. case MBX_READ_LNK_STAT:
  1697. case MBX_DUMP_MEMORY:
  1698. case MBX_DOWN_LOAD:
  1699. case MBX_UPDATE_CFG:
  1700. case MBX_KILL_BOARD:
  1701. case MBX_LOAD_AREA:
  1702. case MBX_LOAD_EXP_ROM:
  1703. case MBX_BEACON:
  1704. case MBX_DEL_LD_ENTRY:
  1705. case MBX_SET_VARIABLE:
  1706. case MBX_WRITE_WWN:
  1707. break;
  1708. case MBX_READ_SPARM64:
  1709. case MBX_READ_LA:
  1710. case MBX_READ_LA64:
  1711. case MBX_REG_LOGIN:
  1712. case MBX_REG_LOGIN64:
  1713. case MBX_CONFIG_PORT:
  1714. case MBX_RUN_BIU_DIAG:
  1715. printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
  1716. phba->sysfs_mbox.mbox->mb.mbxCommand);
  1717. sysfs_mbox_idle(phba);
  1718. spin_unlock_irq(&phba->hbalock);
  1719. return -EPERM;
  1720. default:
  1721. printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
  1722. phba->sysfs_mbox.mbox->mb.mbxCommand);
  1723. sysfs_mbox_idle(phba);
  1724. spin_unlock_irq(&phba->hbalock);
  1725. return -EPERM;
  1726. }
  1727. /* If HBA encountered an error attention, allow only DUMP
  1728. * or RESTART mailbox commands until the HBA is restarted.
  1729. */
  1730. if ((phba->pport->stopped) &&
  1731. (phba->sysfs_mbox.mbox->mb.mbxCommand !=
  1732. MBX_DUMP_MEMORY &&
  1733. phba->sysfs_mbox.mbox->mb.mbxCommand !=
  1734. MBX_RESTART &&
  1735. phba->sysfs_mbox.mbox->mb.mbxCommand !=
  1736. MBX_WRITE_VPARMS)) {
  1737. sysfs_mbox_idle(phba);
  1738. spin_unlock_irq(&phba->hbalock);
  1739. return -EPERM;
  1740. }
  1741. phba->sysfs_mbox.mbox->vport = vport;
  1742. /* Don't allow mailbox commands to be sent when blocked
  1743. * or when in the middle of discovery
  1744. */
  1745. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
  1746. sysfs_mbox_idle(phba);
  1747. spin_unlock_irq(&phba->hbalock);
  1748. return -EAGAIN;
  1749. }
  1750. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  1751. (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
  1752. spin_unlock_irq(&phba->hbalock);
  1753. rc = lpfc_sli_issue_mbox (phba,
  1754. phba->sysfs_mbox.mbox,
  1755. MBX_POLL);
  1756. spin_lock_irq(&phba->hbalock);
  1757. } else {
  1758. spin_unlock_irq(&phba->hbalock);
  1759. rc = lpfc_sli_issue_mbox_wait (phba,
  1760. phba->sysfs_mbox.mbox,
  1761. lpfc_mbox_tmo_val(phba,
  1762. phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
  1763. spin_lock_irq(&phba->hbalock);
  1764. }
  1765. if (rc != MBX_SUCCESS) {
  1766. if (rc == MBX_TIMEOUT) {
  1767. phba->sysfs_mbox.mbox = NULL;
  1768. }
  1769. sysfs_mbox_idle(phba);
  1770. spin_unlock_irq(&phba->hbalock);
  1771. return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
  1772. }
  1773. phba->sysfs_mbox.state = SMBOX_READING;
  1774. }
  1775. else if (phba->sysfs_mbox.offset != off ||
  1776. phba->sysfs_mbox.state != SMBOX_READING) {
  1777. printk(KERN_WARNING "mbox_read: Bad State\n");
  1778. sysfs_mbox_idle(phba);
  1779. spin_unlock_irq(&phba->hbalock);
  1780. return -EAGAIN;
  1781. }
  1782. memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
  1783. phba->sysfs_mbox.offset = off + count;
  1784. if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
  1785. sysfs_mbox_idle(phba);
  1786. spin_unlock_irq(&phba->hbalock);
  1787. return count;
  1788. }
  1789. static struct bin_attribute sysfs_mbox_attr = {
  1790. .attr = {
  1791. .name = "mbox",
  1792. .mode = S_IRUSR | S_IWUSR,
  1793. },
  1794. .size = MAILBOX_CMD_SIZE,
  1795. .read = sysfs_mbox_read,
  1796. .write = sysfs_mbox_write,
  1797. };
  1798. int
  1799. lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
  1800. {
  1801. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1802. int error;
  1803. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  1804. &sysfs_ctlreg_attr);
  1805. if (error)
  1806. goto out;
  1807. error = sysfs_create_bin_file(&shost->shost_dev.kobj,
  1808. &sysfs_mbox_attr);
  1809. if (error)
  1810. goto out_remove_ctlreg_attr;
  1811. return 0;
  1812. out_remove_ctlreg_attr:
  1813. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
  1814. out:
  1815. return error;
  1816. }
  1817. void
  1818. lpfc_free_sysfs_attr(struct lpfc_vport *vport)
  1819. {
  1820. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1821. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_mbox_attr);
  1822. sysfs_remove_bin_file(&shost->shost_dev.kobj, &sysfs_ctlreg_attr);
  1823. }
  1824. /*
  1825. * Dynamic FC Host Attributes Support
  1826. */
  1827. static void
  1828. lpfc_get_host_port_id(struct Scsi_Host *shost)
  1829. {
  1830. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1831. /* note: fc_myDID already in cpu endianness */
  1832. fc_host_port_id(shost) = vport->fc_myDID;
  1833. }
  1834. static void
  1835. lpfc_get_host_port_type(struct Scsi_Host *shost)
  1836. {
  1837. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1838. struct lpfc_hba *phba = vport->phba;
  1839. spin_lock_irq(shost->host_lock);
  1840. if (vport->port_type == LPFC_NPIV_PORT) {
  1841. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1842. } else if (lpfc_is_link_up(phba)) {
  1843. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1844. if (vport->fc_flag & FC_PUBLIC_LOOP)
  1845. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  1846. else
  1847. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  1848. } else {
  1849. if (vport->fc_flag & FC_FABRIC)
  1850. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  1851. else
  1852. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  1853. }
  1854. } else
  1855. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1856. spin_unlock_irq(shost->host_lock);
  1857. }
  1858. static void
  1859. lpfc_get_host_port_state(struct Scsi_Host *shost)
  1860. {
  1861. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1862. struct lpfc_hba *phba = vport->phba;
  1863. spin_lock_irq(shost->host_lock);
  1864. if (vport->fc_flag & FC_OFFLINE_MODE)
  1865. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1866. else {
  1867. switch (phba->link_state) {
  1868. case LPFC_LINK_UNKNOWN:
  1869. case LPFC_LINK_DOWN:
  1870. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1871. break;
  1872. case LPFC_LINK_UP:
  1873. case LPFC_CLEAR_LA:
  1874. case LPFC_HBA_READY:
  1875. /* Links up, beyond this port_type reports state */
  1876. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1877. break;
  1878. case LPFC_HBA_ERROR:
  1879. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  1880. break;
  1881. default:
  1882. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1883. break;
  1884. }
  1885. }
  1886. spin_unlock_irq(shost->host_lock);
  1887. }
  1888. static void
  1889. lpfc_get_host_speed(struct Scsi_Host *shost)
  1890. {
  1891. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1892. struct lpfc_hba *phba = vport->phba;
  1893. spin_lock_irq(shost->host_lock);
  1894. if (lpfc_is_link_up(phba)) {
  1895. switch(phba->fc_linkspeed) {
  1896. case LA_1GHZ_LINK:
  1897. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  1898. break;
  1899. case LA_2GHZ_LINK:
  1900. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  1901. break;
  1902. case LA_4GHZ_LINK:
  1903. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  1904. break;
  1905. case LA_8GHZ_LINK:
  1906. fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
  1907. break;
  1908. default:
  1909. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1910. break;
  1911. }
  1912. } else
  1913. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1914. spin_unlock_irq(shost->host_lock);
  1915. }
  1916. static void
  1917. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  1918. {
  1919. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1920. struct lpfc_hba *phba = vport->phba;
  1921. u64 node_name;
  1922. spin_lock_irq(shost->host_lock);
  1923. if ((vport->fc_flag & FC_FABRIC) ||
  1924. ((phba->fc_topology == TOPOLOGY_LOOP) &&
  1925. (vport->fc_flag & FC_PUBLIC_LOOP)))
  1926. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  1927. else
  1928. /* fabric is local port if there is no F/FL_Port */
  1929. node_name = 0;
  1930. spin_unlock_irq(shost->host_lock);
  1931. fc_host_fabric_name(shost) = node_name;
  1932. }
  1933. static struct fc_host_statistics *
  1934. lpfc_get_stats(struct Scsi_Host *shost)
  1935. {
  1936. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1937. struct lpfc_hba *phba = vport->phba;
  1938. struct lpfc_sli *psli = &phba->sli;
  1939. struct fc_host_statistics *hs = &phba->link_stats;
  1940. struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
  1941. LPFC_MBOXQ_t *pmboxq;
  1942. MAILBOX_t *pmb;
  1943. unsigned long seconds;
  1944. int rc = 0;
  1945. /*
  1946. * prevent udev from issuing mailbox commands until the port is
  1947. * configured.
  1948. */
  1949. if (phba->link_state < LPFC_LINK_DOWN ||
  1950. !phba->mbox_mem_pool ||
  1951. (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
  1952. return NULL;
  1953. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  1954. return NULL;
  1955. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1956. if (!pmboxq)
  1957. return NULL;
  1958. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1959. pmb = &pmboxq->mb;
  1960. pmb->mbxCommand = MBX_READ_STATUS;
  1961. pmb->mbxOwner = OWN_HOST;
  1962. pmboxq->context1 = NULL;
  1963. pmboxq->vport = vport;
  1964. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  1965. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1966. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1967. else
  1968. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1969. if (rc != MBX_SUCCESS) {
  1970. if (rc != MBX_TIMEOUT)
  1971. mempool_free(pmboxq, phba->mbox_mem_pool);
  1972. return NULL;
  1973. }
  1974. memset(hs, 0, sizeof (struct fc_host_statistics));
  1975. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  1976. hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
  1977. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  1978. hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
  1979. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1980. pmb->mbxCommand = MBX_READ_LNK_STAT;
  1981. pmb->mbxOwner = OWN_HOST;
  1982. pmboxq->context1 = NULL;
  1983. pmboxq->vport = vport;
  1984. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  1985. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1986. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1987. else
  1988. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1989. if (rc != MBX_SUCCESS) {
  1990. if (rc != MBX_TIMEOUT)
  1991. mempool_free(pmboxq, phba->mbox_mem_pool);
  1992. return NULL;
  1993. }
  1994. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  1995. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  1996. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  1997. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  1998. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  1999. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  2000. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  2001. hs->link_failure_count -= lso->link_failure_count;
  2002. hs->loss_of_sync_count -= lso->loss_of_sync_count;
  2003. hs->loss_of_signal_count -= lso->loss_of_signal_count;
  2004. hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
  2005. hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
  2006. hs->invalid_crc_count -= lso->invalid_crc_count;
  2007. hs->error_frames -= lso->error_frames;
  2008. if (phba->fc_topology == TOPOLOGY_LOOP) {
  2009. hs->lip_count = (phba->fc_eventTag >> 1);
  2010. hs->lip_count -= lso->link_events;
  2011. hs->nos_count = -1;
  2012. } else {
  2013. hs->lip_count = -1;
  2014. hs->nos_count = (phba->fc_eventTag >> 1);
  2015. hs->nos_count -= lso->link_events;
  2016. }
  2017. hs->dumped_frames = -1;
  2018. seconds = get_seconds();
  2019. if (seconds < psli->stats_start)
  2020. hs->seconds_since_last_reset = seconds +
  2021. ((unsigned long)-1 - psli->stats_start);
  2022. else
  2023. hs->seconds_since_last_reset = seconds - psli->stats_start;
  2024. mempool_free(pmboxq, phba->mbox_mem_pool);
  2025. return hs;
  2026. }
  2027. static void
  2028. lpfc_reset_stats(struct Scsi_Host *shost)
  2029. {
  2030. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2031. struct lpfc_hba *phba = vport->phba;
  2032. struct lpfc_sli *psli = &phba->sli;
  2033. struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
  2034. LPFC_MBOXQ_t *pmboxq;
  2035. MAILBOX_t *pmb;
  2036. int rc = 0;
  2037. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  2038. return;
  2039. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  2040. if (!pmboxq)
  2041. return;
  2042. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  2043. pmb = &pmboxq->mb;
  2044. pmb->mbxCommand = MBX_READ_STATUS;
  2045. pmb->mbxOwner = OWN_HOST;
  2046. pmb->un.varWords[0] = 0x1; /* reset request */
  2047. pmboxq->context1 = NULL;
  2048. pmboxq->vport = vport;
  2049. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  2050. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  2051. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  2052. else
  2053. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  2054. if (rc != MBX_SUCCESS) {
  2055. if (rc != MBX_TIMEOUT)
  2056. mempool_free(pmboxq, phba->mbox_mem_pool);
  2057. return;
  2058. }
  2059. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  2060. pmb->mbxCommand = MBX_READ_LNK_STAT;
  2061. pmb->mbxOwner = OWN_HOST;
  2062. pmboxq->context1 = NULL;
  2063. pmboxq->vport = vport;
  2064. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  2065. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  2066. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  2067. else
  2068. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  2069. if (rc != MBX_SUCCESS) {
  2070. if (rc != MBX_TIMEOUT)
  2071. mempool_free( pmboxq, phba->mbox_mem_pool);
  2072. return;
  2073. }
  2074. lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  2075. lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  2076. lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  2077. lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  2078. lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  2079. lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  2080. lso->error_frames = pmb->un.varRdLnk.crcCnt;
  2081. lso->link_events = (phba->fc_eventTag >> 1);
  2082. psli->stats_start = get_seconds();
  2083. mempool_free(pmboxq, phba->mbox_mem_pool);
  2084. return;
  2085. }
  2086. /*
  2087. * The LPFC driver treats linkdown handling as target loss events so there
  2088. * are no sysfs handlers for link_down_tmo.
  2089. */
  2090. static struct lpfc_nodelist *
  2091. lpfc_get_node_by_target(struct scsi_target *starget)
  2092. {
  2093. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  2094. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  2095. struct lpfc_nodelist *ndlp;
  2096. spin_lock_irq(shost->host_lock);
  2097. /* Search for this, mapped, target ID */
  2098. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  2099. if (NLP_CHK_NODE_ACT(ndlp) &&
  2100. ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  2101. starget->id == ndlp->nlp_sid) {
  2102. spin_unlock_irq(shost->host_lock);
  2103. return ndlp;
  2104. }
  2105. }
  2106. spin_unlock_irq(shost->host_lock);
  2107. return NULL;
  2108. }
  2109. static void
  2110. lpfc_get_starget_port_id(struct scsi_target *starget)
  2111. {
  2112. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  2113. fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
  2114. }
  2115. static void
  2116. lpfc_get_starget_node_name(struct scsi_target *starget)
  2117. {
  2118. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  2119. fc_starget_node_name(starget) =
  2120. ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
  2121. }
  2122. static void
  2123. lpfc_get_starget_port_name(struct scsi_target *starget)
  2124. {
  2125. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  2126. fc_starget_port_name(starget) =
  2127. ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
  2128. }
  2129. static void
  2130. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  2131. {
  2132. if (timeout)
  2133. rport->dev_loss_tmo = timeout;
  2134. else
  2135. rport->dev_loss_tmo = 1;
  2136. }
  2137. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  2138. static ssize_t \
  2139. lpfc_show_rport_##field (struct device *dev, \
  2140. struct device_attribute *attr, \
  2141. char *buf) \
  2142. { \
  2143. struct fc_rport *rport = transport_class_to_rport(dev); \
  2144. struct lpfc_rport_data *rdata = rport->hostdata; \
  2145. return snprintf(buf, sz, format_string, \
  2146. (rdata->target) ? cast rdata->target->field : 0); \
  2147. }
  2148. #define lpfc_rport_rd_attr(field, format_string, sz) \
  2149. lpfc_rport_show_function(field, format_string, sz, ) \
  2150. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  2151. struct fc_function_template lpfc_transport_functions = {
  2152. /* fixed attributes the driver supports */
  2153. .show_host_node_name = 1,
  2154. .show_host_port_name = 1,
  2155. .show_host_supported_classes = 1,
  2156. .show_host_supported_fc4s = 1,
  2157. .show_host_supported_speeds = 1,
  2158. .show_host_maxframe_size = 1,
  2159. /* dynamic attributes the driver supports */
  2160. .get_host_port_id = lpfc_get_host_port_id,
  2161. .show_host_port_id = 1,
  2162. .get_host_port_type = lpfc_get_host_port_type,
  2163. .show_host_port_type = 1,
  2164. .get_host_port_state = lpfc_get_host_port_state,
  2165. .show_host_port_state = 1,
  2166. /* active_fc4s is shown but doesn't change (thus no get function) */
  2167. .show_host_active_fc4s = 1,
  2168. .get_host_speed = lpfc_get_host_speed,
  2169. .show_host_speed = 1,
  2170. .get_host_fabric_name = lpfc_get_host_fabric_name,
  2171. .show_host_fabric_name = 1,
  2172. /*
  2173. * The LPFC driver treats linkdown handling as target loss events
  2174. * so there are no sysfs handlers for link_down_tmo.
  2175. */
  2176. .get_fc_host_stats = lpfc_get_stats,
  2177. .reset_fc_host_stats = lpfc_reset_stats,
  2178. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  2179. .show_rport_maxframe_size = 1,
  2180. .show_rport_supported_classes = 1,
  2181. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  2182. .show_rport_dev_loss_tmo = 1,
  2183. .get_starget_port_id = lpfc_get_starget_port_id,
  2184. .show_starget_port_id = 1,
  2185. .get_starget_node_name = lpfc_get_starget_node_name,
  2186. .show_starget_node_name = 1,
  2187. .get_starget_port_name = lpfc_get_starget_port_name,
  2188. .show_starget_port_name = 1,
  2189. .issue_fc_host_lip = lpfc_issue_lip,
  2190. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  2191. .terminate_rport_io = lpfc_terminate_rport_io,
  2192. .dd_fcvport_size = sizeof(struct lpfc_vport *),
  2193. };
  2194. struct fc_function_template lpfc_vport_transport_functions = {
  2195. /* fixed attributes the driver supports */
  2196. .show_host_node_name = 1,
  2197. .show_host_port_name = 1,
  2198. .show_host_supported_classes = 1,
  2199. .show_host_supported_fc4s = 1,
  2200. .show_host_supported_speeds = 1,
  2201. .show_host_maxframe_size = 1,
  2202. /* dynamic attributes the driver supports */
  2203. .get_host_port_id = lpfc_get_host_port_id,
  2204. .show_host_port_id = 1,
  2205. .get_host_port_type = lpfc_get_host_port_type,
  2206. .show_host_port_type = 1,
  2207. .get_host_port_state = lpfc_get_host_port_state,
  2208. .show_host_port_state = 1,
  2209. /* active_fc4s is shown but doesn't change (thus no get function) */
  2210. .show_host_active_fc4s = 1,
  2211. .get_host_speed = lpfc_get_host_speed,
  2212. .show_host_speed = 1,
  2213. .get_host_fabric_name = lpfc_get_host_fabric_name,
  2214. .show_host_fabric_name = 1,
  2215. /*
  2216. * The LPFC driver treats linkdown handling as target loss events
  2217. * so there are no sysfs handlers for link_down_tmo.
  2218. */
  2219. .get_fc_host_stats = lpfc_get_stats,
  2220. .reset_fc_host_stats = lpfc_reset_stats,
  2221. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  2222. .show_rport_maxframe_size = 1,
  2223. .show_rport_supported_classes = 1,
  2224. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  2225. .show_rport_dev_loss_tmo = 1,
  2226. .get_starget_port_id = lpfc_get_starget_port_id,
  2227. .show_starget_port_id = 1,
  2228. .get_starget_node_name = lpfc_get_starget_node_name,
  2229. .show_starget_node_name = 1,
  2230. .get_starget_port_name = lpfc_get_starget_port_name,
  2231. .show_starget_port_name = 1,
  2232. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  2233. .terminate_rport_io = lpfc_terminate_rport_io,
  2234. .vport_disable = lpfc_vport_disable,
  2235. };
  2236. void
  2237. lpfc_get_cfgparam(struct lpfc_hba *phba)
  2238. {
  2239. lpfc_cr_delay_init(phba, lpfc_cr_delay);
  2240. lpfc_cr_count_init(phba, lpfc_cr_count);
  2241. lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
  2242. lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
  2243. lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
  2244. lpfc_ack0_init(phba, lpfc_ack0);
  2245. lpfc_topology_init(phba, lpfc_topology);
  2246. lpfc_link_speed_init(phba, lpfc_link_speed);
  2247. lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
  2248. lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
  2249. lpfc_use_msi_init(phba, lpfc_use_msi);
  2250. lpfc_enable_hba_reset_init(phba, lpfc_enable_hba_reset);
  2251. lpfc_enable_hba_heartbeat_init(phba, lpfc_enable_hba_heartbeat);
  2252. phba->cfg_poll = lpfc_poll;
  2253. phba->cfg_soft_wwnn = 0L;
  2254. phba->cfg_soft_wwpn = 0L;
  2255. lpfc_sg_seg_cnt_init(phba, lpfc_sg_seg_cnt);
  2256. /* Also reinitialize the host templates with new values. */
  2257. lpfc_vport_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  2258. lpfc_template.sg_tablesize = phba->cfg_sg_seg_cnt;
  2259. /*
  2260. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  2261. * used to create the sg_dma_buf_pool must be dynamically calculated.
  2262. * 2 segments are added since the IOCB needs a command and response bde.
  2263. */
  2264. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  2265. sizeof(struct fcp_rsp) +
  2266. ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct ulp_bde64));
  2267. lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
  2268. return;
  2269. }
  2270. void
  2271. lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
  2272. {
  2273. lpfc_log_verbose_init(vport, lpfc_log_verbose);
  2274. lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
  2275. lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
  2276. lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
  2277. lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
  2278. lpfc_restrict_login_init(vport, lpfc_restrict_login);
  2279. lpfc_fcp_class_init(vport, lpfc_fcp_class);
  2280. lpfc_use_adisc_init(vport, lpfc_use_adisc);
  2281. lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
  2282. lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
  2283. lpfc_max_luns_init(vport, lpfc_max_luns);
  2284. lpfc_scan_down_init(vport, lpfc_scan_down);
  2285. lpfc_enable_da_id_init(vport, lpfc_enable_da_id);
  2286. return;
  2287. }