lpfc_attr.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461
  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. 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 *host = class_to_shost(cdev);
  884. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  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 *host = class_to_shost(cdev);
  892. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
  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 lpfc_vport **vports;
  992. struct Scsi_Host *shost;
  993. struct lpfc_nodelist *ndlp;
  994. int i;
  995. vports = lpfc_create_vport_work_array(vport->phba);
  996. if (vports != NULL)
  997. for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
  998. shost = lpfc_shost_from_vport(vports[i]);
  999. spin_lock_irq(shost->host_lock);
  1000. list_for_each_entry(ndlp, &vports[i]->fc_nodes,
  1001. nlp_listp)
  1002. if (ndlp->rport)
  1003. ndlp->rport->dev_loss_tmo =
  1004. vport->cfg_devloss_tmo;
  1005. spin_unlock_irq(shost->host_lock);
  1006. }
  1007. lpfc_destroy_vport_work_array(vports);
  1008. }
  1009. static int
  1010. lpfc_nodev_tmo_set(struct lpfc_vport *vport, int val)
  1011. {
  1012. if (vport->dev_loss_tmo_changed ||
  1013. (lpfc_devloss_tmo != LPFC_DEF_DEVLOSS_TMO)) {
  1014. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1015. "0401 Ignoring change to nodev_tmo "
  1016. "because devloss_tmo is set.\n");
  1017. return 0;
  1018. }
  1019. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  1020. vport->cfg_nodev_tmo = val;
  1021. vport->cfg_devloss_tmo = val;
  1022. lpfc_update_rport_devloss_tmo(vport);
  1023. return 0;
  1024. }
  1025. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1026. "0403 lpfc_nodev_tmo attribute cannot be set to"
  1027. "%d, allowed range is [%d, %d]\n",
  1028. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  1029. return -EINVAL;
  1030. }
  1031. lpfc_vport_param_store(nodev_tmo)
  1032. static CLASS_DEVICE_ATTR(lpfc_nodev_tmo, S_IRUGO | S_IWUSR,
  1033. lpfc_nodev_tmo_show, lpfc_nodev_tmo_store);
  1034. /*
  1035. # lpfc_devloss_tmo: If set, it will hold all I/O errors on devices that
  1036. # disappear until the timer expires. Value range is [0,255]. Default
  1037. # value is 30.
  1038. */
  1039. module_param(lpfc_devloss_tmo, int, 0);
  1040. MODULE_PARM_DESC(lpfc_devloss_tmo,
  1041. "Seconds driver will hold I/O waiting "
  1042. "for a device to come back");
  1043. lpfc_vport_param_init(devloss_tmo, LPFC_DEF_DEVLOSS_TMO,
  1044. LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO)
  1045. lpfc_vport_param_show(devloss_tmo)
  1046. static int
  1047. lpfc_devloss_tmo_set(struct lpfc_vport *vport, int val)
  1048. {
  1049. if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
  1050. vport->cfg_nodev_tmo = val;
  1051. vport->cfg_devloss_tmo = val;
  1052. vport->dev_loss_tmo_changed = 1;
  1053. lpfc_update_rport_devloss_tmo(vport);
  1054. return 0;
  1055. }
  1056. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1057. "0404 lpfc_devloss_tmo attribute cannot be set to"
  1058. " %d, allowed range is [%d, %d]\n",
  1059. val, LPFC_MIN_DEVLOSS_TMO, LPFC_MAX_DEVLOSS_TMO);
  1060. return -EINVAL;
  1061. }
  1062. lpfc_vport_param_store(devloss_tmo)
  1063. static CLASS_DEVICE_ATTR(lpfc_devloss_tmo, S_IRUGO | S_IWUSR,
  1064. lpfc_devloss_tmo_show, lpfc_devloss_tmo_store);
  1065. /*
  1066. # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
  1067. # deluged with LOTS of information.
  1068. # You can set a bit mask to record specific types of verbose messages:
  1069. #
  1070. # LOG_ELS 0x1 ELS events
  1071. # LOG_DISCOVERY 0x2 Link discovery events
  1072. # LOG_MBOX 0x4 Mailbox events
  1073. # LOG_INIT 0x8 Initialization events
  1074. # LOG_LINK_EVENT 0x10 Link events
  1075. # LOG_FCP 0x40 FCP traffic history
  1076. # LOG_NODE 0x80 Node table events
  1077. # LOG_MISC 0x400 Miscellaneous events
  1078. # LOG_SLI 0x800 SLI events
  1079. # LOG_FCP_ERROR 0x1000 Only log FCP errors
  1080. # LOG_LIBDFC 0x2000 LIBDFC events
  1081. # LOG_ALL_MSG 0xffff LOG all messages
  1082. */
  1083. LPFC_VPORT_ATTR_HEX_RW(log_verbose, 0x0, 0x0, 0xffff,
  1084. "Verbose logging bit-mask");
  1085. /*
  1086. # lun_queue_depth: This parameter is used to limit the number of outstanding
  1087. # commands per FCP LUN. Value range is [1,128]. Default value is 30.
  1088. */
  1089. LPFC_VPORT_ATTR_R(lun_queue_depth, 30, 1, 128,
  1090. "Max number of FCP commands we can queue to a specific LUN");
  1091. /*
  1092. # hba_queue_depth: This parameter is used to limit the number of outstanding
  1093. # commands per lpfc HBA. Value range is [32,8192]. If this parameter
  1094. # value is greater than the maximum number of exchanges supported by the HBA,
  1095. # then maximum number of exchanges supported by the HBA is used to determine
  1096. # the hba_queue_depth.
  1097. */
  1098. LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
  1099. "Max number of FCP commands we can queue to a lpfc HBA");
  1100. /*
  1101. # peer_port_login: This parameter allows/prevents logins
  1102. # between peer ports hosted on the same physical port.
  1103. # When this parameter is set 0 peer ports of same physical port
  1104. # are not allowed to login to each other.
  1105. # When this parameter is set 1 peer ports of same physical port
  1106. # are allowed to login to each other.
  1107. # Default value of this parameter is 0.
  1108. */
  1109. LPFC_VPORT_ATTR_R(peer_port_login, 0, 0, 1,
  1110. "Allow peer ports on the same physical port to login to each "
  1111. "other.");
  1112. /*
  1113. # restrict_login: This parameter allows/prevents logins
  1114. # between Virtual Ports and remote initiators.
  1115. # When this parameter is not set (0) Virtual Ports will accept PLOGIs from
  1116. # other initiators and will attempt to PLOGI all remote ports.
  1117. # When this parameter is set (1) Virtual Ports will reject PLOGIs from
  1118. # remote ports and will not attempt to PLOGI to other initiators.
  1119. # This parameter does not restrict to the physical port.
  1120. # This parameter does not restrict logins to Fabric resident remote ports.
  1121. # Default value of this parameter is 1.
  1122. */
  1123. static int lpfc_restrict_login = 1;
  1124. module_param(lpfc_restrict_login, int, 0);
  1125. MODULE_PARM_DESC(lpfc_restrict_login,
  1126. "Restrict virtual ports login to remote initiators.");
  1127. lpfc_vport_param_show(restrict_login);
  1128. static int
  1129. lpfc_restrict_login_init(struct lpfc_vport *vport, int val)
  1130. {
  1131. if (val < 0 || val > 1) {
  1132. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1133. "0449 lpfc_restrict_login attribute cannot "
  1134. "be set to %d, allowed range is [0, 1]\n",
  1135. val);
  1136. vport->cfg_restrict_login = 1;
  1137. return -EINVAL;
  1138. }
  1139. if (vport->port_type == LPFC_PHYSICAL_PORT) {
  1140. vport->cfg_restrict_login = 0;
  1141. return 0;
  1142. }
  1143. vport->cfg_restrict_login = val;
  1144. return 0;
  1145. }
  1146. static int
  1147. lpfc_restrict_login_set(struct lpfc_vport *vport, int val)
  1148. {
  1149. if (val < 0 || val > 1) {
  1150. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1151. "0450 lpfc_restrict_login attribute cannot "
  1152. "be set to %d, allowed range is [0, 1]\n",
  1153. val);
  1154. vport->cfg_restrict_login = 1;
  1155. return -EINVAL;
  1156. }
  1157. if (vport->port_type == LPFC_PHYSICAL_PORT && val != 0) {
  1158. lpfc_printf_vlog(vport, KERN_ERR, LOG_INIT,
  1159. "0468 lpfc_restrict_login must be 0 for "
  1160. "Physical ports.\n");
  1161. vport->cfg_restrict_login = 0;
  1162. return 0;
  1163. }
  1164. vport->cfg_restrict_login = val;
  1165. return 0;
  1166. }
  1167. lpfc_vport_param_store(restrict_login);
  1168. static CLASS_DEVICE_ATTR(lpfc_restrict_login, S_IRUGO | S_IWUSR,
  1169. lpfc_restrict_login_show, lpfc_restrict_login_store);
  1170. /*
  1171. # Some disk devices have a "select ID" or "select Target" capability.
  1172. # From a protocol standpoint "select ID" usually means select the
  1173. # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
  1174. # annex" which contains a table that maps a "select ID" (a number
  1175. # between 0 and 7F) to an ALPA. By default, for compatibility with
  1176. # older drivers, the lpfc driver scans this table from low ALPA to high
  1177. # ALPA.
  1178. #
  1179. # Turning on the scan-down variable (on = 1, off = 0) will
  1180. # cause the lpfc driver to use an inverted table, effectively
  1181. # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
  1182. #
  1183. # (Note: This "select ID" functionality is a LOOP ONLY characteristic
  1184. # and will not work across a fabric. Also this parameter will take
  1185. # effect only in the case when ALPA map is not available.)
  1186. */
  1187. LPFC_VPORT_ATTR_R(scan_down, 1, 0, 1,
  1188. "Start scanning for devices from highest ALPA to lowest");
  1189. /*
  1190. # lpfc_topology: link topology for init link
  1191. # 0x0 = attempt loop mode then point-to-point
  1192. # 0x01 = internal loopback mode
  1193. # 0x02 = attempt point-to-point mode only
  1194. # 0x04 = attempt loop mode only
  1195. # 0x06 = attempt point-to-point mode then loop
  1196. # Set point-to-point mode if you want to run as an N_Port.
  1197. # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
  1198. # Default value is 0.
  1199. */
  1200. LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
  1201. /*
  1202. # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
  1203. # connection.
  1204. # 0 = auto select (default)
  1205. # 1 = 1 Gigabaud
  1206. # 2 = 2 Gigabaud
  1207. # 4 = 4 Gigabaud
  1208. # 8 = 8 Gigabaud
  1209. # Value range is [0,8]. Default value is 0.
  1210. */
  1211. LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
  1212. /*
  1213. # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
  1214. # Value range is [2,3]. Default value is 3.
  1215. */
  1216. LPFC_VPORT_ATTR_R(fcp_class, 3, 2, 3,
  1217. "Select Fibre Channel class of service for FCP sequences");
  1218. /*
  1219. # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
  1220. # is [0,1]. Default value is 0.
  1221. */
  1222. LPFC_VPORT_ATTR_RW(use_adisc, 0, 0, 1,
  1223. "Use ADISC on rediscovery to authenticate FCP devices");
  1224. /*
  1225. # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
  1226. # range is [0,1]. Default value is 0.
  1227. */
  1228. LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
  1229. /*
  1230. # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
  1231. # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
  1232. # value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
  1233. # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
  1234. # cr_delay is set to 0.
  1235. */
  1236. LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an "
  1237. "interrupt response is generated");
  1238. LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an "
  1239. "interrupt response is generated");
  1240. /*
  1241. # lpfc_multi_ring_support: Determines how many rings to spread available
  1242. # cmd/rsp IOCB entries across.
  1243. # Value range is [1,2]. Default value is 1.
  1244. */
  1245. LPFC_ATTR_R(multi_ring_support, 1, 1, 2, "Determines number of primary "
  1246. "SLI rings to spread IOCB entries across");
  1247. /*
  1248. # lpfc_multi_ring_rctl: If lpfc_multi_ring_support is enabled, this
  1249. # identifies what rctl value to configure the additional ring for.
  1250. # Value range is [1,0xff]. Default value is 4 (Unsolicated Data).
  1251. */
  1252. LPFC_ATTR_R(multi_ring_rctl, FC_UNSOL_DATA, 1,
  1253. 255, "Identifies RCTL for additional ring configuration");
  1254. /*
  1255. # lpfc_multi_ring_type: If lpfc_multi_ring_support is enabled, this
  1256. # identifies what type value to configure the additional ring for.
  1257. # Value range is [1,0xff]. Default value is 5 (LLC/SNAP).
  1258. */
  1259. LPFC_ATTR_R(multi_ring_type, FC_LLC_SNAP, 1,
  1260. 255, "Identifies TYPE for additional ring configuration");
  1261. /*
  1262. # lpfc_fdmi_on: controls FDMI support.
  1263. # 0 = no FDMI support
  1264. # 1 = support FDMI without attribute of hostname
  1265. # 2 = support FDMI with attribute of hostname
  1266. # Value range [0,2]. Default value is 0.
  1267. */
  1268. LPFC_VPORT_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
  1269. /*
  1270. # Specifies the maximum number of ELS cmds we can have outstanding (for
  1271. # discovery). Value range is [1,64]. Default value = 32.
  1272. */
  1273. LPFC_VPORT_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands "
  1274. "during discovery");
  1275. /*
  1276. # lpfc_max_luns: maximum allowed LUN.
  1277. # Value range is [0,65535]. Default value is 255.
  1278. # NOTE: The SCSI layer might probe all allowed LUN on some old targets.
  1279. */
  1280. LPFC_VPORT_ATTR_R(max_luns, 255, 0, 65535, "Maximum allowed LUN");
  1281. /*
  1282. # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
  1283. # Value range is [1,255], default value is 10.
  1284. */
  1285. LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
  1286. "Milliseconds driver will wait between polling FCP ring");
  1287. /*
  1288. # lpfc_use_msi: Use MSI (Message Signaled Interrupts) in systems that
  1289. # support this feature
  1290. # 0 = MSI disabled (default)
  1291. # 1 = MSI enabled
  1292. # Value range is [0,1]. Default value is 0.
  1293. */
  1294. LPFC_ATTR_R(use_msi, 0, 0, 1, "Use Message Signaled Interrupts, if possible");
  1295. struct class_device_attribute *lpfc_hba_attrs[] = {
  1296. &class_device_attr_info,
  1297. &class_device_attr_serialnum,
  1298. &class_device_attr_modeldesc,
  1299. &class_device_attr_modelname,
  1300. &class_device_attr_programtype,
  1301. &class_device_attr_portnum,
  1302. &class_device_attr_fwrev,
  1303. &class_device_attr_hdw,
  1304. &class_device_attr_option_rom_version,
  1305. &class_device_attr_state,
  1306. &class_device_attr_num_discovered_ports,
  1307. &class_device_attr_lpfc_drvr_version,
  1308. &class_device_attr_lpfc_log_verbose,
  1309. &class_device_attr_lpfc_lun_queue_depth,
  1310. &class_device_attr_lpfc_hba_queue_depth,
  1311. &class_device_attr_lpfc_peer_port_login,
  1312. &class_device_attr_lpfc_nodev_tmo,
  1313. &class_device_attr_lpfc_devloss_tmo,
  1314. &class_device_attr_lpfc_fcp_class,
  1315. &class_device_attr_lpfc_use_adisc,
  1316. &class_device_attr_lpfc_ack0,
  1317. &class_device_attr_lpfc_topology,
  1318. &class_device_attr_lpfc_scan_down,
  1319. &class_device_attr_lpfc_link_speed,
  1320. &class_device_attr_lpfc_cr_delay,
  1321. &class_device_attr_lpfc_cr_count,
  1322. &class_device_attr_lpfc_multi_ring_support,
  1323. &class_device_attr_lpfc_multi_ring_rctl,
  1324. &class_device_attr_lpfc_multi_ring_type,
  1325. &class_device_attr_lpfc_fdmi_on,
  1326. &class_device_attr_lpfc_max_luns,
  1327. &class_device_attr_lpfc_enable_npiv,
  1328. &class_device_attr_nport_evt_cnt,
  1329. &class_device_attr_board_mode,
  1330. &class_device_attr_max_vpi,
  1331. &class_device_attr_used_vpi,
  1332. &class_device_attr_max_rpi,
  1333. &class_device_attr_used_rpi,
  1334. &class_device_attr_max_xri,
  1335. &class_device_attr_used_xri,
  1336. &class_device_attr_npiv_info,
  1337. &class_device_attr_issue_reset,
  1338. &class_device_attr_lpfc_poll,
  1339. &class_device_attr_lpfc_poll_tmo,
  1340. &class_device_attr_lpfc_use_msi,
  1341. &class_device_attr_lpfc_soft_wwnn,
  1342. &class_device_attr_lpfc_soft_wwpn,
  1343. &class_device_attr_lpfc_soft_wwn_enable,
  1344. NULL,
  1345. };
  1346. struct class_device_attribute *lpfc_vport_attrs[] = {
  1347. &class_device_attr_info,
  1348. &class_device_attr_state,
  1349. &class_device_attr_num_discovered_ports,
  1350. &class_device_attr_lpfc_drvr_version,
  1351. &class_device_attr_lpfc_log_verbose,
  1352. &class_device_attr_lpfc_lun_queue_depth,
  1353. &class_device_attr_lpfc_nodev_tmo,
  1354. &class_device_attr_lpfc_devloss_tmo,
  1355. &class_device_attr_lpfc_hba_queue_depth,
  1356. &class_device_attr_lpfc_peer_port_login,
  1357. &class_device_attr_lpfc_restrict_login,
  1358. &class_device_attr_lpfc_fcp_class,
  1359. &class_device_attr_lpfc_use_adisc,
  1360. &class_device_attr_lpfc_fdmi_on,
  1361. &class_device_attr_lpfc_max_luns,
  1362. &class_device_attr_nport_evt_cnt,
  1363. &class_device_attr_npiv_info,
  1364. NULL,
  1365. };
  1366. static ssize_t
  1367. sysfs_ctlreg_write(struct kobject *kobj, struct bin_attribute *bin_attr,
  1368. char *buf, loff_t off, size_t count)
  1369. {
  1370. size_t buf_off;
  1371. struct class_device *cdev = container_of(kobj, struct class_device,
  1372. kobj);
  1373. struct Scsi_Host *shost = class_to_shost(cdev);
  1374. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1375. struct lpfc_hba *phba = vport->phba;
  1376. if ((off + count) > FF_REG_AREA_SIZE)
  1377. return -ERANGE;
  1378. if (count == 0) return 0;
  1379. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  1380. return -EINVAL;
  1381. if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
  1382. return -EPERM;
  1383. }
  1384. spin_lock_irq(&phba->hbalock);
  1385. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
  1386. writel(*((uint32_t *)(buf + buf_off)),
  1387. phba->ctrl_regs_memmap_p + off + buf_off);
  1388. spin_unlock_irq(&phba->hbalock);
  1389. return count;
  1390. }
  1391. static ssize_t
  1392. sysfs_ctlreg_read(struct kobject *kobj, struct bin_attribute *bin_attr,
  1393. char *buf, loff_t off, size_t count)
  1394. {
  1395. size_t buf_off;
  1396. uint32_t * tmp_ptr;
  1397. struct class_device *cdev = container_of(kobj, struct class_device,
  1398. kobj);
  1399. struct Scsi_Host *shost = class_to_shost(cdev);
  1400. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1401. struct lpfc_hba *phba = vport->phba;
  1402. if (off > FF_REG_AREA_SIZE)
  1403. return -ERANGE;
  1404. if ((off + count) > FF_REG_AREA_SIZE)
  1405. count = FF_REG_AREA_SIZE - off;
  1406. if (count == 0) return 0;
  1407. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  1408. return -EINVAL;
  1409. spin_lock_irq(&phba->hbalock);
  1410. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
  1411. tmp_ptr = (uint32_t *)(buf + buf_off);
  1412. *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
  1413. }
  1414. spin_unlock_irq(&phba->hbalock);
  1415. return count;
  1416. }
  1417. static struct bin_attribute sysfs_ctlreg_attr = {
  1418. .attr = {
  1419. .name = "ctlreg",
  1420. .mode = S_IRUSR | S_IWUSR,
  1421. },
  1422. .size = 256,
  1423. .read = sysfs_ctlreg_read,
  1424. .write = sysfs_ctlreg_write,
  1425. };
  1426. static void
  1427. sysfs_mbox_idle(struct lpfc_hba *phba)
  1428. {
  1429. phba->sysfs_mbox.state = SMBOX_IDLE;
  1430. phba->sysfs_mbox.offset = 0;
  1431. if (phba->sysfs_mbox.mbox) {
  1432. mempool_free(phba->sysfs_mbox.mbox,
  1433. phba->mbox_mem_pool);
  1434. phba->sysfs_mbox.mbox = NULL;
  1435. }
  1436. }
  1437. static ssize_t
  1438. sysfs_mbox_write(struct kobject *kobj, struct bin_attribute *bin_attr,
  1439. char *buf, loff_t off, size_t count)
  1440. {
  1441. struct class_device *cdev = container_of(kobj, struct class_device,
  1442. kobj);
  1443. struct Scsi_Host *shost = class_to_shost(cdev);
  1444. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1445. struct lpfc_hba *phba = vport->phba;
  1446. struct lpfcMboxq *mbox = NULL;
  1447. if ((count + off) > MAILBOX_CMD_SIZE)
  1448. return -ERANGE;
  1449. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  1450. return -EINVAL;
  1451. if (count == 0)
  1452. return 0;
  1453. if (off == 0) {
  1454. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1455. if (!mbox)
  1456. return -ENOMEM;
  1457. memset(mbox, 0, sizeof (LPFC_MBOXQ_t));
  1458. }
  1459. spin_lock_irq(&phba->hbalock);
  1460. if (off == 0) {
  1461. if (phba->sysfs_mbox.mbox)
  1462. mempool_free(mbox, phba->mbox_mem_pool);
  1463. else
  1464. phba->sysfs_mbox.mbox = mbox;
  1465. phba->sysfs_mbox.state = SMBOX_WRITING;
  1466. } else {
  1467. if (phba->sysfs_mbox.state != SMBOX_WRITING ||
  1468. phba->sysfs_mbox.offset != off ||
  1469. phba->sysfs_mbox.mbox == NULL) {
  1470. sysfs_mbox_idle(phba);
  1471. spin_unlock_irq(&phba->hbalock);
  1472. return -EAGAIN;
  1473. }
  1474. }
  1475. memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
  1476. buf, count);
  1477. phba->sysfs_mbox.offset = off + count;
  1478. spin_unlock_irq(&phba->hbalock);
  1479. return count;
  1480. }
  1481. static ssize_t
  1482. sysfs_mbox_read(struct kobject *kobj, struct bin_attribute *bin_attr,
  1483. char *buf, loff_t off, size_t count)
  1484. {
  1485. struct class_device *cdev = container_of(kobj, struct class_device,
  1486. kobj);
  1487. struct Scsi_Host *shost = class_to_shost(cdev);
  1488. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1489. struct lpfc_hba *phba = vport->phba;
  1490. int rc;
  1491. if (off > MAILBOX_CMD_SIZE)
  1492. return -ERANGE;
  1493. if ((count + off) > MAILBOX_CMD_SIZE)
  1494. count = MAILBOX_CMD_SIZE - off;
  1495. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  1496. return -EINVAL;
  1497. if (off && count == 0)
  1498. return 0;
  1499. spin_lock_irq(&phba->hbalock);
  1500. if (off == 0 &&
  1501. phba->sysfs_mbox.state == SMBOX_WRITING &&
  1502. phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
  1503. switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
  1504. /* Offline only */
  1505. case MBX_WRITE_NV:
  1506. case MBX_INIT_LINK:
  1507. case MBX_DOWN_LINK:
  1508. case MBX_CONFIG_LINK:
  1509. case MBX_CONFIG_RING:
  1510. case MBX_RESET_RING:
  1511. case MBX_UNREG_LOGIN:
  1512. case MBX_CLEAR_LA:
  1513. case MBX_DUMP_CONTEXT:
  1514. case MBX_RUN_DIAGS:
  1515. case MBX_RESTART:
  1516. case MBX_FLASH_WR_ULA:
  1517. case MBX_SET_MASK:
  1518. case MBX_SET_SLIM:
  1519. case MBX_SET_DEBUG:
  1520. if (!(vport->fc_flag & FC_OFFLINE_MODE)) {
  1521. printk(KERN_WARNING "mbox_read:Command 0x%x "
  1522. "is illegal in on-line state\n",
  1523. phba->sysfs_mbox.mbox->mb.mbxCommand);
  1524. sysfs_mbox_idle(phba);
  1525. spin_unlock_irq(&phba->hbalock);
  1526. return -EPERM;
  1527. }
  1528. case MBX_LOAD_SM:
  1529. case MBX_READ_NV:
  1530. case MBX_READ_CONFIG:
  1531. case MBX_READ_RCONFIG:
  1532. case MBX_READ_STATUS:
  1533. case MBX_READ_XRI:
  1534. case MBX_READ_REV:
  1535. case MBX_READ_LNK_STAT:
  1536. case MBX_DUMP_MEMORY:
  1537. case MBX_DOWN_LOAD:
  1538. case MBX_UPDATE_CFG:
  1539. case MBX_KILL_BOARD:
  1540. case MBX_LOAD_AREA:
  1541. case MBX_LOAD_EXP_ROM:
  1542. case MBX_BEACON:
  1543. case MBX_DEL_LD_ENTRY:
  1544. break;
  1545. case MBX_READ_SPARM64:
  1546. case MBX_READ_LA:
  1547. case MBX_READ_LA64:
  1548. case MBX_REG_LOGIN:
  1549. case MBX_REG_LOGIN64:
  1550. case MBX_CONFIG_PORT:
  1551. case MBX_RUN_BIU_DIAG:
  1552. printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
  1553. phba->sysfs_mbox.mbox->mb.mbxCommand);
  1554. sysfs_mbox_idle(phba);
  1555. spin_unlock_irq(&phba->hbalock);
  1556. return -EPERM;
  1557. default:
  1558. printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
  1559. phba->sysfs_mbox.mbox->mb.mbxCommand);
  1560. sysfs_mbox_idle(phba);
  1561. spin_unlock_irq(&phba->hbalock);
  1562. return -EPERM;
  1563. }
  1564. phba->sysfs_mbox.mbox->vport = vport;
  1565. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO) {
  1566. sysfs_mbox_idle(phba);
  1567. spin_unlock_irq(&phba->hbalock);
  1568. return -EAGAIN;
  1569. }
  1570. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  1571. (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
  1572. spin_unlock_irq(&phba->hbalock);
  1573. rc = lpfc_sli_issue_mbox (phba,
  1574. phba->sysfs_mbox.mbox,
  1575. MBX_POLL);
  1576. spin_lock_irq(&phba->hbalock);
  1577. } else {
  1578. spin_unlock_irq(&phba->hbalock);
  1579. rc = lpfc_sli_issue_mbox_wait (phba,
  1580. phba->sysfs_mbox.mbox,
  1581. lpfc_mbox_tmo_val(phba,
  1582. phba->sysfs_mbox.mbox->mb.mbxCommand) * HZ);
  1583. spin_lock_irq(&phba->hbalock);
  1584. }
  1585. if (rc != MBX_SUCCESS) {
  1586. if (rc == MBX_TIMEOUT) {
  1587. phba->sysfs_mbox.mbox = NULL;
  1588. }
  1589. sysfs_mbox_idle(phba);
  1590. spin_unlock_irq(&phba->hbalock);
  1591. return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
  1592. }
  1593. phba->sysfs_mbox.state = SMBOX_READING;
  1594. }
  1595. else if (phba->sysfs_mbox.offset != off ||
  1596. phba->sysfs_mbox.state != SMBOX_READING) {
  1597. printk(KERN_WARNING "mbox_read: Bad State\n");
  1598. sysfs_mbox_idle(phba);
  1599. spin_unlock_irq(&phba->hbalock);
  1600. return -EAGAIN;
  1601. }
  1602. memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
  1603. phba->sysfs_mbox.offset = off + count;
  1604. if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
  1605. sysfs_mbox_idle(phba);
  1606. spin_unlock_irq(&phba->hbalock);
  1607. return count;
  1608. }
  1609. static struct bin_attribute sysfs_mbox_attr = {
  1610. .attr = {
  1611. .name = "mbox",
  1612. .mode = S_IRUSR | S_IWUSR,
  1613. },
  1614. .size = MAILBOX_CMD_SIZE,
  1615. .read = sysfs_mbox_read,
  1616. .write = sysfs_mbox_write,
  1617. };
  1618. int
  1619. lpfc_alloc_sysfs_attr(struct lpfc_vport *vport)
  1620. {
  1621. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1622. int error;
  1623. error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
  1624. &sysfs_ctlreg_attr);
  1625. if (error)
  1626. goto out;
  1627. error = sysfs_create_bin_file(&shost->shost_classdev.kobj,
  1628. &sysfs_mbox_attr);
  1629. if (error)
  1630. goto out_remove_ctlreg_attr;
  1631. return 0;
  1632. out_remove_ctlreg_attr:
  1633. sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
  1634. out:
  1635. return error;
  1636. }
  1637. void
  1638. lpfc_free_sysfs_attr(struct lpfc_vport *vport)
  1639. {
  1640. struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
  1641. sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_mbox_attr);
  1642. sysfs_remove_bin_file(&shost->shost_classdev.kobj, &sysfs_ctlreg_attr);
  1643. }
  1644. /*
  1645. * Dynamic FC Host Attributes Support
  1646. */
  1647. static void
  1648. lpfc_get_host_port_id(struct Scsi_Host *shost)
  1649. {
  1650. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1651. /* note: fc_myDID already in cpu endianness */
  1652. fc_host_port_id(shost) = vport->fc_myDID;
  1653. }
  1654. static void
  1655. lpfc_get_host_port_type(struct Scsi_Host *shost)
  1656. {
  1657. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1658. struct lpfc_hba *phba = vport->phba;
  1659. spin_lock_irq(shost->host_lock);
  1660. if (vport->port_type == LPFC_NPIV_PORT) {
  1661. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1662. } else if (lpfc_is_link_up(phba)) {
  1663. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1664. if (vport->fc_flag & FC_PUBLIC_LOOP)
  1665. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  1666. else
  1667. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  1668. } else {
  1669. if (vport->fc_flag & FC_FABRIC)
  1670. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  1671. else
  1672. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  1673. }
  1674. } else
  1675. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1676. spin_unlock_irq(shost->host_lock);
  1677. }
  1678. static void
  1679. lpfc_get_host_port_state(struct Scsi_Host *shost)
  1680. {
  1681. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1682. struct lpfc_hba *phba = vport->phba;
  1683. spin_lock_irq(shost->host_lock);
  1684. if (vport->fc_flag & FC_OFFLINE_MODE)
  1685. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1686. else {
  1687. switch (phba->link_state) {
  1688. case LPFC_LINK_UNKNOWN:
  1689. case LPFC_LINK_DOWN:
  1690. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1691. break;
  1692. case LPFC_LINK_UP:
  1693. case LPFC_CLEAR_LA:
  1694. case LPFC_HBA_READY:
  1695. /* Links up, beyond this port_type reports state */
  1696. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1697. break;
  1698. case LPFC_HBA_ERROR:
  1699. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  1700. break;
  1701. default:
  1702. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1703. break;
  1704. }
  1705. }
  1706. spin_unlock_irq(shost->host_lock);
  1707. }
  1708. static void
  1709. lpfc_get_host_speed(struct Scsi_Host *shost)
  1710. {
  1711. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1712. struct lpfc_hba *phba = vport->phba;
  1713. spin_lock_irq(shost->host_lock);
  1714. if (lpfc_is_link_up(phba)) {
  1715. switch(phba->fc_linkspeed) {
  1716. case LA_1GHZ_LINK:
  1717. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  1718. break;
  1719. case LA_2GHZ_LINK:
  1720. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  1721. break;
  1722. case LA_4GHZ_LINK:
  1723. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  1724. break;
  1725. case LA_8GHZ_LINK:
  1726. fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
  1727. break;
  1728. default:
  1729. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1730. break;
  1731. }
  1732. }
  1733. spin_unlock_irq(shost->host_lock);
  1734. }
  1735. static void
  1736. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  1737. {
  1738. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1739. struct lpfc_hba *phba = vport->phba;
  1740. u64 node_name;
  1741. spin_lock_irq(shost->host_lock);
  1742. if ((vport->fc_flag & FC_FABRIC) ||
  1743. ((phba->fc_topology == TOPOLOGY_LOOP) &&
  1744. (vport->fc_flag & FC_PUBLIC_LOOP)))
  1745. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  1746. else
  1747. /* fabric is local port if there is no F/FL_Port */
  1748. node_name = wwn_to_u64(vport->fc_nodename.u.wwn);
  1749. spin_unlock_irq(shost->host_lock);
  1750. fc_host_fabric_name(shost) = node_name;
  1751. }
  1752. static struct fc_host_statistics *
  1753. lpfc_get_stats(struct Scsi_Host *shost)
  1754. {
  1755. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1756. struct lpfc_hba *phba = vport->phba;
  1757. struct lpfc_sli *psli = &phba->sli;
  1758. struct fc_host_statistics *hs = &phba->link_stats;
  1759. struct lpfc_lnk_stat * lso = &psli->lnk_stat_offsets;
  1760. LPFC_MBOXQ_t *pmboxq;
  1761. MAILBOX_t *pmb;
  1762. unsigned long seconds;
  1763. int rc = 0;
  1764. /*
  1765. * prevent udev from issuing mailbox commands until the port is
  1766. * configured.
  1767. */
  1768. if (phba->link_state < LPFC_LINK_DOWN ||
  1769. !phba->mbox_mem_pool ||
  1770. (phba->sli.sli_flag & LPFC_SLI2_ACTIVE) == 0)
  1771. return NULL;
  1772. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  1773. return NULL;
  1774. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1775. if (!pmboxq)
  1776. return NULL;
  1777. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1778. pmb = &pmboxq->mb;
  1779. pmb->mbxCommand = MBX_READ_STATUS;
  1780. pmb->mbxOwner = OWN_HOST;
  1781. pmboxq->context1 = NULL;
  1782. pmboxq->vport = vport;
  1783. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  1784. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1785. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1786. else
  1787. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1788. if (rc != MBX_SUCCESS) {
  1789. if (rc != MBX_TIMEOUT)
  1790. mempool_free(pmboxq, phba->mbox_mem_pool);
  1791. return NULL;
  1792. }
  1793. memset(hs, 0, sizeof (struct fc_host_statistics));
  1794. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  1795. hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
  1796. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  1797. hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
  1798. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1799. pmb->mbxCommand = MBX_READ_LNK_STAT;
  1800. pmb->mbxOwner = OWN_HOST;
  1801. pmboxq->context1 = NULL;
  1802. pmboxq->vport = vport;
  1803. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  1804. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1805. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1806. else
  1807. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1808. if (rc != MBX_SUCCESS) {
  1809. if (rc != MBX_TIMEOUT)
  1810. mempool_free(pmboxq, phba->mbox_mem_pool);
  1811. return NULL;
  1812. }
  1813. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  1814. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  1815. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  1816. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  1817. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  1818. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  1819. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  1820. hs->link_failure_count -= lso->link_failure_count;
  1821. hs->loss_of_sync_count -= lso->loss_of_sync_count;
  1822. hs->loss_of_signal_count -= lso->loss_of_signal_count;
  1823. hs->prim_seq_protocol_err_count -= lso->prim_seq_protocol_err_count;
  1824. hs->invalid_tx_word_count -= lso->invalid_tx_word_count;
  1825. hs->invalid_crc_count -= lso->invalid_crc_count;
  1826. hs->error_frames -= lso->error_frames;
  1827. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1828. hs->lip_count = (phba->fc_eventTag >> 1);
  1829. hs->lip_count -= lso->link_events;
  1830. hs->nos_count = -1;
  1831. } else {
  1832. hs->lip_count = -1;
  1833. hs->nos_count = (phba->fc_eventTag >> 1);
  1834. hs->nos_count -= lso->link_events;
  1835. }
  1836. hs->dumped_frames = -1;
  1837. seconds = get_seconds();
  1838. if (seconds < psli->stats_start)
  1839. hs->seconds_since_last_reset = seconds +
  1840. ((unsigned long)-1 - psli->stats_start);
  1841. else
  1842. hs->seconds_since_last_reset = seconds - psli->stats_start;
  1843. mempool_free(pmboxq, phba->mbox_mem_pool);
  1844. return hs;
  1845. }
  1846. static void
  1847. lpfc_reset_stats(struct Scsi_Host *shost)
  1848. {
  1849. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1850. struct lpfc_hba *phba = vport->phba;
  1851. struct lpfc_sli *psli = &phba->sli;
  1852. struct lpfc_lnk_stat *lso = &psli->lnk_stat_offsets;
  1853. LPFC_MBOXQ_t *pmboxq;
  1854. MAILBOX_t *pmb;
  1855. int rc = 0;
  1856. if (phba->sli.sli_flag & LPFC_BLOCK_MGMT_IO)
  1857. return;
  1858. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  1859. if (!pmboxq)
  1860. return;
  1861. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  1862. pmb = &pmboxq->mb;
  1863. pmb->mbxCommand = MBX_READ_STATUS;
  1864. pmb->mbxOwner = OWN_HOST;
  1865. pmb->un.varWords[0] = 0x1; /* reset request */
  1866. pmboxq->context1 = NULL;
  1867. pmboxq->vport = vport;
  1868. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  1869. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1870. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1871. else
  1872. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1873. if (rc != MBX_SUCCESS) {
  1874. if (rc != MBX_TIMEOUT)
  1875. mempool_free(pmboxq, phba->mbox_mem_pool);
  1876. return;
  1877. }
  1878. memset(pmboxq, 0, sizeof(LPFC_MBOXQ_t));
  1879. pmb->mbxCommand = MBX_READ_LNK_STAT;
  1880. pmb->mbxOwner = OWN_HOST;
  1881. pmboxq->context1 = NULL;
  1882. pmboxq->vport = vport;
  1883. if ((vport->fc_flag & FC_OFFLINE_MODE) ||
  1884. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1885. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1886. else
  1887. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1888. if (rc != MBX_SUCCESS) {
  1889. if (rc != MBX_TIMEOUT)
  1890. mempool_free( pmboxq, phba->mbox_mem_pool);
  1891. return;
  1892. }
  1893. lso->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  1894. lso->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  1895. lso->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  1896. lso->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  1897. lso->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  1898. lso->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  1899. lso->error_frames = pmb->un.varRdLnk.crcCnt;
  1900. lso->link_events = (phba->fc_eventTag >> 1);
  1901. psli->stats_start = get_seconds();
  1902. mempool_free(pmboxq, phba->mbox_mem_pool);
  1903. return;
  1904. }
  1905. /*
  1906. * The LPFC driver treats linkdown handling as target loss events so there
  1907. * are no sysfs handlers for link_down_tmo.
  1908. */
  1909. static struct lpfc_nodelist *
  1910. lpfc_get_node_by_target(struct scsi_target *starget)
  1911. {
  1912. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1913. struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
  1914. struct lpfc_nodelist *ndlp;
  1915. spin_lock_irq(shost->host_lock);
  1916. /* Search for this, mapped, target ID */
  1917. list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
  1918. if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
  1919. starget->id == ndlp->nlp_sid) {
  1920. spin_unlock_irq(shost->host_lock);
  1921. return ndlp;
  1922. }
  1923. }
  1924. spin_unlock_irq(shost->host_lock);
  1925. return NULL;
  1926. }
  1927. static void
  1928. lpfc_get_starget_port_id(struct scsi_target *starget)
  1929. {
  1930. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  1931. fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
  1932. }
  1933. static void
  1934. lpfc_get_starget_node_name(struct scsi_target *starget)
  1935. {
  1936. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  1937. fc_starget_node_name(starget) =
  1938. ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
  1939. }
  1940. static void
  1941. lpfc_get_starget_port_name(struct scsi_target *starget)
  1942. {
  1943. struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
  1944. fc_starget_port_name(starget) =
  1945. ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
  1946. }
  1947. static void
  1948. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1949. {
  1950. if (timeout)
  1951. rport->dev_loss_tmo = timeout;
  1952. else
  1953. rport->dev_loss_tmo = 1;
  1954. }
  1955. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  1956. static ssize_t \
  1957. lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
  1958. { \
  1959. struct fc_rport *rport = transport_class_to_rport(cdev); \
  1960. struct lpfc_rport_data *rdata = rport->hostdata; \
  1961. return snprintf(buf, sz, format_string, \
  1962. (rdata->target) ? cast rdata->target->field : 0); \
  1963. }
  1964. #define lpfc_rport_rd_attr(field, format_string, sz) \
  1965. lpfc_rport_show_function(field, format_string, sz, ) \
  1966. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  1967. struct fc_function_template lpfc_transport_functions = {
  1968. /* fixed attributes the driver supports */
  1969. .show_host_node_name = 1,
  1970. .show_host_port_name = 1,
  1971. .show_host_supported_classes = 1,
  1972. .show_host_supported_fc4s = 1,
  1973. .show_host_supported_speeds = 1,
  1974. .show_host_maxframe_size = 1,
  1975. /* dynamic attributes the driver supports */
  1976. .get_host_port_id = lpfc_get_host_port_id,
  1977. .show_host_port_id = 1,
  1978. .get_host_port_type = lpfc_get_host_port_type,
  1979. .show_host_port_type = 1,
  1980. .get_host_port_state = lpfc_get_host_port_state,
  1981. .show_host_port_state = 1,
  1982. /* active_fc4s is shown but doesn't change (thus no get function) */
  1983. .show_host_active_fc4s = 1,
  1984. .get_host_speed = lpfc_get_host_speed,
  1985. .show_host_speed = 1,
  1986. .get_host_fabric_name = lpfc_get_host_fabric_name,
  1987. .show_host_fabric_name = 1,
  1988. /*
  1989. * The LPFC driver treats linkdown handling as target loss events
  1990. * so there are no sysfs handlers for link_down_tmo.
  1991. */
  1992. .get_fc_host_stats = lpfc_get_stats,
  1993. .reset_fc_host_stats = lpfc_reset_stats,
  1994. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  1995. .show_rport_maxframe_size = 1,
  1996. .show_rport_supported_classes = 1,
  1997. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  1998. .show_rport_dev_loss_tmo = 1,
  1999. .get_starget_port_id = lpfc_get_starget_port_id,
  2000. .show_starget_port_id = 1,
  2001. .get_starget_node_name = lpfc_get_starget_node_name,
  2002. .show_starget_node_name = 1,
  2003. .get_starget_port_name = lpfc_get_starget_port_name,
  2004. .show_starget_port_name = 1,
  2005. .issue_fc_host_lip = lpfc_issue_lip,
  2006. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  2007. .terminate_rport_io = lpfc_terminate_rport_io,
  2008. .vport_create = lpfc_vport_create,
  2009. .vport_delete = lpfc_vport_delete,
  2010. .dd_fcvport_size = sizeof(struct lpfc_vport *),
  2011. };
  2012. struct fc_function_template lpfc_vport_transport_functions = {
  2013. /* fixed attributes the driver supports */
  2014. .show_host_node_name = 1,
  2015. .show_host_port_name = 1,
  2016. .show_host_supported_classes = 1,
  2017. .show_host_supported_fc4s = 1,
  2018. .show_host_supported_speeds = 1,
  2019. .show_host_maxframe_size = 1,
  2020. /* dynamic attributes the driver supports */
  2021. .get_host_port_id = lpfc_get_host_port_id,
  2022. .show_host_port_id = 1,
  2023. .get_host_port_type = lpfc_get_host_port_type,
  2024. .show_host_port_type = 1,
  2025. .get_host_port_state = lpfc_get_host_port_state,
  2026. .show_host_port_state = 1,
  2027. /* active_fc4s is shown but doesn't change (thus no get function) */
  2028. .show_host_active_fc4s = 1,
  2029. .get_host_speed = lpfc_get_host_speed,
  2030. .show_host_speed = 1,
  2031. .get_host_fabric_name = lpfc_get_host_fabric_name,
  2032. .show_host_fabric_name = 1,
  2033. /*
  2034. * The LPFC driver treats linkdown handling as target loss events
  2035. * so there are no sysfs handlers for link_down_tmo.
  2036. */
  2037. .get_fc_host_stats = lpfc_get_stats,
  2038. .reset_fc_host_stats = lpfc_reset_stats,
  2039. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  2040. .show_rport_maxframe_size = 1,
  2041. .show_rport_supported_classes = 1,
  2042. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  2043. .show_rport_dev_loss_tmo = 1,
  2044. .get_starget_port_id = lpfc_get_starget_port_id,
  2045. .show_starget_port_id = 1,
  2046. .get_starget_node_name = lpfc_get_starget_node_name,
  2047. .show_starget_node_name = 1,
  2048. .get_starget_port_name = lpfc_get_starget_port_name,
  2049. .show_starget_port_name = 1,
  2050. .dev_loss_tmo_callbk = lpfc_dev_loss_tmo_callbk,
  2051. .terminate_rport_io = lpfc_terminate_rport_io,
  2052. .vport_disable = lpfc_vport_disable,
  2053. };
  2054. void
  2055. lpfc_get_cfgparam(struct lpfc_hba *phba)
  2056. {
  2057. lpfc_cr_delay_init(phba, lpfc_cr_delay);
  2058. lpfc_cr_count_init(phba, lpfc_cr_count);
  2059. lpfc_multi_ring_support_init(phba, lpfc_multi_ring_support);
  2060. lpfc_multi_ring_rctl_init(phba, lpfc_multi_ring_rctl);
  2061. lpfc_multi_ring_type_init(phba, lpfc_multi_ring_type);
  2062. lpfc_ack0_init(phba, lpfc_ack0);
  2063. lpfc_topology_init(phba, lpfc_topology);
  2064. lpfc_link_speed_init(phba, lpfc_link_speed);
  2065. lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
  2066. lpfc_enable_npiv_init(phba, lpfc_enable_npiv);
  2067. lpfc_use_msi_init(phba, lpfc_use_msi);
  2068. phba->cfg_poll = lpfc_poll;
  2069. phba->cfg_soft_wwnn = 0L;
  2070. phba->cfg_soft_wwpn = 0L;
  2071. /*
  2072. * The total number of segments is the configuration value plus 2
  2073. * since the IOCB need a command and response bde.
  2074. */
  2075. phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
  2076. /*
  2077. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  2078. * used to create the sg_dma_buf_pool must be dynamically calculated
  2079. */
  2080. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  2081. sizeof(struct fcp_rsp) +
  2082. (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
  2083. lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
  2084. return;
  2085. }
  2086. void
  2087. lpfc_get_vport_cfgparam(struct lpfc_vport *vport)
  2088. {
  2089. lpfc_log_verbose_init(vport, lpfc_log_verbose);
  2090. lpfc_lun_queue_depth_init(vport, lpfc_lun_queue_depth);
  2091. lpfc_devloss_tmo_init(vport, lpfc_devloss_tmo);
  2092. lpfc_nodev_tmo_init(vport, lpfc_nodev_tmo);
  2093. lpfc_peer_port_login_init(vport, lpfc_peer_port_login);
  2094. lpfc_restrict_login_init(vport, lpfc_restrict_login);
  2095. lpfc_fcp_class_init(vport, lpfc_fcp_class);
  2096. lpfc_use_adisc_init(vport, lpfc_use_adisc);
  2097. lpfc_fdmi_on_init(vport, lpfc_fdmi_on);
  2098. lpfc_discovery_threads_init(vport, lpfc_discovery_threads);
  2099. lpfc_max_luns_init(vport, lpfc_max_luns);
  2100. lpfc_scan_down_init(vport, lpfc_scan_down);
  2101. return;
  2102. }