lpfc_attr.c 55 KB

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