lpfc_attr.c 37 KB

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