lpfc_attr.c 48 KB

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