lpfc_attr.c 43 KB

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