lpfc_attr.c 42 KB

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