lpfc_attr.c 65 KB

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