lpfc_attr.c 36 KB

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