lpfc_attr.c 55 KB

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