lpfc_attr.c 73 KB

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