lpfc_attr.c 71 KB

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