lpfc_attr.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. /*******************************************************************
  2. * This file is part of the Emulex Linux Device Driver for *
  3. * Fibre Channel Host Bus Adapters. *
  4. * Copyright (C) 2004-2005 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/pci.h>
  23. #include <linux/interrupt.h>
  24. #include <scsi/scsi.h>
  25. #include <scsi/scsi_device.h>
  26. #include <scsi/scsi_host.h>
  27. #include <scsi/scsi_tcq.h>
  28. #include <scsi/scsi_transport_fc.h>
  29. #include "lpfc_hw.h"
  30. #include "lpfc_sli.h"
  31. #include "lpfc_disc.h"
  32. #include "lpfc_scsi.h"
  33. #include "lpfc.h"
  34. #include "lpfc_logmsg.h"
  35. #include "lpfc_version.h"
  36. #include "lpfc_compat.h"
  37. #include "lpfc_crtn.h"
  38. static void
  39. lpfc_jedec_to_ascii(int incr, char hdw[])
  40. {
  41. int i, j;
  42. for (i = 0; i < 8; i++) {
  43. j = (incr & 0xf);
  44. if (j <= 9)
  45. hdw[7 - i] = 0x30 + j;
  46. else
  47. hdw[7 - i] = 0x61 + j - 10;
  48. incr = (incr >> 4);
  49. }
  50. hdw[8] = 0;
  51. return;
  52. }
  53. static ssize_t
  54. lpfc_drvr_version_show(struct class_device *cdev, char *buf)
  55. {
  56. return snprintf(buf, PAGE_SIZE, LPFC_MODULE_DESC "\n");
  57. }
  58. static ssize_t
  59. management_version_show(struct class_device *cdev, char *buf)
  60. {
  61. return snprintf(buf, PAGE_SIZE, DFC_API_VERSION "\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 *host = class_to_shost(cdev);
  73. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  74. return snprintf(buf, PAGE_SIZE, "%s\n",phba->SerialNumber);
  75. }
  76. static ssize_t
  77. lpfc_modeldesc_show(struct class_device *cdev, char *buf)
  78. {
  79. struct Scsi_Host *host = class_to_shost(cdev);
  80. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  81. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelDesc);
  82. }
  83. static ssize_t
  84. lpfc_modelname_show(struct class_device *cdev, char *buf)
  85. {
  86. struct Scsi_Host *host = class_to_shost(cdev);
  87. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  88. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ModelName);
  89. }
  90. static ssize_t
  91. lpfc_programtype_show(struct class_device *cdev, char *buf)
  92. {
  93. struct Scsi_Host *host = class_to_shost(cdev);
  94. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  95. return snprintf(buf, PAGE_SIZE, "%s\n",phba->ProgramType);
  96. }
  97. static ssize_t
  98. lpfc_portnum_show(struct class_device *cdev, char *buf)
  99. {
  100. struct Scsi_Host *host = class_to_shost(cdev);
  101. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  102. return snprintf(buf, PAGE_SIZE, "%s\n",phba->Port);
  103. }
  104. static ssize_t
  105. lpfc_fwrev_show(struct class_device *cdev, char *buf)
  106. {
  107. struct Scsi_Host *host = class_to_shost(cdev);
  108. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  109. char fwrev[32];
  110. lpfc_decode_firmware_rev(phba, fwrev, 1);
  111. return snprintf(buf, PAGE_SIZE, "%s\n",fwrev);
  112. }
  113. static ssize_t
  114. lpfc_hdw_show(struct class_device *cdev, char *buf)
  115. {
  116. char hdw[9];
  117. struct Scsi_Host *host = class_to_shost(cdev);
  118. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  119. lpfc_vpd_t *vp = &phba->vpd;
  120. lpfc_jedec_to_ascii(vp->rev.biuRev, hdw);
  121. return snprintf(buf, PAGE_SIZE, "%s\n", hdw);
  122. }
  123. static ssize_t
  124. lpfc_option_rom_version_show(struct class_device *cdev, char *buf)
  125. {
  126. struct Scsi_Host *host = class_to_shost(cdev);
  127. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  128. return snprintf(buf, PAGE_SIZE, "%s\n", phba->OptionROMVersion);
  129. }
  130. static ssize_t
  131. lpfc_state_show(struct class_device *cdev, char *buf)
  132. {
  133. struct Scsi_Host *host = class_to_shost(cdev);
  134. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  135. int len = 0;
  136. switch (phba->hba_state) {
  137. case LPFC_INIT_START:
  138. case LPFC_INIT_MBX_CMDS:
  139. case LPFC_LINK_DOWN:
  140. len += snprintf(buf + len, PAGE_SIZE-len, "Link Down\n");
  141. break;
  142. case LPFC_LINK_UP:
  143. case LPFC_LOCAL_CFG_LINK:
  144. len += snprintf(buf + len, PAGE_SIZE-len, "Link Up\n");
  145. break;
  146. case LPFC_FLOGI:
  147. case LPFC_FABRIC_CFG_LINK:
  148. case LPFC_NS_REG:
  149. case LPFC_NS_QRY:
  150. case LPFC_BUILD_DISC_LIST:
  151. case LPFC_DISC_AUTH:
  152. case LPFC_CLEAR_LA:
  153. len += snprintf(buf + len, PAGE_SIZE-len,
  154. "Link Up - Discovery\n");
  155. break;
  156. case LPFC_HBA_READY:
  157. len += snprintf(buf + len, PAGE_SIZE-len,
  158. "Link Up - Ready:\n");
  159. if (phba->fc_topology == TOPOLOGY_LOOP) {
  160. if (phba->fc_flag & FC_PUBLIC_LOOP)
  161. len += snprintf(buf + len, PAGE_SIZE-len,
  162. " Public Loop\n");
  163. else
  164. len += snprintf(buf + len, PAGE_SIZE-len,
  165. " Private Loop\n");
  166. } else {
  167. if (phba->fc_flag & FC_FABRIC)
  168. len += snprintf(buf + len, PAGE_SIZE-len,
  169. " Fabric\n");
  170. else
  171. len += snprintf(buf + len, PAGE_SIZE-len,
  172. " Point-2-Point\n");
  173. }
  174. }
  175. return len;
  176. }
  177. static ssize_t
  178. lpfc_num_discovered_ports_show(struct class_device *cdev, char *buf)
  179. {
  180. struct Scsi_Host *host = class_to_shost(cdev);
  181. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  182. return snprintf(buf, PAGE_SIZE, "%d\n", phba->fc_map_cnt +
  183. phba->fc_unmap_cnt);
  184. }
  185. static int
  186. lpfc_issue_lip(struct Scsi_Host *host)
  187. {
  188. struct lpfc_hba *phba = (struct lpfc_hba *) host->hostdata[0];
  189. LPFC_MBOXQ_t *pmboxq;
  190. int mbxstatus = MBXERR_ERROR;
  191. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  192. (phba->hba_state != LPFC_HBA_READY))
  193. return -EPERM;
  194. pmboxq = mempool_alloc(phba->mbox_mem_pool,GFP_KERNEL);
  195. if (!pmboxq)
  196. return -ENOMEM;
  197. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  198. lpfc_init_link(phba, pmboxq, phba->cfg_topology, phba->cfg_link_speed);
  199. mbxstatus = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  200. if (mbxstatus == MBX_TIMEOUT)
  201. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  202. else
  203. mempool_free( pmboxq, phba->mbox_mem_pool);
  204. if (mbxstatus == MBXERR_ERROR)
  205. return -EIO;
  206. return 0;
  207. }
  208. static ssize_t
  209. lpfc_nport_evt_cnt_show(struct class_device *cdev, char *buf)
  210. {
  211. struct Scsi_Host *host = class_to_shost(cdev);
  212. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  213. return snprintf(buf, PAGE_SIZE, "%d\n", phba->nport_event_cnt);
  214. }
  215. static ssize_t
  216. lpfc_board_online_show(struct class_device *cdev, char *buf)
  217. {
  218. struct Scsi_Host *host = class_to_shost(cdev);
  219. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  220. if (!phba) return 0;
  221. if (phba->fc_flag & FC_OFFLINE_MODE)
  222. return snprintf(buf, PAGE_SIZE, "0\n");
  223. else
  224. return snprintf(buf, PAGE_SIZE, "1\n");
  225. }
  226. static ssize_t
  227. lpfc_board_online_store(struct class_device *cdev, const char *buf,
  228. size_t count)
  229. {
  230. struct Scsi_Host *host = class_to_shost(cdev);
  231. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  232. struct completion online_compl;
  233. int val=0, status=0;
  234. if (sscanf(buf, "%d", &val) != 1)
  235. return 0;
  236. init_completion(&online_compl);
  237. if (val)
  238. lpfc_workq_post_event(phba, &status, &online_compl,
  239. LPFC_EVT_ONLINE);
  240. else
  241. lpfc_workq_post_event(phba, &status, &online_compl,
  242. LPFC_EVT_OFFLINE);
  243. wait_for_completion(&online_compl);
  244. if (!status)
  245. return strlen(buf);
  246. else
  247. return 0;
  248. }
  249. #define lpfc_param_show(attr) \
  250. static ssize_t \
  251. lpfc_##attr##_show(struct class_device *cdev, char *buf) \
  252. { \
  253. struct Scsi_Host *host = class_to_shost(cdev);\
  254. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\
  255. int val = 0;\
  256. if (phba){\
  257. val = phba->cfg_##attr;\
  258. return snprintf(buf, PAGE_SIZE, "%d\n",\
  259. phba->cfg_##attr);\
  260. }\
  261. return 0;\
  262. }
  263. #define lpfc_param_store(attr, minval, maxval) \
  264. static ssize_t \
  265. lpfc_##attr##_store(struct class_device *cdev, const char *buf, size_t count) \
  266. { \
  267. struct Scsi_Host *host = class_to_shost(cdev);\
  268. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];\
  269. int val = 0;\
  270. if (!isdigit(buf[0]))\
  271. return -EINVAL;\
  272. if (sscanf(buf, "0x%x", &val) != 1)\
  273. if (sscanf(buf, "%d", &val) != 1)\
  274. return -EINVAL;\
  275. if (phba){\
  276. if (val >= minval && val <= maxval) {\
  277. phba->cfg_##attr = val;\
  278. return strlen(buf);\
  279. }\
  280. }\
  281. return 0;\
  282. }
  283. #define LPFC_ATTR_R_NOINIT(name, desc) \
  284. extern int lpfc_##name;\
  285. module_param(lpfc_##name, int, 0);\
  286. MODULE_PARM_DESC(lpfc_##name, desc);\
  287. lpfc_param_show(name)\
  288. static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  289. #define LPFC_ATTR_R(name, defval, minval, maxval, desc) \
  290. static int lpfc_##name = defval;\
  291. module_param(lpfc_##name, int, 0);\
  292. MODULE_PARM_DESC(lpfc_##name, desc);\
  293. lpfc_param_show(name)\
  294. static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO , lpfc_##name##_show, NULL)
  295. #define LPFC_ATTR_RW(name, defval, minval, maxval, desc) \
  296. static int lpfc_##name = defval;\
  297. module_param(lpfc_##name, int, 0);\
  298. MODULE_PARM_DESC(lpfc_##name, desc);\
  299. lpfc_param_show(name)\
  300. lpfc_param_store(name, minval, maxval)\
  301. static CLASS_DEVICE_ATTR(lpfc_##name, S_IRUGO | S_IWUSR,\
  302. lpfc_##name##_show, lpfc_##name##_store)
  303. static CLASS_DEVICE_ATTR(info, S_IRUGO, lpfc_info_show, NULL);
  304. static CLASS_DEVICE_ATTR(serialnum, S_IRUGO, lpfc_serialnum_show, NULL);
  305. static CLASS_DEVICE_ATTR(modeldesc, S_IRUGO, lpfc_modeldesc_show, NULL);
  306. static CLASS_DEVICE_ATTR(modelname, S_IRUGO, lpfc_modelname_show, NULL);
  307. static CLASS_DEVICE_ATTR(programtype, S_IRUGO, lpfc_programtype_show, NULL);
  308. static CLASS_DEVICE_ATTR(portnum, S_IRUGO, lpfc_portnum_show, NULL);
  309. static CLASS_DEVICE_ATTR(fwrev, S_IRUGO, lpfc_fwrev_show, NULL);
  310. static CLASS_DEVICE_ATTR(hdw, S_IRUGO, lpfc_hdw_show, NULL);
  311. static CLASS_DEVICE_ATTR(state, S_IRUGO, lpfc_state_show, NULL);
  312. static CLASS_DEVICE_ATTR(option_rom_version, S_IRUGO,
  313. lpfc_option_rom_version_show, NULL);
  314. static CLASS_DEVICE_ATTR(num_discovered_ports, S_IRUGO,
  315. lpfc_num_discovered_ports_show, NULL);
  316. static CLASS_DEVICE_ATTR(nport_evt_cnt, S_IRUGO, lpfc_nport_evt_cnt_show, NULL);
  317. static CLASS_DEVICE_ATTR(lpfc_drvr_version, S_IRUGO, lpfc_drvr_version_show,
  318. NULL);
  319. static CLASS_DEVICE_ATTR(management_version, S_IRUGO, management_version_show,
  320. NULL);
  321. static CLASS_DEVICE_ATTR(board_online, S_IRUGO | S_IWUSR,
  322. lpfc_board_online_show, lpfc_board_online_store);
  323. /*
  324. # lpfc_log_verbose: Only turn this flag on if you are willing to risk being
  325. # deluged with LOTS of information.
  326. # You can set a bit mask to record specific types of verbose messages:
  327. #
  328. # LOG_ELS 0x1 ELS events
  329. # LOG_DISCOVERY 0x2 Link discovery events
  330. # LOG_MBOX 0x4 Mailbox events
  331. # LOG_INIT 0x8 Initialization events
  332. # LOG_LINK_EVENT 0x10 Link events
  333. # LOG_IP 0x20 IP traffic history
  334. # LOG_FCP 0x40 FCP traffic history
  335. # LOG_NODE 0x80 Node table events
  336. # LOG_MISC 0x400 Miscellaneous events
  337. # LOG_SLI 0x800 SLI events
  338. # LOG_CHK_COND 0x1000 FCP Check condition flag
  339. # LOG_LIBDFC 0x2000 LIBDFC events
  340. # LOG_ALL_MSG 0xffff LOG all messages
  341. */
  342. LPFC_ATTR_RW(log_verbose, 0x0, 0x0, 0xffff, "Verbose logging bit-mask");
  343. /*
  344. # lun_queue_depth: This parameter is used to limit the number of outstanding
  345. # commands per FCP LUN. Value range is [1,128]. Default value is 30.
  346. */
  347. LPFC_ATTR_R(lun_queue_depth, 30, 1, 128,
  348. "Max number of FCP commands we can queue to a specific LUN");
  349. /*
  350. # Some disk devices have a "select ID" or "select Target" capability.
  351. # From a protocol standpoint "select ID" usually means select the
  352. # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
  353. # annex" which contains a table that maps a "select ID" (a number
  354. # between 0 and 7F) to an ALPA. By default, for compatibility with
  355. # older drivers, the lpfc driver scans this table from low ALPA to high
  356. # ALPA.
  357. #
  358. # Turning on the scan-down variable (on = 1, off = 0) will
  359. # cause the lpfc driver to use an inverted table, effectively
  360. # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
  361. #
  362. # (Note: This "select ID" functionality is a LOOP ONLY characteristic
  363. # and will not work across a fabric. Also this parameter will take
  364. # effect only in the case when ALPA map is not available.)
  365. */
  366. LPFC_ATTR_R(scan_down, 1, 0, 1,
  367. "Start scanning for devices from highest ALPA to lowest");
  368. /*
  369. # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
  370. # until the timer expires. Value range is [0,255]. Default value is 20.
  371. # NOTE: this MUST be less then the SCSI Layer command timeout - 1.
  372. */
  373. LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
  374. "Seconds driver will hold I/O waiting for a device to come back");
  375. /*
  376. # lpfc_topology: link topology for init link
  377. # 0x0 = attempt loop mode then point-to-point
  378. # 0x02 = attempt point-to-point mode only
  379. # 0x04 = attempt loop mode only
  380. # 0x06 = attempt point-to-point mode then loop
  381. # Set point-to-point mode if you want to run as an N_Port.
  382. # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
  383. # Default value is 0.
  384. */
  385. LPFC_ATTR_R(topology, 0, 0, 6, "Select Fibre Channel topology");
  386. /*
  387. # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
  388. # connection.
  389. # 0 = auto select (default)
  390. # 1 = 1 Gigabaud
  391. # 2 = 2 Gigabaud
  392. # 4 = 4 Gigabaud
  393. # Value range is [0,4]. Default value is 0.
  394. */
  395. LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
  396. /*
  397. # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
  398. # Value range is [2,3]. Default value is 3.
  399. */
  400. LPFC_ATTR_R(fcp_class, 3, 2, 3,
  401. "Select Fibre Channel class of service for FCP sequences");
  402. /*
  403. # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
  404. # is [0,1]. Default value is 0.
  405. */
  406. LPFC_ATTR_RW(use_adisc, 0, 0, 1,
  407. "Use ADISC on rediscovery to authenticate FCP devices");
  408. /*
  409. # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
  410. # range is [0,1]. Default value is 0.
  411. */
  412. LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
  413. /*
  414. # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
  415. # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
  416. # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
  417. # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
  418. # cr_delay is set to 0.
  419. */
  420. static int lpfc_cr_delay = 0;
  421. module_param(lpfc_cr_delay, int , 0);
  422. MODULE_PARM_DESC(lpfc_cr_delay, "A count of milliseconds after which an "
  423. "interrupt response is generated");
  424. static int lpfc_cr_count = 1;
  425. module_param(lpfc_cr_count, int, 0);
  426. MODULE_PARM_DESC(lpfc_cr_count, "A count of I/O completions after which an "
  427. "interrupt response is generated");
  428. /*
  429. # lpfc_fdmi_on: controls FDMI support.
  430. # 0 = no FDMI support
  431. # 1 = support FDMI without attribute of hostname
  432. # 2 = support FDMI with attribute of hostname
  433. # Value range [0,2]. Default value is 0.
  434. */
  435. LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
  436. /*
  437. # Specifies the maximum number of ELS cmds we can have outstanding (for
  438. # discovery). Value range is [1,64]. Default value = 32.
  439. */
  440. static int lpfc_discovery_threads = 32;
  441. module_param(lpfc_discovery_threads, int, 0);
  442. MODULE_PARM_DESC(lpfc_discovery_threads, "Maximum number of ELS commands "
  443. "during discovery");
  444. /*
  445. # lpfc_max_luns: maximum number of LUNs per target driver will support
  446. # Value range is [1,32768]. Default value is 256.
  447. # NOTE: The SCSI layer will scan each target for this many luns
  448. */
  449. LPFC_ATTR_R(max_luns, 256, 1, 32768,
  450. "Maximum number of LUNs per target driver will support");
  451. struct class_device_attribute *lpfc_host_attrs[] = {
  452. &class_device_attr_info,
  453. &class_device_attr_serialnum,
  454. &class_device_attr_modeldesc,
  455. &class_device_attr_modelname,
  456. &class_device_attr_programtype,
  457. &class_device_attr_portnum,
  458. &class_device_attr_fwrev,
  459. &class_device_attr_hdw,
  460. &class_device_attr_option_rom_version,
  461. &class_device_attr_state,
  462. &class_device_attr_num_discovered_ports,
  463. &class_device_attr_lpfc_drvr_version,
  464. &class_device_attr_lpfc_log_verbose,
  465. &class_device_attr_lpfc_lun_queue_depth,
  466. &class_device_attr_lpfc_nodev_tmo,
  467. &class_device_attr_lpfc_fcp_class,
  468. &class_device_attr_lpfc_use_adisc,
  469. &class_device_attr_lpfc_ack0,
  470. &class_device_attr_lpfc_topology,
  471. &class_device_attr_lpfc_scan_down,
  472. &class_device_attr_lpfc_link_speed,
  473. &class_device_attr_lpfc_fdmi_on,
  474. &class_device_attr_lpfc_max_luns,
  475. &class_device_attr_nport_evt_cnt,
  476. &class_device_attr_management_version,
  477. &class_device_attr_board_online,
  478. NULL,
  479. };
  480. static ssize_t
  481. sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
  482. {
  483. size_t buf_off;
  484. struct Scsi_Host *host = class_to_shost(container_of(kobj,
  485. struct class_device, kobj));
  486. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  487. if ((off + count) > FF_REG_AREA_SIZE)
  488. return -ERANGE;
  489. if (count == 0) return 0;
  490. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  491. return -EINVAL;
  492. spin_lock_irq(phba->host->host_lock);
  493. if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
  494. spin_unlock_irq(phba->host->host_lock);
  495. return -EPERM;
  496. }
  497. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
  498. writel(*((uint32_t *)(buf + buf_off)),
  499. phba->ctrl_regs_memmap_p + off + buf_off);
  500. spin_unlock_irq(phba->host->host_lock);
  501. return count;
  502. }
  503. static ssize_t
  504. sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  505. {
  506. size_t buf_off;
  507. uint32_t * tmp_ptr;
  508. struct Scsi_Host *host = class_to_shost(container_of(kobj,
  509. struct class_device, kobj));
  510. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  511. if (off > FF_REG_AREA_SIZE)
  512. return -ERANGE;
  513. if ((off + count) > FF_REG_AREA_SIZE)
  514. count = FF_REG_AREA_SIZE - off;
  515. if (count == 0) return 0;
  516. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  517. return -EINVAL;
  518. spin_lock_irq(phba->host->host_lock);
  519. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
  520. tmp_ptr = (uint32_t *)(buf + buf_off);
  521. *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
  522. }
  523. spin_unlock_irq(phba->host->host_lock);
  524. return count;
  525. }
  526. static struct bin_attribute sysfs_ctlreg_attr = {
  527. .attr = {
  528. .name = "ctlreg",
  529. .mode = S_IRUSR | S_IWUSR,
  530. .owner = THIS_MODULE,
  531. },
  532. .size = 256,
  533. .read = sysfs_ctlreg_read,
  534. .write = sysfs_ctlreg_write,
  535. };
  536. static void
  537. sysfs_mbox_idle (struct lpfc_hba * phba)
  538. {
  539. phba->sysfs_mbox.state = SMBOX_IDLE;
  540. phba->sysfs_mbox.offset = 0;
  541. if (phba->sysfs_mbox.mbox) {
  542. mempool_free(phba->sysfs_mbox.mbox,
  543. phba->mbox_mem_pool);
  544. phba->sysfs_mbox.mbox = NULL;
  545. }
  546. }
  547. static ssize_t
  548. sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
  549. {
  550. struct Scsi_Host * host =
  551. class_to_shost(container_of(kobj, struct class_device, kobj));
  552. struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata[0];
  553. struct lpfcMboxq * mbox = NULL;
  554. if ((count + off) > MAILBOX_CMD_SIZE)
  555. return -ERANGE;
  556. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  557. return -EINVAL;
  558. if (count == 0)
  559. return 0;
  560. if (off == 0) {
  561. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  562. if (!mbox)
  563. return -ENOMEM;
  564. }
  565. spin_lock_irq(host->host_lock);
  566. if (off == 0) {
  567. if (phba->sysfs_mbox.mbox)
  568. mempool_free(mbox, phba->mbox_mem_pool);
  569. else
  570. phba->sysfs_mbox.mbox = mbox;
  571. phba->sysfs_mbox.state = SMBOX_WRITING;
  572. } else {
  573. if (phba->sysfs_mbox.state != SMBOX_WRITING ||
  574. phba->sysfs_mbox.offset != off ||
  575. phba->sysfs_mbox.mbox == NULL ) {
  576. sysfs_mbox_idle(phba);
  577. spin_unlock_irq(host->host_lock);
  578. return -EINVAL;
  579. }
  580. }
  581. memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
  582. buf, count);
  583. phba->sysfs_mbox.offset = off + count;
  584. spin_unlock_irq(host->host_lock);
  585. return count;
  586. }
  587. static ssize_t
  588. sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  589. {
  590. struct Scsi_Host *host =
  591. class_to_shost(container_of(kobj, struct class_device,
  592. kobj));
  593. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  594. int rc;
  595. if (off > sizeof(MAILBOX_t))
  596. return -ERANGE;
  597. if ((count + off) > sizeof(MAILBOX_t))
  598. count = sizeof(MAILBOX_t) - off;
  599. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  600. return -EINVAL;
  601. if (off && count == 0)
  602. return 0;
  603. spin_lock_irq(phba->host->host_lock);
  604. if (off == 0 &&
  605. phba->sysfs_mbox.state == SMBOX_WRITING &&
  606. phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
  607. switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
  608. /* Offline only */
  609. case MBX_WRITE_NV:
  610. case MBX_INIT_LINK:
  611. case MBX_DOWN_LINK:
  612. case MBX_CONFIG_LINK:
  613. case MBX_CONFIG_RING:
  614. case MBX_RESET_RING:
  615. case MBX_UNREG_LOGIN:
  616. case MBX_CLEAR_LA:
  617. case MBX_DUMP_CONTEXT:
  618. case MBX_RUN_DIAGS:
  619. case MBX_RESTART:
  620. case MBX_FLASH_WR_ULA:
  621. case MBX_SET_MASK:
  622. case MBX_SET_SLIM:
  623. case MBX_SET_DEBUG:
  624. if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
  625. printk(KERN_WARNING "mbox_read:Command 0x%x "
  626. "is illegal in on-line state\n",
  627. phba->sysfs_mbox.mbox->mb.mbxCommand);
  628. sysfs_mbox_idle(phba);
  629. spin_unlock_irq(phba->host->host_lock);
  630. return -EPERM;
  631. }
  632. case MBX_LOAD_SM:
  633. case MBX_READ_NV:
  634. case MBX_READ_CONFIG:
  635. case MBX_READ_RCONFIG:
  636. case MBX_READ_STATUS:
  637. case MBX_READ_XRI:
  638. case MBX_READ_REV:
  639. case MBX_READ_LNK_STAT:
  640. case MBX_DUMP_MEMORY:
  641. case MBX_DOWN_LOAD:
  642. case MBX_UPDATE_CFG:
  643. case MBX_LOAD_AREA:
  644. case MBX_LOAD_EXP_ROM:
  645. break;
  646. case MBX_READ_SPARM64:
  647. case MBX_READ_LA:
  648. case MBX_READ_LA64:
  649. case MBX_REG_LOGIN:
  650. case MBX_REG_LOGIN64:
  651. case MBX_CONFIG_PORT:
  652. case MBX_RUN_BIU_DIAG:
  653. printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
  654. phba->sysfs_mbox.mbox->mb.mbxCommand);
  655. sysfs_mbox_idle(phba);
  656. spin_unlock_irq(phba->host->host_lock);
  657. return -EPERM;
  658. default:
  659. printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
  660. phba->sysfs_mbox.mbox->mb.mbxCommand);
  661. sysfs_mbox_idle(phba);
  662. spin_unlock_irq(phba->host->host_lock);
  663. return -EPERM;
  664. }
  665. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  666. (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
  667. spin_unlock_irq(phba->host->host_lock);
  668. rc = lpfc_sli_issue_mbox (phba,
  669. phba->sysfs_mbox.mbox,
  670. MBX_POLL);
  671. spin_lock_irq(phba->host->host_lock);
  672. } else {
  673. spin_unlock_irq(phba->host->host_lock);
  674. rc = lpfc_sli_issue_mbox_wait (phba,
  675. phba->sysfs_mbox.mbox,
  676. phba->fc_ratov * 2);
  677. spin_lock_irq(phba->host->host_lock);
  678. }
  679. if (rc != MBX_SUCCESS) {
  680. sysfs_mbox_idle(phba);
  681. spin_unlock_irq(host->host_lock);
  682. return -ENODEV;
  683. }
  684. phba->sysfs_mbox.state = SMBOX_READING;
  685. }
  686. else if (phba->sysfs_mbox.offset != off ||
  687. phba->sysfs_mbox.state != SMBOX_READING) {
  688. printk(KERN_WARNING "mbox_read: Bad State\n");
  689. sysfs_mbox_idle(phba);
  690. spin_unlock_irq(host->host_lock);
  691. return -EINVAL;
  692. }
  693. memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
  694. phba->sysfs_mbox.offset = off + count;
  695. if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
  696. sysfs_mbox_idle(phba);
  697. spin_unlock_irq(phba->host->host_lock);
  698. return count;
  699. }
  700. static struct bin_attribute sysfs_mbox_attr = {
  701. .attr = {
  702. .name = "mbox",
  703. .mode = S_IRUSR | S_IWUSR,
  704. .owner = THIS_MODULE,
  705. },
  706. .size = sizeof(MAILBOX_t),
  707. .read = sysfs_mbox_read,
  708. .write = sysfs_mbox_write,
  709. };
  710. int
  711. lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
  712. {
  713. struct Scsi_Host *host = phba->host;
  714. int error;
  715. error = sysfs_create_bin_file(&host->shost_classdev.kobj,
  716. &sysfs_ctlreg_attr);
  717. if (error)
  718. goto out;
  719. error = sysfs_create_bin_file(&host->shost_classdev.kobj,
  720. &sysfs_mbox_attr);
  721. if (error)
  722. goto out_remove_ctlreg_attr;
  723. return 0;
  724. out_remove_ctlreg_attr:
  725. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
  726. out:
  727. return error;
  728. }
  729. void
  730. lpfc_free_sysfs_attr(struct lpfc_hba *phba)
  731. {
  732. struct Scsi_Host *host = phba->host;
  733. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
  734. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
  735. }
  736. /*
  737. * Dynamic FC Host Attributes Support
  738. */
  739. static void
  740. lpfc_get_host_port_id(struct Scsi_Host *shost)
  741. {
  742. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  743. /* note: fc_myDID already in cpu endianness */
  744. fc_host_port_id(shost) = phba->fc_myDID;
  745. }
  746. static void
  747. lpfc_get_host_port_type(struct Scsi_Host *shost)
  748. {
  749. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  750. spin_lock_irq(shost->host_lock);
  751. if (phba->hba_state == LPFC_HBA_READY) {
  752. if (phba->fc_topology == TOPOLOGY_LOOP) {
  753. if (phba->fc_flag & FC_PUBLIC_LOOP)
  754. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  755. else
  756. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  757. } else {
  758. if (phba->fc_flag & FC_FABRIC)
  759. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  760. else
  761. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  762. }
  763. } else
  764. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  765. spin_unlock_irq(shost->host_lock);
  766. }
  767. static void
  768. lpfc_get_host_port_state(struct Scsi_Host *shost)
  769. {
  770. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  771. spin_lock_irq(shost->host_lock);
  772. if (phba->fc_flag & FC_OFFLINE_MODE)
  773. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  774. else {
  775. switch (phba->hba_state) {
  776. case LPFC_INIT_START:
  777. case LPFC_INIT_MBX_CMDS:
  778. case LPFC_LINK_DOWN:
  779. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  780. break;
  781. case LPFC_LINK_UP:
  782. case LPFC_LOCAL_CFG_LINK:
  783. case LPFC_FLOGI:
  784. case LPFC_FABRIC_CFG_LINK:
  785. case LPFC_NS_REG:
  786. case LPFC_NS_QRY:
  787. case LPFC_BUILD_DISC_LIST:
  788. case LPFC_DISC_AUTH:
  789. case LPFC_CLEAR_LA:
  790. case LPFC_HBA_READY:
  791. /* Links up, beyond this port_type reports state */
  792. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  793. break;
  794. case LPFC_HBA_ERROR:
  795. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  796. break;
  797. default:
  798. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  799. break;
  800. }
  801. }
  802. spin_unlock_irq(shost->host_lock);
  803. }
  804. static void
  805. lpfc_get_host_speed(struct Scsi_Host *shost)
  806. {
  807. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  808. spin_lock_irq(shost->host_lock);
  809. if (phba->hba_state == LPFC_HBA_READY) {
  810. switch(phba->fc_linkspeed) {
  811. case LA_1GHZ_LINK:
  812. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  813. break;
  814. case LA_2GHZ_LINK:
  815. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  816. break;
  817. case LA_4GHZ_LINK:
  818. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  819. break;
  820. default:
  821. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  822. break;
  823. }
  824. }
  825. spin_unlock_irq(shost->host_lock);
  826. }
  827. static void
  828. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  829. {
  830. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  831. u64 node_name;
  832. spin_lock_irq(shost->host_lock);
  833. if ((phba->fc_flag & FC_FABRIC) ||
  834. ((phba->fc_topology == TOPOLOGY_LOOP) &&
  835. (phba->fc_flag & FC_PUBLIC_LOOP)))
  836. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  837. else
  838. /* fabric is local port if there is no F/FL_Port */
  839. node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
  840. spin_unlock_irq(shost->host_lock);
  841. fc_host_fabric_name(shost) = node_name;
  842. }
  843. static struct fc_host_statistics *
  844. lpfc_get_stats(struct Scsi_Host *shost)
  845. {
  846. struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
  847. struct lpfc_sli *psli = &phba->sli;
  848. struct fc_host_statistics *hs = &phba->link_stats;
  849. LPFC_MBOXQ_t *pmboxq;
  850. MAILBOX_t *pmb;
  851. int rc=0;
  852. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  853. if (!pmboxq)
  854. return NULL;
  855. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  856. pmb = &pmboxq->mb;
  857. pmb->mbxCommand = MBX_READ_STATUS;
  858. pmb->mbxOwner = OWN_HOST;
  859. pmboxq->context1 = NULL;
  860. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  861. (!(psli->sli_flag & LPFC_SLI2_ACTIVE))){
  862. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  863. } else
  864. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  865. if (rc != MBX_SUCCESS) {
  866. if (pmboxq) {
  867. if (rc == MBX_TIMEOUT)
  868. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  869. else
  870. mempool_free( pmboxq, phba->mbox_mem_pool);
  871. }
  872. return NULL;
  873. }
  874. memset(hs, 0, sizeof (struct fc_host_statistics));
  875. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  876. hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
  877. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  878. hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
  879. memset((void *)pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  880. pmb->mbxCommand = MBX_READ_LNK_STAT;
  881. pmb->mbxOwner = OWN_HOST;
  882. pmboxq->context1 = NULL;
  883. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  884. (!(psli->sli_flag & LPFC_SLI2_ACTIVE))) {
  885. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  886. } else
  887. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  888. if (rc != MBX_SUCCESS) {
  889. if (pmboxq) {
  890. if (rc == MBX_TIMEOUT)
  891. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  892. else
  893. mempool_free( pmboxq, phba->mbox_mem_pool);
  894. }
  895. return NULL;
  896. }
  897. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  898. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  899. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  900. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  901. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  902. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  903. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  904. if (phba->fc_topology == TOPOLOGY_LOOP) {
  905. hs->lip_count = (phba->fc_eventTag >> 1);
  906. hs->nos_count = -1;
  907. } else {
  908. hs->lip_count = -1;
  909. hs->nos_count = (phba->fc_eventTag >> 1);
  910. }
  911. hs->dumped_frames = -1;
  912. /* FIX ME */
  913. /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
  914. return hs;
  915. }
  916. /*
  917. * The LPFC driver treats linkdown handling as target loss events so there
  918. * are no sysfs handlers for link_down_tmo.
  919. */
  920. static void
  921. lpfc_get_starget_port_id(struct scsi_target *starget)
  922. {
  923. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  924. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
  925. uint32_t did = -1;
  926. struct lpfc_nodelist *ndlp = NULL;
  927. spin_lock_irq(shost->host_lock);
  928. /* Search the mapped list for this target ID */
  929. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  930. if (starget->id == ndlp->nlp_sid) {
  931. did = ndlp->nlp_DID;
  932. break;
  933. }
  934. }
  935. spin_unlock_irq(shost->host_lock);
  936. fc_starget_port_id(starget) = did;
  937. }
  938. static void
  939. lpfc_get_starget_node_name(struct scsi_target *starget)
  940. {
  941. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  942. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
  943. u64 node_name = 0;
  944. struct lpfc_nodelist *ndlp = NULL;
  945. spin_lock_irq(shost->host_lock);
  946. /* Search the mapped list for this target ID */
  947. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  948. if (starget->id == ndlp->nlp_sid) {
  949. node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  950. break;
  951. }
  952. }
  953. spin_unlock_irq(shost->host_lock);
  954. fc_starget_node_name(starget) = node_name;
  955. }
  956. static void
  957. lpfc_get_starget_port_name(struct scsi_target *starget)
  958. {
  959. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  960. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
  961. u64 port_name = 0;
  962. struct lpfc_nodelist *ndlp = NULL;
  963. spin_lock_irq(shost->host_lock);
  964. /* Search the mapped list for this target ID */
  965. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  966. if (starget->id == ndlp->nlp_sid) {
  967. port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  968. break;
  969. }
  970. }
  971. spin_unlock_irq(shost->host_lock);
  972. fc_starget_port_name(starget) = port_name;
  973. }
  974. static void
  975. lpfc_get_rport_loss_tmo(struct fc_rport *rport)
  976. {
  977. /*
  978. * Return the driver's global value for device loss timeout plus
  979. * five seconds to allow the driver's nodev timer to run.
  980. */
  981. rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
  982. }
  983. static void
  984. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  985. {
  986. /*
  987. * The driver doesn't have a per-target timeout setting. Set
  988. * this value globally. lpfc_nodev_tmo should be greater then 0.
  989. */
  990. if (timeout)
  991. lpfc_nodev_tmo = timeout;
  992. else
  993. lpfc_nodev_tmo = 1;
  994. rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
  995. }
  996. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  997. static ssize_t \
  998. lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
  999. { \
  1000. struct fc_rport *rport = transport_class_to_rport(cdev); \
  1001. struct lpfc_rport_data *rdata = rport->hostdata; \
  1002. return snprintf(buf, sz, format_string, \
  1003. (rdata->target) ? cast rdata->target->field : 0); \
  1004. }
  1005. #define lpfc_rport_rd_attr(field, format_string, sz) \
  1006. lpfc_rport_show_function(field, format_string, sz, ) \
  1007. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  1008. struct fc_function_template lpfc_transport_functions = {
  1009. /* fixed attributes the driver supports */
  1010. .show_host_node_name = 1,
  1011. .show_host_port_name = 1,
  1012. .show_host_supported_classes = 1,
  1013. .show_host_supported_fc4s = 1,
  1014. .show_host_symbolic_name = 1,
  1015. .show_host_supported_speeds = 1,
  1016. .show_host_maxframe_size = 1,
  1017. /* dynamic attributes the driver supports */
  1018. .get_host_port_id = lpfc_get_host_port_id,
  1019. .show_host_port_id = 1,
  1020. .get_host_port_type = lpfc_get_host_port_type,
  1021. .show_host_port_type = 1,
  1022. .get_host_port_state = lpfc_get_host_port_state,
  1023. .show_host_port_state = 1,
  1024. /* active_fc4s is shown but doesn't change (thus no get function) */
  1025. .show_host_active_fc4s = 1,
  1026. .get_host_speed = lpfc_get_host_speed,
  1027. .show_host_speed = 1,
  1028. .get_host_fabric_name = lpfc_get_host_fabric_name,
  1029. .show_host_fabric_name = 1,
  1030. /*
  1031. * The LPFC driver treats linkdown handling as target loss events
  1032. * so there are no sysfs handlers for link_down_tmo.
  1033. */
  1034. .get_fc_host_stats = lpfc_get_stats,
  1035. /* the LPFC driver doesn't support resetting stats yet */
  1036. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  1037. .show_rport_maxframe_size = 1,
  1038. .show_rport_supported_classes = 1,
  1039. .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
  1040. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  1041. .show_rport_dev_loss_tmo = 1,
  1042. .get_starget_port_id = lpfc_get_starget_port_id,
  1043. .show_starget_port_id = 1,
  1044. .get_starget_node_name = lpfc_get_starget_node_name,
  1045. .show_starget_node_name = 1,
  1046. .get_starget_port_name = lpfc_get_starget_port_name,
  1047. .show_starget_port_name = 1,
  1048. .issue_fc_host_lip = lpfc_issue_lip,
  1049. };
  1050. void
  1051. lpfc_get_cfgparam(struct lpfc_hba *phba)
  1052. {
  1053. phba->cfg_log_verbose = lpfc_log_verbose;
  1054. phba->cfg_cr_delay = lpfc_cr_delay;
  1055. phba->cfg_cr_count = lpfc_cr_count;
  1056. phba->cfg_lun_queue_depth = lpfc_lun_queue_depth;
  1057. phba->cfg_fcp_class = lpfc_fcp_class;
  1058. phba->cfg_use_adisc = lpfc_use_adisc;
  1059. phba->cfg_ack0 = lpfc_ack0;
  1060. phba->cfg_topology = lpfc_topology;
  1061. phba->cfg_scan_down = lpfc_scan_down;
  1062. phba->cfg_nodev_tmo = lpfc_nodev_tmo;
  1063. phba->cfg_link_speed = lpfc_link_speed;
  1064. phba->cfg_fdmi_on = lpfc_fdmi_on;
  1065. phba->cfg_discovery_threads = lpfc_discovery_threads;
  1066. phba->cfg_max_luns = lpfc_max_luns;
  1067. /*
  1068. * The total number of segments is the configuration value plus 2
  1069. * since the IOCB need a command and response bde.
  1070. */
  1071. phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
  1072. /*
  1073. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  1074. * used to create the sg_dma_buf_pool must be dynamically calculated
  1075. */
  1076. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  1077. sizeof(struct fcp_rsp) +
  1078. (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
  1079. switch (phba->pcidev->device) {
  1080. case PCI_DEVICE_ID_LP101:
  1081. case PCI_DEVICE_ID_BSMB:
  1082. case PCI_DEVICE_ID_ZSMB:
  1083. phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
  1084. break;
  1085. case PCI_DEVICE_ID_RFLY:
  1086. case PCI_DEVICE_ID_PFLY:
  1087. case PCI_DEVICE_ID_BMID:
  1088. case PCI_DEVICE_ID_ZMID:
  1089. case PCI_DEVICE_ID_TFLY:
  1090. phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
  1091. break;
  1092. default:
  1093. phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
  1094. }
  1095. return;
  1096. }