lpfc_attr.c 36 KB

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