lpfc_attr.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514
  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. static void
  39. lpfc_jedec_to_ascii(int incr, char hdw[])
  40. {
  41. int i, j;
  42. for (i = 0; i < 8; i++) {
  43. j = (incr & 0xf);
  44. if (j <= 9)
  45. hdw[7 - i] = 0x30 + j;
  46. else
  47. hdw[7 - i] = 0x61 + j - 10;
  48. incr = (incr >> 4);
  49. }
  50. hdw[8] = 0;
  51. return;
  52. }
  53. static ssize_t
  54. lpfc_drvr_version_show(struct class_device *cdev, char *buf)
  55. {
  56. return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
  57. }
  58. static ssize_t
  59. management_version_show(struct class_device *cdev, char *buf)
  60. {
  61. return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\n");
  62. }
  63. static ssize_t
  64. lpfc_info_show(struct class_device *cdev, char *buf)
  65. {
  66. struct Scsi_Host *host = class_to_shost(cdev);
  67. return snprintf(buf, PAGE_SIZE, "%s\n",lpfc_info(host));
  68. }
  69. static ssize_t
  70. lpfc_serialnum_show(struct class_device *cdev, char *buf)
  71. {
  72. struct Scsi_Host *host = class_to_shost(cdev);
  73. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  74. return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
  75. }
  76. static ssize_t
  77. lpfc_modeldesc_show(struct class_device *cdev, char *buf)
  78. {
  79. struct Scsi_Host *host = class_to_shost(cdev);
  80. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  81. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
  82. }
  83. static ssize_t
  84. lpfc_modelname_show(struct class_device *cdev, char *buf)
  85. {
  86. struct Scsi_Host *host = class_to_shost(cdev);
  87. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  88. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
  89. }
  90. static ssize_t
  91. lpfc_programtype_show(struct class_device *cdev, char *buf)
  92. {
  93. struct Scsi_Host *host = class_to_shost(cdev);
  94. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  95. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
  96. }
  97. static ssize_t
  98. lpfc_portnum_show(struct class_device *cdev, char *buf)
  99. {
  100. struct Scsi_Host *host = class_to_shost(cdev);
  101. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  102. return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
  103. }
  104. static ssize_t
  105. lpfc_fwrev_show(struct class_device *cdev, char *buf)
  106. {
  107. struct Scsi_Host *host = class_to_shost(cdev);
  108. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  109. char fwrev[32];
  110. lpfc_decode_firmware_rev(phba, fwrev, 1);
  111. return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
  112. }
  113. static ssize_t
  114. lpfc_hdw_show(struct class_device *cdev, char *buf)
  115. {
  116. char hdw[9];
  117. struct Scsi_Host *host = class_to_shost(cdev);
  118. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  119. lpfc_vpd_t *vp = &phba->vpd;
  120. lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
  121. return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
  122. }
  123. static ssize_t
  124. lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
  125. {
  126. struct Scsi_Host *host = class_to_shost(cdev);
  127. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  128. return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
  129. }
  130. static ssize_t
  131. lpfc_state_show(struct class_device *cdev, char *buf)
  132. {
  133. struct Scsi_Host *host = class_to_shost(cdev);
  134. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  135. int len = 0;
  136. switch (phba->hba_state) {
  137. case LPFC_STATE_UNKNOWN:
  138. case LPFC_WARM_START:
  139. case LPFC_INIT_START:
  140. case LPFC_INIT_MBX_CMDS:
  141. case LPFC_LINK_DOWN:
  142. len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
  143. break;
  144. case LPFC_LINK_UP:
  145. case LPFC_LOCAL_CFG_LINK:
  146. len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
  147. break;
  148. case LPFC_FLOGI:
  149. case LPFC_FABRIC_CFG_LINK:
  150. case LPFC_NS_REG:
  151. case LPFC_NS_QRY:
  152. case LPFC_BUILD_DISC_LIST:
  153. case LPFC_DISC_AUTH:
  154. case LPFC_CLEAR_LA:
  155. len += snprintf(buf + len, PAGE_SIZE-len,
  156. "Link Up - Discovery\n");
  157. break;
  158. case LPFC_HBA_READY:
  159. len += snprintf(buf + len, PAGE_SIZE-len,
  160. "Link Up - Ready:\n");
  161. if (phba->fc_topology == TOPOLOGY_LOOP) {
  162. if (phba->fc_flag & FC_PUBLIC_LOOP)
  163. len += snprintf(buf + len, PAGE_SIZE-len,
  164. " Public Loop\n");
  165. else
  166. len += snprintf(buf + len, PAGE_SIZE-len,
  167. " Private Loop\n");
  168. } else {
  169. if (phba->fc_flag & FC_FABRIC)
  170. len += snprintf(buf + len, PAGE_SIZE-len,
  171. " Fabric\n");
  172. else
  173. len += snprintf(buf + len, PAGE_SIZE-len,
  174. " Point-2-Point\n");
  175. }
  176. }
  177. return len;
  178. }
  179. static ssize_t
  180. lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
  181. {
  182. struct Scsi_Host *host = class_to_shost(cdev);
  183. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  184. return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
  185. phba->fc_unmap_cnt);
  186. }
  187. static int
  188. lpfc_issue_lip(struct Scsi_Host *host)
  189. {
  190. struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata;
  191. LPFC_MBOXQ_t *pmboxq;
  192. int mbxstatus = MBXERR_ERROR;
  193. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  194. (phba->hba_state != LPFC_HBA_READY))
  195. return -EPERM;
  196. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  197. if (!pmboxq)
  198. return -ENOMEM;
  199. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  200. pmboxq->mb.mbxCommand = MBX_DOWN_LINK;
  201. pmboxq->mb.mbxOwner = OWN_HOST;
  202. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  203. if ((mbxstatus == MBX_SUCCESS) && (pmboxq->mb.mbxStatus == 0)) {
  204. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  205. lpfc_init_link(phba, pmboxq, phba->cfg_topology,
  206. phba->cfg_link_speed);
  207. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq,
  208. phba->fc_ratov * 2);
  209. }
  210. if (mbxstatus == MBX_TIMEOUT)
  211. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  212. else
  213. mempool_free(pmboxq, phba->mbox_mem_pool);
  214. if (mbxstatus == MBXERR_ERROR)
  215. return -EIO;
  216. return 0;
  217. }
  218. static int
  219. lpfc_selective_reset(struct lpfc_hba *phba)
  220. {
  221. struct completion online_compl;
  222. int status = 0;
  223. init_completion(&online_compl);
  224. lpfc_workq_post_event(phba, &status, &online_compl,
  225. LPFC_EVT_OFFLINE);
  226. wait_for_completion(&online_compl);
  227. if (status != 0)
  228. return -EIO;
  229. init_completion(&online_compl);
  230. lpfc_workq_post_event(phba, &status, &online_compl,
  231. LPFC_EVT_ONLINE);
  232. wait_for_completion(&online_compl);
  233. if (status != 0)
  234. return -EIO;
  235. return 0;
  236. }
  237. static ssize_t
  238. lpfc_issue_reset(struct class_device *cdev, const char *buf, size_t count)
  239. {
  240. struct Scsi_Host *host = class_to_shost(cdev);
  241. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  242. int status = -EINVAL;
  243. if (strncmp(buf, "selective", sizeof("selective") - 1) == 0)
  244. status = lpfc_selective_reset(phba);
  245. if (status == 0)
  246. return strlen(buf);
  247. else
  248. return status;
  249. }
  250. static ssize_t
  251. lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
  252. {
  253. struct Scsi_Host *host = class_to_shost(cdev);
  254. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  255. return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
  256. }
  257. static ssize_t
  258. lpfc_board_mode_show(struct class_device *cdev, char *buf)
  259. {
  260. struct Scsi_Host *host = class_to_shost(cdev);
  261. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  262. char * state;
  263. if (phba->hba_state == LPFC_HBA_ERROR)
  264. state = "error";
  265. else if (phba->hba_state == LPFC_WARM_START)
  266. state = "warm start";
  267. else if (phba->hba_state == LPFC_INIT_START)
  268. state = "offline";
  269. else
  270. state = "online";
  271. return snprintf(buf, PAGE_SIZE, "%s\n", state);
  272. }
  273. static ssize_t
  274. lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
  275. {
  276. struct Scsi_Host *host = class_to_shost(cdev);
  277. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  278. struct completion online_compl;
  279. int status=0;
  280. init_completion(&online_compl);
  281. if(strncmp(buf, "online", sizeof("online") - 1) == 0)
  282. lpfc_workq_post_event(phba, &status, &online_compl,
  283. LPFC_EVT_ONLINE);
  284. else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
  285. lpfc_workq_post_event(phba, &status, &online_compl,
  286. LPFC_EVT_OFFLINE);
  287. else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
  288. lpfc_workq_post_event(phba, &status, &online_compl,
  289. LPFC_EVT_WARM_START);
  290. else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
  291. lpfc_workq_post_event(phba, &status, &online_compl,
  292. LPFC_EVT_KILL);
  293. else
  294. return -EINVAL;
  295. wait_for_completion(&online_compl);
  296. if (!status)
  297. return strlen(buf);
  298. else
  299. return -EIO;
  300. }
  301. static ssize_t
  302. lpfc_poll_show(struct class_device *cdev, char *buf)
  303. {
  304. struct Scsi_Host *host = class_to_shost(cdev);
  305. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  306. return snprintf(buf, PAGE_SIZE, "%#x\n", phba->cfg_poll);
  307. }
  308. static ssize_t
  309. lpfc_poll_store(struct class_device *cdev, const char *buf,
  310. size_t count)
  311. {
  312. struct Scsi_Host *host = class_to_shost(cdev);
  313. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  314. uint32_t creg_val;
  315. uint32_t old_val;
  316. int val=0;
  317. if (!isdigit(buf[0]))
  318. return -EINVAL;
  319. if (sscanf(buf, "%i", &val) != 1)
  320. return -EINVAL;
  321. if ((val & 0x3) != val)
  322. return -EINVAL;
  323. spin_lock_irq(phba->host->host_lock);
  324. old_val = phba->cfg_poll;
  325. if (val & ENABLE_FCP_RING_POLLING) {
  326. if ((val & DISABLE_FCP_RING_INT) &&
  327. !(old_val & DISABLE_FCP_RING_INT)) {
  328. creg_val = readl(phba->HCregaddr);
  329. creg_val &= ~(HC_R0INT_ENA << LPFC_FCP_RING);
  330. writel(creg_val, phba->HCregaddr);
  331. readl(phba->HCregaddr); /* flush */
  332. lpfc_poll_start_timer(phba);
  333. }
  334. } else if (val != 0x0) {
  335. spin_unlock_irq(phba->host->host_lock);
  336. return -EINVAL;
  337. }
  338. if (!(val & DISABLE_FCP_RING_INT) &&
  339. (old_val & DISABLE_FCP_RING_INT))
  340. {
  341. spin_unlock_irq(phba->host->host_lock);
  342. del_timer(&phba->fcp_poll_timer);
  343. spin_lock_irq(phba->host->host_lock);
  344. creg_val = readl(phba->HCregaddr);
  345. creg_val |= (HC_R0INT_ENA << LPFC_FCP_RING);
  346. writel(creg_val, phba->HCregaddr);
  347. readl(phba->HCregaddr); /* flush */
  348. }
  349. phba->cfg_poll = val;
  350. spin_unlock_irq(phba->host->host_lock);
  351. return strlen(buf);
  352. }
  353. #define lpfc_param_show(attr) \
  354. static ssize_t \
  355. lpfc_##attr##_show(struct class_device *cdev, char *buf) \
  356. { \
  357. struct Scsi_Host *host = class_to_shost(cdev);\
  358. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
  359. int val = 0;\
  360. val = phba->cfg_##attr;\
  361. return snprintf(buf, PAGE_SIZE, "%d\n",\
  362. phba->cfg_##attr);\
  363. }
  364. #define lpfc_param_hex_show(attr) \
  365. static ssize_t \
  366. lpfc_##attr##_show(struct class_device *cdev, char *buf) \
  367. { \
  368. struct Scsi_Host *host = class_to_shost(cdev);\
  369. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
  370. int val = 0;\
  371. val = phba->cfg_##attr;\
  372. return snprintf(buf, PAGE_SIZE, "%#x\n",\
  373. phba->cfg_##attr);\
  374. }
  375. #define lpfc_param_init(attr, default, minval, maxval) \
  376. static int \
  377. lpfc_##attr##_init(struct lpfc_hba *phba, int val) \
  378. { \
  379. if (val >= minval && val <= maxval) {\
  380. phba->cfg_##attr = val;\
  381. return 0;\
  382. }\
  383. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  384. "%d:0449 lpfc_"#attr" attribute cannot be set to %d, "\
  385. "allowed range is ["#minval", "#maxval"]\n", \
  386. phba->brd_no, val); \
  387. phba->cfg_##attr = default;\
  388. return -EINVAL;\
  389. }
  390. #define lpfc_param_set(attr, default, minval, maxval) \
  391. static int \
  392. lpfc_##attr##_set(struct lpfc_hba *phba, int val) \
  393. { \
  394. if (val >= minval && val <= maxval) {\
  395. phba->cfg_##attr = val;\
  396. return 0;\
  397. }\
  398. lpfc_printf_log(phba, KERN_ERR, LOG_INIT, \
  399. "%d:0450 lpfc_"#attr" attribute cannot be set to %d, "\
  400. "allowed range is ["#minval", "#maxval"]\n", \
  401. phba->brd_no, val); \
  402. return -EINVAL;\
  403. }
  404. #define lpfc_param_store(attr) \
  405. static ssize_t \
  406. lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
  407. { \
  408. struct Scsi_Host *host = class_to_shost(cdev);\
  409. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;\
  410. int val=0;\
  411. if (!isdigit(buf[0]))\
  412. return -EINVAL;\
  413. if (sscanf(buf, "%i", &val) != 1)\
  414. return -EINVAL;\
  415. if (lpfc_##attr##_set(phba, val) == 0) \
  416. return strlen(buf);\
  417. else \
  418. return -EINVAL;\
  419. }
  420. #define LPFC_ATTR(name, defval, minval, maxval, desc) \
  421. static int lpfc_##name = defval;\
  422. module_param(lpfc_##name, int, 0);\
  423. MODULE_PARM_DESC(lpfc_##name, desc);\
  424. lpfc_param_init(name, defval, minval, maxval)
  425. #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
  426. static int lpfc_##name = defval;\
  427. module_param(lpfc_##name, int, 0);\
  428. MODULE_PARM_DESC(lpfc_##name, desc);\
  429. lpfc_param_show(name)\
  430. lpfc_param_init(name, defval, minval, maxval)\
  431. static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  432. #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
  433. static int lpfc_##name = defval;\
  434. module_param(lpfc_##name, int, 0);\
  435. MODULE_PARM_DESC(lpfc_##name, desc);\
  436. lpfc_param_show(name)\
  437. lpfc_param_init(name, defval, minval, maxval)\
  438. lpfc_param_set(name, defval, minval, maxval)\
  439. lpfc_param_store(name)\
  440. static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  441. lpfc_##name##_show, lpfc_##name##_store)
  442. #define LPFC_ATTR_HEX_R(name, defval, minval, maxval, desc) \
  443. static int lpfc_##name = defval;\
  444. module_param(lpfc_##name, int, 0);\
  445. MODULE_PARM_DESC(lpfc_##name, desc);\
  446. lpfc_param_hex_show(name)\
  447. lpfc_param_init(name, defval, minval, maxval)\
  448. static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  449. #define LPFC_ATTR_HEX_RW(name, defval, minval, maxval, desc) \
  450. static int lpfc_##name = defval;\
  451. module_param(lpfc_##name, int, 0);\
  452. MODULE_PARM_DESC(lpfc_##name, desc);\
  453. lpfc_param_hex_show(name)\
  454. lpfc_param_init(name, defval, minval, maxval)\
  455. lpfc_param_set(name, defval, minval, maxval)\
  456. lpfc_param_store(name)\
  457. static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  458. lpfc_##name##_show, lpfc_##name##_store)
  459. static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
  460. static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
  461. static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
  462. static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
  463. static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
  464. static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
  465. static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
  466. static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
  467. static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
  468. static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
  469. lpfc_option_rom_version_show, NULL);
  470. static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
  471. lpfc_num_discovered_ports_show, NULL);
  472. static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
  473. static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
  474. NULL);
  475. static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
  476. NULL);
  477. static CLASS_DEVICE_ATTR(board_mode, S_IRUGO | S_IWUSR,
  478. lpfc_board_mode_show, lpfc_board_mode_store);
  479. static CLASS_DEVICE_ATTR(issue_reset, S_IWUSR, NULL, lpfc_issue_reset);
  480. static int lpfc_poll = 0;
  481. module_param(lpfc_poll, int, 0);
  482. MODULE_PARM_DESC(lpfc_poll, "FCP ring polling mode control:"
  483. " 0 - none,"
  484. " 1 - poll with interrupts enabled"
  485. " 3 - poll and disable FCP ring interrupts");
  486. static CLASS_DEVICE_ATTR(lpfc_poll, S_IRUGO | S_IWUSR,
  487. lpfc_poll_show, lpfc_poll_store);
  488. /*
  489. # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
  490. # deluged with LOTS of information.
  491. # You can set a bit mask to record specific types of verbose messages:
  492. #
  493. # LOG_ELS 0x1 ELS events
  494. # LOG_DISCOVERY 0x2 Link discovery events
  495. # LOG_MBOX 0x4 Mailbox events
  496. # LOG_INIT 0x8 Initialization events
  497. # LOG_LINK_EVENT 0x10 Link events
  498. # LOG_IP 0x20 IP traffic history
  499. # LOG_FCP 0x40 FCP traffic history
  500. # LOG_NODE 0x80 Node table events
  501. # LOG_MISC 0x400 Miscellaneous events
  502. # LOG_SLI 0x800 SLI events
  503. # LOG_CHK_COND 0x1000 FCP Check condition flag
  504. # LOG_LIBDFC 0x2000 LIBDFC events
  505. # LOG_ALL_MSG 0xffff LOG all messages
  506. */
  507. LPFC_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
  508. /*
  509. # lun_queue_depth: This parameter is used to limit the number of outstanding
  510. # commands per FCP LUN. Value range is [1,128]. Default value is 30.
  511. */
  512. LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
  513. "Max number of FCP commands we can queue to a specific LUN");
  514. /*
  515. # hba_queue_depth: This parameter is used to limit the number of outstanding
  516. # commands per lpfc HBA. Value range is [32,8192]. If this parameter
  517. # value is greater than the maximum number of exchanges supported by the HBA,
  518. # then maximum number of exchanges supported by the HBA is used to determine
  519. # the hba_queue_depth.
  520. */
  521. LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
  522. "Max number of FCP commands we can queue to a lpfc HBA");
  523. /*
  524. # Some disk devices have a "select ID" or "select Target" capability.
  525. # From a protocol standpoint "select ID" usually means select the
  526. # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
  527. # annex" which contains a table that maps a "select ID" (a number
  528. # between 0 and 7F) to an ALPA. By default, for compatibility with
  529. # older drivers, the lpfc driver scans this table from low ALPA to high
  530. # ALPA.
  531. #
  532. # Turning on the scan-down variable (on = 1, off = 0) will
  533. # cause the lpfc driver to use an inverted table, effectively
  534. # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
  535. #
  536. # (Note: This "select ID" functionality is a LOOP ONLY characteristic
  537. # and will not work across a fabric. Also this parameter will take
  538. # effect only in the case when ALPA map is not available.)
  539. */
  540. LPFC_ATTR_R(scan_down, 1, 0, 1,
  541. "Start scanning for devices from highest ALPA to lowest");
  542. /*
  543. # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
  544. # until the timer expires. Value range is [0,255]. Default value is 30.
  545. # NOTE: this MUST be less then the SCSI Layer command timeout - 1.
  546. */
  547. LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
  548. "Seconds driver will hold I/O waiting for a device to come back");
  549. /*
  550. # lpfc_topology: link topology for init link
  551. # 0x0 = attempt loop mode then point-to-point
  552. # 0x01 = internal loopback mode
  553. # 0x02 = attempt point-to-point mode only
  554. # 0x04 = attempt loop mode only
  555. # 0x06 = attempt point-to-point mode then loop
  556. # Set point-to-point mode if you want to run as an N_Port.
  557. # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
  558. # Default value is 0.
  559. */
  560. LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
  561. /*
  562. # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
  563. # connection.
  564. # 0 = auto select (default)
  565. # 1 = 1 Gigabaud
  566. # 2 = 2 Gigabaud
  567. # 4 = 4 Gigabaud
  568. # Value range is [0,4]. Default value is 0.
  569. */
  570. LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
  571. /*
  572. # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
  573. # Value range is [2,3]. Default value is 3.
  574. */
  575. LPFC_ATTR_R(fcp_class, 3, 2, 3,
  576. "Select Fibre Channel class of service for FCP sequences");
  577. /*
  578. # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
  579. # is [0,1]. Default value is 0.
  580. */
  581. LPFC_ATTR_RW(use_adisc, 0, 0, 1,
  582. "Use ADISC on rediscovery to authenticate FCP devices");
  583. /*
  584. # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
  585. # range is [0,1]. Default value is 0.
  586. */
  587. LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
  588. /*
  589. # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
  590. # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
  591. # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
  592. # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
  593. # cr_delay is set to 0.
  594. */
  595. LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
  596. "interrupt response is generated");
  597. LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
  598. "interrupt response is generated");
  599. /*
  600. # lpfc_multi_ring_support: Determines how many rings to spread available
  601. # cmd/rsp IOCB entries across.
  602. # Value range is [1,2]. Default value is 1.
  603. */
  604. LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
  605. "SLI rings to spread IOCB entries across");
  606. /*
  607. # lpfc_fdmi_on: controls FDMI support.
  608. # 0 = no FDMI support
  609. # 1 = support FDMI without attribute of hostname
  610. # 2 = support FDMI with attribute of hostname
  611. # Value range [0,2]. Default value is 0.
  612. */
  613. LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
  614. /*
  615. # Specifies the maximum number of ELS cmds we can have outstanding (for
  616. # discovery). Value range is [1,64]. Default value = 32.
  617. */
  618. LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
  619. "during discovery");
  620. /*
  621. # lpfc_max_luns: maximum number of LUNs per target driver will support
  622. # Value range is [1,32768]. Default value is 256.
  623. # NOTE: The SCSI layer will scan each target for this many luns
  624. */
  625. LPFC_ATTR_R(max_luns, 256, 1, 32768,
  626. "Maximum number of LUNs per target driver will support");
  627. /*
  628. # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
  629. # Value range is [1,255], default value is 10.
  630. */
  631. LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
  632. "Milliseconds driver will wait between polling FCP ring");
  633. struct class_device_attribute *lpfc_host_attrs[] = {
  634. &class_device_attr_info,
  635. &class_device_attr_serialnum,
  636. &class_device_attr_modeldesc,
  637. &class_device_attr_modelname,
  638. &class_device_attr_programtype,
  639. &class_device_attr_portnum,
  640. &class_device_attr_fwrev,
  641. &class_device_attr_hdw,
  642. &class_device_attr_option_rom_version,
  643. &class_device_attr_state,
  644. &class_device_attr_num_discovered_ports,
  645. &class_device_attr_lpfc_drvr_version,
  646. &class_device_attr_lpfc_log_verbose,
  647. &class_device_attr_lpfc_lun_queue_depth,
  648. &class_device_attr_lpfc_hba_queue_depth,
  649. &class_device_attr_lpfc_nodev_tmo,
  650. &class_device_attr_lpfc_fcp_class,
  651. &class_device_attr_lpfc_use_adisc,
  652. &class_device_attr_lpfc_ack0,
  653. &class_device_attr_lpfc_topology,
  654. &class_device_attr_lpfc_scan_down,
  655. &class_device_attr_lpfc_link_speed,
  656. &class_device_attr_lpfc_cr_delay,
  657. &class_device_attr_lpfc_cr_count,
  658. &class_device_attr_lpfc_multi_ring_support,
  659. &class_device_attr_lpfc_fdmi_on,
  660. &class_device_attr_lpfc_max_luns,
  661. &class_device_attr_nport_evt_cnt,
  662. &class_device_attr_management_version,
  663. &class_device_attr_board_mode,
  664. &class_device_attr_issue_reset,
  665. &class_device_attr_lpfc_poll,
  666. &class_device_attr_lpfc_poll_tmo,
  667. NULL,
  668. };
  669. static ssize_t
  670. sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
  671. {
  672. size_t buf_off;
  673. struct Scsi_Host *host = class_to_shost(container_of(kobj,
  674. struct class_device, kobj));
  675. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  676. if ((off + count) > FF_REG_AREA_SIZE)
  677. return -ERANGE;
  678. if (count == 0) return 0;
  679. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  680. return -EINVAL;
  681. spin_lock_irq(phba->host->host_lock);
  682. if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
  683. spin_unlock_irq(phba->host->host_lock);
  684. return -EPERM;
  685. }
  686. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
  687. writel(*((uint32_t *)(buf + buf_off)),
  688. phba->ctrl_regs_memmap_p + off + buf_off);
  689. spin_unlock_irq(phba->host->host_lock);
  690. return count;
  691. }
  692. static ssize_t
  693. sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  694. {
  695. size_t buf_off;
  696. uint32_t * tmp_ptr;
  697. struct Scsi_Host *host = class_to_shost(container_of(kobj,
  698. struct class_device, kobj));
  699. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  700. if (off > FF_REG_AREA_SIZE)
  701. return -ERANGE;
  702. if ((off + count) > FF_REG_AREA_SIZE)
  703. count = FF_REG_AREA_SIZE - off;
  704. if (count == 0) return 0;
  705. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  706. return -EINVAL;
  707. spin_lock_irq(phba->host->host_lock);
  708. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
  709. tmp_ptr = (uint32_t *)(buf + buf_off);
  710. *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
  711. }
  712. spin_unlock_irq(phba->host->host_lock);
  713. return count;
  714. }
  715. static struct bin_attribute sysfs_ctlreg_attr = {
  716. .attr = {
  717. .name = "ctlreg",
  718. .mode = S_IRUSR | S_IWUSR,
  719. .owner = THIS_MODULE,
  720. },
  721. .size = 256,
  722. .read = sysfs_ctlreg_read,
  723. .write = sysfs_ctlreg_write,
  724. };
  725. static void
  726. sysfs_mbox_idle (struct lpfc_hba * phba)
  727. {
  728. phba->sysfs_mbox.state = SMBOX_IDLE;
  729. phba->sysfs_mbox.offset = 0;
  730. if (phba->sysfs_mbox.mbox) {
  731. mempool_free(phba->sysfs_mbox.mbox,
  732. phba->mbox_mem_pool);
  733. phba->sysfs_mbox.mbox = NULL;
  734. }
  735. }
  736. static ssize_t
  737. sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
  738. {
  739. struct Scsi_Host * host =
  740. class_to_shost(container_of(kobj, struct class_device, kobj));
  741. struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata;
  742. struct lpfcMboxq * mbox = NULL;
  743. if ((count + off) > MAILBOX_CMD_SIZE)
  744. return -ERANGE;
  745. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  746. return -EINVAL;
  747. if (count == 0)
  748. return 0;
  749. if (off == 0) {
  750. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  751. if (!mbox)
  752. return -ENOMEM;
  753. memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
  754. }
  755. spin_lock_irq(host->host_lock);
  756. if (off == 0) {
  757. if (phba->sysfs_mbox.mbox)
  758. mempool_free(mbox, phba->mbox_mem_pool);
  759. else
  760. phba->sysfs_mbox.mbox = mbox;
  761. phba->sysfs_mbox.state = SMBOX_WRITING;
  762. } else {
  763. if (phba->sysfs_mbox.state != SMBOX_WRITING ||
  764. phba->sysfs_mbox.offset != off ||
  765. phba->sysfs_mbox.mbox == NULL ) {
  766. sysfs_mbox_idle(phba);
  767. spin_unlock_irq(host->host_lock);
  768. return -EINVAL;
  769. }
  770. }
  771. memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
  772. buf, count);
  773. phba->sysfs_mbox.offset = off + count;
  774. spin_unlock_irq(host->host_lock);
  775. return count;
  776. }
  777. static ssize_t
  778. sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  779. {
  780. struct Scsi_Host *host =
  781. class_to_shost(container_of(kobj, struct class_device,
  782. kobj));
  783. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  784. int rc;
  785. if (off > sizeof(MAILBOX_t))
  786. return -ERANGE;
  787. if ((count + off) > sizeof(MAILBOX_t))
  788. count = sizeof(MAILBOX_t) - off;
  789. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  790. return -EINVAL;
  791. if (off && count == 0)
  792. return 0;
  793. spin_lock_irq(phba->host->host_lock);
  794. if (off == 0 &&
  795. phba->sysfs_mbox.state == SMBOX_WRITING &&
  796. phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
  797. switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
  798. /* Offline only */
  799. case MBX_WRITE_NV:
  800. case MBX_INIT_LINK:
  801. case MBX_DOWN_LINK:
  802. case MBX_CONFIG_LINK:
  803. case MBX_CONFIG_RING:
  804. case MBX_RESET_RING:
  805. case MBX_UNREG_LOGIN:
  806. case MBX_CLEAR_LA:
  807. case MBX_DUMP_CONTEXT:
  808. case MBX_RUN_DIAGS:
  809. case MBX_RESTART:
  810. case MBX_FLASH_WR_ULA:
  811. case MBX_SET_MASK:
  812. case MBX_SET_SLIM:
  813. case MBX_SET_DEBUG:
  814. if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
  815. printk(KERN_WARNING "mbox_read:Command 0x%x "
  816. "is illegal in on-line state\n",
  817. phba->sysfs_mbox.mbox->mb.mbxCommand);
  818. sysfs_mbox_idle(phba);
  819. spin_unlock_irq(phba->host->host_lock);
  820. return -EPERM;
  821. }
  822. case MBX_LOAD_SM:
  823. case MBX_READ_NV:
  824. case MBX_READ_CONFIG:
  825. case MBX_READ_RCONFIG:
  826. case MBX_READ_STATUS:
  827. case MBX_READ_XRI:
  828. case MBX_READ_REV:
  829. case MBX_READ_LNK_STAT:
  830. case MBX_DUMP_MEMORY:
  831. case MBX_DOWN_LOAD:
  832. case MBX_UPDATE_CFG:
  833. case MBX_KILL_BOARD:
  834. case MBX_LOAD_AREA:
  835. case MBX_LOAD_EXP_ROM:
  836. case MBX_BEACON:
  837. case MBX_DEL_LD_ENTRY:
  838. break;
  839. case MBX_READ_SPARM64:
  840. case MBX_READ_LA:
  841. case MBX_READ_LA64:
  842. case MBX_REG_LOGIN:
  843. case MBX_REG_LOGIN64:
  844. case MBX_CONFIG_PORT:
  845. case MBX_RUN_BIU_DIAG:
  846. printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
  847. phba->sysfs_mbox.mbox->mb.mbxCommand);
  848. sysfs_mbox_idle(phba);
  849. spin_unlock_irq(phba->host->host_lock);
  850. return -EPERM;
  851. default:
  852. printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
  853. phba->sysfs_mbox.mbox->mb.mbxCommand);
  854. sysfs_mbox_idle(phba);
  855. spin_unlock_irq(phba->host->host_lock);
  856. return -EPERM;
  857. }
  858. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  859. (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
  860. spin_unlock_irq(phba->host->host_lock);
  861. rc = lpfc_sli_issue_mbox (phba,
  862. phba->sysfs_mbox.mbox,
  863. MBX_POLL);
  864. spin_lock_irq(phba->host->host_lock);
  865. } else {
  866. spin_unlock_irq(phba->host->host_lock);
  867. rc = lpfc_sli_issue_mbox_wait (phba,
  868. phba->sysfs_mbox.mbox,
  869. phba->fc_ratov * 2);
  870. spin_lock_irq(phba->host->host_lock);
  871. }
  872. if (rc != MBX_SUCCESS) {
  873. sysfs_mbox_idle(phba);
  874. spin_unlock_irq(host->host_lock);
  875. return -ENODEV;
  876. }
  877. phba->sysfs_mbox.state = SMBOX_READING;
  878. }
  879. else if (phba->sysfs_mbox.offset != off ||
  880. phba->sysfs_mbox.state != SMBOX_READING) {
  881. printk(KERN_WARNING "mbox_read: Bad State\n");
  882. sysfs_mbox_idle(phba);
  883. spin_unlock_irq(host->host_lock);
  884. return -EINVAL;
  885. }
  886. memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
  887. phba->sysfs_mbox.offset = off + count;
  888. if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
  889. sysfs_mbox_idle(phba);
  890. spin_unlock_irq(phba->host->host_lock);
  891. return count;
  892. }
  893. static struct bin_attribute sysfs_mbox_attr = {
  894. .attr = {
  895. .name = "mbox",
  896. .mode = S_IRUSR | S_IWUSR,
  897. .owner = THIS_MODULE,
  898. },
  899. .size = sizeof(MAILBOX_t),
  900. .read = sysfs_mbox_read,
  901. .write = sysfs_mbox_write,
  902. };
  903. int
  904. lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
  905. {
  906. struct Scsi_Host *host = phba->host;
  907. int error;
  908. error = sysfs_create_bin_file(&host->shost_classdev.kobj,
  909. &sysfs_ctlreg_attr);
  910. if (error)
  911. goto out;
  912. error = sysfs_create_bin_file(&host->shost_classdev.kobj,
  913. &sysfs_mbox_attr);
  914. if (error)
  915. goto out_remove_ctlreg_attr;
  916. return 0;
  917. out_remove_ctlreg_attr:
  918. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
  919. out:
  920. return error;
  921. }
  922. void
  923. lpfc_free_sysfs_attr(struct lpfc_hba *phba)
  924. {
  925. struct Scsi_Host *host = phba->host;
  926. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
  927. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
  928. }
  929. /*
  930. * Dynamic FC Host Attributes Support
  931. */
  932. static void
  933. lpfc_get_host_port_id(struct Scsi_Host *shost)
  934. {
  935. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  936. /* note: fc_myDID already in cpu endianness */
  937. fc_host_port_id(shost) = phba->fc_myDID;
  938. }
  939. static void
  940. lpfc_get_host_port_type(struct Scsi_Host *shost)
  941. {
  942. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  943. spin_lock_irq(shost->host_lock);
  944. if (phba->hba_state == LPFC_HBA_READY) {
  945. if (phba->fc_topology == TOPOLOGY_LOOP) {
  946. if (phba->fc_flag & FC_PUBLIC_LOOP)
  947. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  948. else
  949. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  950. } else {
  951. if (phba->fc_flag & FC_FABRIC)
  952. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  953. else
  954. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  955. }
  956. } else
  957. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  958. spin_unlock_irq(shost->host_lock);
  959. }
  960. static void
  961. lpfc_get_host_port_state(struct Scsi_Host *shost)
  962. {
  963. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  964. spin_lock_irq(shost->host_lock);
  965. if (phba->fc_flag & FC_OFFLINE_MODE)
  966. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  967. else {
  968. switch (phba->hba_state) {
  969. case LPFC_STATE_UNKNOWN:
  970. case LPFC_WARM_START:
  971. case LPFC_INIT_START:
  972. case LPFC_INIT_MBX_CMDS:
  973. case LPFC_LINK_DOWN:
  974. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  975. break;
  976. case LPFC_LINK_UP:
  977. case LPFC_LOCAL_CFG_LINK:
  978. case LPFC_FLOGI:
  979. case LPFC_FABRIC_CFG_LINK:
  980. case LPFC_NS_REG:
  981. case LPFC_NS_QRY:
  982. case LPFC_BUILD_DISC_LIST:
  983. case LPFC_DISC_AUTH:
  984. case LPFC_CLEAR_LA:
  985. case LPFC_HBA_READY:
  986. /* Links up, beyond this port_type reports state */
  987. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  988. break;
  989. case LPFC_HBA_ERROR:
  990. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  991. break;
  992. default:
  993. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  994. break;
  995. }
  996. }
  997. spin_unlock_irq(shost->host_lock);
  998. }
  999. static void
  1000. lpfc_get_host_speed(struct Scsi_Host *shost)
  1001. {
  1002. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  1003. spin_lock_irq(shost->host_lock);
  1004. if (phba->hba_state == LPFC_HBA_READY) {
  1005. switch(phba->fc_linkspeed) {
  1006. case LA_1GHZ_LINK:
  1007. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  1008. break;
  1009. case LA_2GHZ_LINK:
  1010. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  1011. break;
  1012. case LA_4GHZ_LINK:
  1013. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  1014. break;
  1015. default:
  1016. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1017. break;
  1018. }
  1019. }
  1020. spin_unlock_irq(shost->host_lock);
  1021. }
  1022. static void
  1023. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  1024. {
  1025. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  1026. u64 node_name;
  1027. spin_lock_irq(shost->host_lock);
  1028. if ((phba->fc_flag & FC_FABRIC) ||
  1029. ((phba->fc_topology == TOPOLOGY_LOOP) &&
  1030. (phba->fc_flag & FC_PUBLIC_LOOP)))
  1031. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  1032. else
  1033. /* fabric is local port if there is no F/FL_Port */
  1034. node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
  1035. spin_unlock_irq(shost->host_lock);
  1036. fc_host_fabric_name(shost) = node_name;
  1037. }
  1038. static struct fc_host_statistics *
  1039. lpfc_get_stats(struct Scsi_Host *shost)
  1040. {
  1041. struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
  1042. struct lpfc_sli *psli = &phba->sli;
  1043. struct fc_host_statistics *hs = &phba->link_stats;
  1044. LPFC_MBOXQ_t *pmboxq;
  1045. MAILBOX_t *pmb;
  1046. int rc = 0;
  1047. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1048. if (!pmboxq)
  1049. return NULL;
  1050. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1051. pmb = &pmboxq->mb;
  1052. pmb->mbxCommand = MBX_READ_STATUS;
  1053. pmb->mbxOwner = OWN_HOST;
  1054. pmboxq->context1 = NULL;
  1055. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  1056. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1057. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1058. else
  1059. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1060. if (rc != MBX_SUCCESS) {
  1061. if (rc == MBX_TIMEOUT)
  1062. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1063. else
  1064. mempool_free(pmboxq, phba->mbox_mem_pool);
  1065. return NULL;
  1066. }
  1067. memset(hs, 0, sizeof (struct fc_host_statistics));
  1068. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  1069. hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
  1070. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  1071. hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
  1072. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1073. pmb->mbxCommand = MBX_READ_LNK_STAT;
  1074. pmb->mbxOwner = OWN_HOST;
  1075. pmboxq->context1 = NULL;
  1076. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  1077. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1078. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1079. else
  1080. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1081. if (rc != MBX_SUCCESS) {
  1082. if (rc == MBX_TIMEOUT)
  1083. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1084. else
  1085. mempool_free( pmboxq, phba->mbox_mem_pool);
  1086. return NULL;
  1087. }
  1088. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  1089. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  1090. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  1091. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  1092. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  1093. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  1094. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  1095. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1096. hs->lip_count = (phba->fc_eventTag >> 1);
  1097. hs->nos_count = -1;
  1098. } else {
  1099. hs->lip_count = -1;
  1100. hs->nos_count = (phba->fc_eventTag >> 1);
  1101. }
  1102. hs->dumped_frames = -1;
  1103. /* FIX ME */
  1104. /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
  1105. return hs;
  1106. }
  1107. /*
  1108. * The LPFC driver treats linkdown handling as target loss events so there
  1109. * are no sysfs handlers for link_down_tmo.
  1110. */
  1111. static void
  1112. lpfc_get_starget_port_id(struct scsi_target *starget)
  1113. {
  1114. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1115. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
  1116. uint32_t did = -1;
  1117. struct lpfc_nodelist *ndlp = NULL;
  1118. spin_lock_irq(shost->host_lock);
  1119. /* Search the mapped list for this target ID */
  1120. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1121. if (starget->id == ndlp->nlp_sid) {
  1122. did = ndlp->nlp_DID;
  1123. break;
  1124. }
  1125. }
  1126. spin_unlock_irq(shost->host_lock);
  1127. fc_starget_port_id(starget) = did;
  1128. }
  1129. static void
  1130. lpfc_get_starget_node_name(struct scsi_target *starget)
  1131. {
  1132. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1133. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
  1134. u64 node_name = 0;
  1135. struct lpfc_nodelist *ndlp = NULL;
  1136. spin_lock_irq(shost->host_lock);
  1137. /* Search the mapped list for this target ID */
  1138. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1139. if (starget->id == ndlp->nlp_sid) {
  1140. node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  1141. break;
  1142. }
  1143. }
  1144. spin_unlock_irq(shost->host_lock);
  1145. fc_starget_node_name(starget) = node_name;
  1146. }
  1147. static void
  1148. lpfc_get_starget_port_name(struct scsi_target *starget)
  1149. {
  1150. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1151. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
  1152. u64 port_name = 0;
  1153. struct lpfc_nodelist *ndlp = NULL;
  1154. spin_lock_irq(shost->host_lock);
  1155. /* Search the mapped list for this target ID */
  1156. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1157. if (starget->id == ndlp->nlp_sid) {
  1158. port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  1159. break;
  1160. }
  1161. }
  1162. spin_unlock_irq(shost->host_lock);
  1163. fc_starget_port_name(starget) = port_name;
  1164. }
  1165. static void
  1166. lpfc_get_rport_loss_tmo(struct fc_rport *rport)
  1167. {
  1168. /*
  1169. * Return the driver's global value for device loss timeout plus
  1170. * five seconds to allow the driver's nodev timer to run.
  1171. */
  1172. rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
  1173. }
  1174. static void
  1175. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1176. {
  1177. /*
  1178. * The driver doesn't have a per-target timeout setting. Set
  1179. * this value globally. lpfc_nodev_tmo should be greater then 0.
  1180. */
  1181. if (timeout)
  1182. lpfc_nodev_tmo = timeout;
  1183. else
  1184. lpfc_nodev_tmo = 1;
  1185. rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
  1186. }
  1187. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  1188. static ssize_t \
  1189. lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
  1190. { \
  1191. struct fc_rport *rport = transport_class_to_rport(cdev); \
  1192. struct lpfc_rport_data *rdata = rport->hostdata; \
  1193. return snprintf(buf, sz, format_string, \
  1194. (rdata->target) ? cast rdata->target->field : 0); \
  1195. }
  1196. #define lpfc_rport_rd_attr(field, format_string, sz) \
  1197. lpfc_rport_show_function(field, format_string, sz, ) \
  1198. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  1199. struct fc_function_template lpfc_transport_functions = {
  1200. /* fixed attributes the driver supports */
  1201. .show_host_node_name = 1,
  1202. .show_host_port_name = 1,
  1203. .show_host_supported_classes = 1,
  1204. .show_host_supported_fc4s = 1,
  1205. .show_host_symbolic_name = 1,
  1206. .show_host_supported_speeds = 1,
  1207. .show_host_maxframe_size = 1,
  1208. /* dynamic attributes the driver supports */
  1209. .get_host_port_id = lpfc_get_host_port_id,
  1210. .show_host_port_id = 1,
  1211. .get_host_port_type = lpfc_get_host_port_type,
  1212. .show_host_port_type = 1,
  1213. .get_host_port_state = lpfc_get_host_port_state,
  1214. .show_host_port_state = 1,
  1215. /* active_fc4s is shown but doesn't change (thus no get function) */
  1216. .show_host_active_fc4s = 1,
  1217. .get_host_speed = lpfc_get_host_speed,
  1218. .show_host_speed = 1,
  1219. .get_host_fabric_name = lpfc_get_host_fabric_name,
  1220. .show_host_fabric_name = 1,
  1221. /*
  1222. * The LPFC driver treats linkdown handling as target loss events
  1223. * so there are no sysfs handlers for link_down_tmo.
  1224. */
  1225. .get_fc_host_stats = lpfc_get_stats,
  1226. /* the LPFC driver doesn't support resetting stats yet */
  1227. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  1228. .show_rport_maxframe_size = 1,
  1229. .show_rport_supported_classes = 1,
  1230. .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
  1231. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  1232. .show_rport_dev_loss_tmo = 1,
  1233. .get_starget_port_id = lpfc_get_starget_port_id,
  1234. .show_starget_port_id = 1,
  1235. .get_starget_node_name = lpfc_get_starget_node_name,
  1236. .show_starget_node_name = 1,
  1237. .get_starget_port_name = lpfc_get_starget_port_name,
  1238. .show_starget_port_name = 1,
  1239. .issue_fc_host_lip = lpfc_issue_lip,
  1240. };
  1241. void
  1242. lpfc_get_cfgparam(struct lpfc_hba *phba)
  1243. {
  1244. lpfc_log_verbose_init(phba, lpfc_log_verbose);
  1245. lpfc_cr_delay_init(phba, lpfc_cr_delay);
  1246. lpfc_cr_count_init(phba, lpfc_cr_count);
  1247. lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
  1248. lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
  1249. lpfc_fcp_class_init(phba, lpfc_fcp_class);
  1250. lpfc_use_adisc_init(phba, lpfc_use_adisc);
  1251. lpfc_ack0_init(phba, lpfc_ack0);
  1252. lpfc_topology_init(phba, lpfc_topology);
  1253. lpfc_scan_down_init(phba, lpfc_scan_down);
  1254. lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
  1255. lpfc_link_speed_init(phba, lpfc_link_speed);
  1256. lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
  1257. lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
  1258. lpfc_max_luns_init(phba, lpfc_max_luns);
  1259. lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
  1260. phba->cfg_poll = lpfc_poll;
  1261. /*
  1262. * The total number of segments is the configuration value plus 2
  1263. * since the IOCB need a command and response bde.
  1264. */
  1265. phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
  1266. /*
  1267. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  1268. * used to create the sg_dma_buf_pool must be dynamically calculated
  1269. */
  1270. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  1271. sizeof(struct fcp_rsp) +
  1272. (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
  1273. switch (phba->pcidev->device) {
  1274. case PCI_DEVICE_ID_LP101:
  1275. case PCI_DEVICE_ID_BSMB:
  1276. case PCI_DEVICE_ID_ZSMB:
  1277. phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
  1278. break;
  1279. case PCI_DEVICE_ID_RFLY:
  1280. case PCI_DEVICE_ID_PFLY:
  1281. case PCI_DEVICE_ID_BMID:
  1282. case PCI_DEVICE_ID_ZMID:
  1283. case PCI_DEVICE_ID_TFLY:
  1284. phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
  1285. break;
  1286. default:
  1287. phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
  1288. }
  1289. if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
  1290. lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
  1291. return;
  1292. }