lpfc_attr.c 36 KB

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