lpfc_attr.c 36 KB

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