lpfc_attr.c 73 KB

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