lpfc_attr.c 72 KB

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