lpfc_attr.c 76 KB

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