lpfc_attr.c 71 KB

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