lpfc_attr.c 55 KB

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