lpfc_attr.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597
  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, LPFC_MBOX_TMO * 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 allowed LUN.
  622. # Value range is [0,65535]. Default value is 255.
  623. # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
  624. */
  625. LPFC_ATTR_R(max_luns, 255, 0, 65535,
  626. "Maximum allowed LUN");
  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 -EAGAIN;
  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. lpfc_mbox_tmo_val(phba,
  870. phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
  871. spin_lock_irq(phba->host->host_lock);
  872. }
  873. if (rc != MBX_SUCCESS) {
  874. sysfs_mbox_idle(phba);
  875. spin_unlock_irq(host->host_lock);
  876. return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
  877. }
  878. phba->sysfs_mbox.state = SMBOX_READING;
  879. }
  880. else if (phba->sysfs_mbox.offset != off ||
  881. phba->sysfs_mbox.state != SMBOX_READING) {
  882. printk(KERN_WARNING "mbox_read: Bad State\n");
  883. sysfs_mbox_idle(phba);
  884. spin_unlock_irq(host->host_lock);
  885. return -EAGAIN;
  886. }
  887. memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
  888. phba->sysfs_mbox.offset = off + count;
  889. if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
  890. sysfs_mbox_idle(phba);
  891. spin_unlock_irq(phba->host->host_lock);
  892. return count;
  893. }
  894. static struct bin_attribute sysfs_mbox_attr = {
  895. .attr = {
  896. .name = "mbox",
  897. .mode = S_IRUSR | S_IWUSR,
  898. .owner = THIS_MODULE,
  899. },
  900. .size = sizeof(MAILBOX_t),
  901. .read = sysfs_mbox_read,
  902. .write = sysfs_mbox_write,
  903. };
  904. int
  905. lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
  906. {
  907. struct Scsi_Host *host = phba->host;
  908. int error;
  909. error = sysfs_create_bin_file(&host->shost_classdev.kobj,
  910. &sysfs_ctlreg_attr);
  911. if (error)
  912. goto out;
  913. error = sysfs_create_bin_file(&host->shost_classdev.kobj,
  914. &sysfs_mbox_attr);
  915. if (error)
  916. goto out_remove_ctlreg_attr;
  917. return 0;
  918. out_remove_ctlreg_attr:
  919. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
  920. out:
  921. return error;
  922. }
  923. void
  924. lpfc_free_sysfs_attr(struct lpfc_hba *phba)
  925. {
  926. struct Scsi_Host *host = phba->host;
  927. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
  928. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
  929. }
  930. /*
  931. * Dynamic FC Host Attributes Support
  932. */
  933. static void
  934. lpfc_get_host_port_id(struct Scsi_Host *shost)
  935. {
  936. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  937. /* note: fc_myDID already in cpu endianness */
  938. fc_host_port_id(shost) = phba->fc_myDID;
  939. }
  940. static void
  941. lpfc_get_host_port_type(struct Scsi_Host *shost)
  942. {
  943. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  944. spin_lock_irq(shost->host_lock);
  945. if (phba->hba_state == LPFC_HBA_READY) {
  946. if (phba->fc_topology == TOPOLOGY_LOOP) {
  947. if (phba->fc_flag & FC_PUBLIC_LOOP)
  948. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  949. else
  950. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  951. } else {
  952. if (phba->fc_flag & FC_FABRIC)
  953. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  954. else
  955. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  956. }
  957. } else
  958. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  959. spin_unlock_irq(shost->host_lock);
  960. }
  961. static void
  962. lpfc_get_host_port_state(struct Scsi_Host *shost)
  963. {
  964. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  965. spin_lock_irq(shost->host_lock);
  966. if (phba->fc_flag & FC_OFFLINE_MODE)
  967. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  968. else {
  969. switch (phba->hba_state) {
  970. case LPFC_STATE_UNKNOWN:
  971. case LPFC_WARM_START:
  972. case LPFC_INIT_START:
  973. case LPFC_INIT_MBX_CMDS:
  974. case LPFC_LINK_DOWN:
  975. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  976. break;
  977. case LPFC_LINK_UP:
  978. case LPFC_LOCAL_CFG_LINK:
  979. case LPFC_FLOGI:
  980. case LPFC_FABRIC_CFG_LINK:
  981. case LPFC_NS_REG:
  982. case LPFC_NS_QRY:
  983. case LPFC_BUILD_DISC_LIST:
  984. case LPFC_DISC_AUTH:
  985. case LPFC_CLEAR_LA:
  986. case LPFC_HBA_READY:
  987. /* Links up, beyond this port_type reports state */
  988. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  989. break;
  990. case LPFC_HBA_ERROR:
  991. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  992. break;
  993. default:
  994. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  995. break;
  996. }
  997. }
  998. spin_unlock_irq(shost->host_lock);
  999. }
  1000. static void
  1001. lpfc_get_host_speed(struct Scsi_Host *shost)
  1002. {
  1003. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  1004. spin_lock_irq(shost->host_lock);
  1005. if (phba->hba_state == LPFC_HBA_READY) {
  1006. switch(phba->fc_linkspeed) {
  1007. case LA_1GHZ_LINK:
  1008. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  1009. break;
  1010. case LA_2GHZ_LINK:
  1011. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  1012. break;
  1013. case LA_4GHZ_LINK:
  1014. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  1015. break;
  1016. default:
  1017. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1018. break;
  1019. }
  1020. }
  1021. spin_unlock_irq(shost->host_lock);
  1022. }
  1023. static void
  1024. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  1025. {
  1026. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata;
  1027. u64 node_name;
  1028. spin_lock_irq(shost->host_lock);
  1029. if ((phba->fc_flag & FC_FABRIC) ||
  1030. ((phba->fc_topology == TOPOLOGY_LOOP) &&
  1031. (phba->fc_flag & FC_PUBLIC_LOOP)))
  1032. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  1033. else
  1034. /* fabric is local port if there is no F/FL_Port */
  1035. node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
  1036. spin_unlock_irq(shost->host_lock);
  1037. fc_host_fabric_name(shost) = node_name;
  1038. }
  1039. static struct fc_host_statistics *
  1040. lpfc_get_stats(struct Scsi_Host *shost)
  1041. {
  1042. struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
  1043. struct lpfc_sli *psli = &phba->sli;
  1044. struct fc_host_statistics *hs = &phba->link_stats;
  1045. struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
  1046. LPFC_MBOXQ_t *pmboxq;
  1047. MAILBOX_t *pmb;
  1048. unsigned long seconds;
  1049. int rc = 0;
  1050. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1051. if (!pmboxq)
  1052. return NULL;
  1053. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1054. pmb = &pmboxq->mb;
  1055. pmb->mbxCommand = MBX_READ_STATUS;
  1056. pmb->mbxOwner = OWN_HOST;
  1057. pmboxq->context1 = NULL;
  1058. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  1059. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1060. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1061. else
  1062. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1063. if (rc != MBX_SUCCESS) {
  1064. if (rc == MBX_TIMEOUT)
  1065. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1066. else
  1067. mempool_free(pmboxq, phba->mbox_mem_pool);
  1068. return NULL;
  1069. }
  1070. memset(hs, 0, sizeof (struct fc_host_statistics));
  1071. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  1072. hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
  1073. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  1074. hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
  1075. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1076. pmb->mbxCommand = MBX_READ_LNK_STAT;
  1077. pmb->mbxOwner = OWN_HOST;
  1078. pmboxq->context1 = NULL;
  1079. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  1080. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1081. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1082. else
  1083. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1084. if (rc != MBX_SUCCESS) {
  1085. if (rc == MBX_TIMEOUT)
  1086. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1087. else
  1088. mempool_free( pmboxq, phba->mbox_mem_pool);
  1089. return NULL;
  1090. }
  1091. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  1092. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  1093. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  1094. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  1095. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  1096. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  1097. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  1098. hs->link_failure_count -= lso->link_failure_count;
  1099. hs->loss_of_sync_count -= lso->loss_of_sync_count;
  1100. hs->loss_of_signal_count -= lso->loss_of_signal_count;
  1101. hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
  1102. hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
  1103. hs->invalid_crc_count -= lso->invalid_crc_count;
  1104. hs->error_frames -= lso->error_frames;
  1105. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1106. hs->lip_count = (phba->fc_eventTag >> 1);
  1107. hs->lip_count -= lso->link_events;
  1108. hs->nos_count = -1;
  1109. } else {
  1110. hs->lip_count = -1;
  1111. hs->nos_count = (phba->fc_eventTag >> 1);
  1112. hs->nos_count -= lso->link_events;
  1113. }
  1114. hs->dumped_frames = -1;
  1115. seconds = get_seconds();
  1116. if (seconds < psli->stats_start)
  1117. hs->seconds_since_last_reset = seconds +
  1118. ((unsigned long)-1 - psli->stats_start);
  1119. else
  1120. hs->seconds_since_last_reset = seconds - psli->stats_start;
  1121. return hs;
  1122. }
  1123. static void
  1124. lpfc_reset_stats(struct Scsi_Host *shost)
  1125. {
  1126. struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
  1127. struct lpfc_sli *psli = &phba->sli;
  1128. struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
  1129. LPFC_MBOXQ_t *pmboxq;
  1130. MAILBOX_t *pmb;
  1131. int rc = 0;
  1132. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1133. if (!pmboxq)
  1134. return;
  1135. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  1136. pmb = &pmboxq->mb;
  1137. pmb->mbxCommand = MBX_READ_STATUS;
  1138. pmb->mbxOwner = OWN_HOST;
  1139. pmb->un.varWords[0] = 0x1; /* reset request */
  1140. pmboxq->context1 = NULL;
  1141. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  1142. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1143. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1144. else
  1145. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1146. if (rc != MBX_SUCCESS) {
  1147. if (rc == MBX_TIMEOUT)
  1148. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1149. else
  1150. mempool_free(pmboxq, phba->mbox_mem_pool);
  1151. return;
  1152. }
  1153. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  1154. pmb->mbxCommand = MBX_READ_LNK_STAT;
  1155. pmb->mbxOwner = OWN_HOST;
  1156. pmboxq->context1 = NULL;
  1157. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  1158. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1159. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1160. else
  1161. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1162. if (rc != MBX_SUCCESS) {
  1163. if (rc == MBX_TIMEOUT)
  1164. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1165. else
  1166. mempool_free( pmboxq, phba->mbox_mem_pool);
  1167. return;
  1168. }
  1169. lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  1170. lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  1171. lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  1172. lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  1173. lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  1174. lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  1175. lso->error_frames = pmb->un.varRdLnk.crcCnt;
  1176. lso->link_events = (phba->fc_eventTag >> 1);
  1177. psli->stats_start = get_seconds();
  1178. return;
  1179. }
  1180. /*
  1181. * The LPFC driver treats linkdown handling as target loss events so there
  1182. * are no sysfs handlers for link_down_tmo.
  1183. */
  1184. static void
  1185. lpfc_get_starget_port_id(struct scsi_target *starget)
  1186. {
  1187. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1188. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
  1189. uint32_t did = -1;
  1190. struct lpfc_nodelist *ndlp = NULL;
  1191. spin_lock_irq(shost->host_lock);
  1192. /* Search the mapped list for this target ID */
  1193. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1194. if (starget->id == ndlp->nlp_sid) {
  1195. did = ndlp->nlp_DID;
  1196. break;
  1197. }
  1198. }
  1199. spin_unlock_irq(shost->host_lock);
  1200. fc_starget_port_id(starget) = did;
  1201. }
  1202. static void
  1203. lpfc_get_starget_node_name(struct scsi_target *starget)
  1204. {
  1205. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1206. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
  1207. u64 node_name = 0;
  1208. struct lpfc_nodelist *ndlp = NULL;
  1209. spin_lock_irq(shost->host_lock);
  1210. /* Search the mapped list for this target ID */
  1211. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1212. if (starget->id == ndlp->nlp_sid) {
  1213. node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  1214. break;
  1215. }
  1216. }
  1217. spin_unlock_irq(shost->host_lock);
  1218. fc_starget_node_name(starget) = node_name;
  1219. }
  1220. static void
  1221. lpfc_get_starget_port_name(struct scsi_target *starget)
  1222. {
  1223. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1224. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
  1225. u64 port_name = 0;
  1226. struct lpfc_nodelist *ndlp = NULL;
  1227. spin_lock_irq(shost->host_lock);
  1228. /* Search the mapped list for this target ID */
  1229. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1230. if (starget->id == ndlp->nlp_sid) {
  1231. port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  1232. break;
  1233. }
  1234. }
  1235. spin_unlock_irq(shost->host_lock);
  1236. fc_starget_port_name(starget) = port_name;
  1237. }
  1238. static void
  1239. lpfc_get_rport_loss_tmo(struct fc_rport *rport)
  1240. {
  1241. /*
  1242. * Return the driver's global value for device loss timeout plus
  1243. * five seconds to allow the driver's nodev timer to run.
  1244. */
  1245. rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
  1246. }
  1247. static void
  1248. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1249. {
  1250. /*
  1251. * The driver doesn't have a per-target timeout setting. Set
  1252. * this value globally. lpfc_nodev_tmo should be greater then 0.
  1253. */
  1254. if (timeout)
  1255. lpfc_nodev_tmo = timeout;
  1256. else
  1257. lpfc_nodev_tmo = 1;
  1258. rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
  1259. }
  1260. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  1261. static ssize_t \
  1262. lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
  1263. { \
  1264. struct fc_rport *rport = transport_class_to_rport(cdev); \
  1265. struct lpfc_rport_data *rdata = rport->hostdata; \
  1266. return snprintf(buf, sz, format_string, \
  1267. (rdata->target) ? cast rdata->target->field : 0); \
  1268. }
  1269. #define lpfc_rport_rd_attr(field, format_string, sz) \
  1270. lpfc_rport_show_function(field, format_string, sz, ) \
  1271. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  1272. struct fc_function_template lpfc_transport_functions = {
  1273. /* fixed attributes the driver supports */
  1274. .show_host_node_name = 1,
  1275. .show_host_port_name = 1,
  1276. .show_host_supported_classes = 1,
  1277. .show_host_supported_fc4s = 1,
  1278. .show_host_symbolic_name = 1,
  1279. .show_host_supported_speeds = 1,
  1280. .show_host_maxframe_size = 1,
  1281. /* dynamic attributes the driver supports */
  1282. .get_host_port_id = lpfc_get_host_port_id,
  1283. .show_host_port_id = 1,
  1284. .get_host_port_type = lpfc_get_host_port_type,
  1285. .show_host_port_type = 1,
  1286. .get_host_port_state = lpfc_get_host_port_state,
  1287. .show_host_port_state = 1,
  1288. /* active_fc4s is shown but doesn't change (thus no get function) */
  1289. .show_host_active_fc4s = 1,
  1290. .get_host_speed = lpfc_get_host_speed,
  1291. .show_host_speed = 1,
  1292. .get_host_fabric_name = lpfc_get_host_fabric_name,
  1293. .show_host_fabric_name = 1,
  1294. /*
  1295. * The LPFC driver treats linkdown handling as target loss events
  1296. * so there are no sysfs handlers for link_down_tmo.
  1297. */
  1298. .get_fc_host_stats = lpfc_get_stats,
  1299. .reset_fc_host_stats = lpfc_reset_stats,
  1300. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  1301. .show_rport_maxframe_size = 1,
  1302. .show_rport_supported_classes = 1,
  1303. .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
  1304. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  1305. .show_rport_dev_loss_tmo = 1,
  1306. .get_starget_port_id = lpfc_get_starget_port_id,
  1307. .show_starget_port_id = 1,
  1308. .get_starget_node_name = lpfc_get_starget_node_name,
  1309. .show_starget_node_name = 1,
  1310. .get_starget_port_name = lpfc_get_starget_port_name,
  1311. .show_starget_port_name = 1,
  1312. .issue_fc_host_lip = lpfc_issue_lip,
  1313. };
  1314. void
  1315. lpfc_get_cfgparam(struct lpfc_hba *phba)
  1316. {
  1317. lpfc_log_verbose_init(phba, lpfc_log_verbose);
  1318. lpfc_cr_delay_init(phba, lpfc_cr_delay);
  1319. lpfc_cr_count_init(phba, lpfc_cr_count);
  1320. lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
  1321. lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
  1322. lpfc_fcp_class_init(phba, lpfc_fcp_class);
  1323. lpfc_use_adisc_init(phba, lpfc_use_adisc);
  1324. lpfc_ack0_init(phba, lpfc_ack0);
  1325. lpfc_topology_init(phba, lpfc_topology);
  1326. lpfc_scan_down_init(phba, lpfc_scan_down);
  1327. lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
  1328. lpfc_link_speed_init(phba, lpfc_link_speed);
  1329. lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
  1330. lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
  1331. lpfc_max_luns_init(phba, lpfc_max_luns);
  1332. lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
  1333. phba->cfg_poll = lpfc_poll;
  1334. /*
  1335. * The total number of segments is the configuration value plus 2
  1336. * since the IOCB need a command and response bde.
  1337. */
  1338. phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
  1339. /*
  1340. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  1341. * used to create the sg_dma_buf_pool must be dynamically calculated
  1342. */
  1343. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  1344. sizeof(struct fcp_rsp) +
  1345. (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
  1346. switch (phba->pcidev->device) {
  1347. case PCI_DEVICE_ID_LP101:
  1348. case PCI_DEVICE_ID_BSMB:
  1349. case PCI_DEVICE_ID_ZSMB:
  1350. phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
  1351. break;
  1352. case PCI_DEVICE_ID_RFLY:
  1353. case PCI_DEVICE_ID_PFLY:
  1354. case PCI_DEVICE_ID_BMID:
  1355. case PCI_DEVICE_ID_ZMID:
  1356. case PCI_DEVICE_ID_TFLY:
  1357. phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
  1358. break;
  1359. default:
  1360. phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
  1361. }
  1362. if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
  1363. lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
  1364. return;
  1365. }