lpfc_attr.c 40 KB

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