lpfc_attr.c 72 KB

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