lpfc_attr.c 76 KB

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