lpfc_attr.c 56 KB

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