lpfc_attr.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  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. # hba_queue_depth: This parameter is used to limit the number of outstanding
  462. # commands per lpfc HBA. Value range is [32,8192]. If this parameter
  463. # value is greater than the maximum number of exchanges supported by the HBA,
  464. # then maximum number of exchanges supported by the HBA is used to determine
  465. # the hba_queue_depth.
  466. */
  467. LPFC_ATTR_R(hba_queue_depth, 8192, 32, 8192,
  468. "Max number of FCP commands we can queue to a lpfc HBA");
  469. /*
  470. # Some disk devices have a "select ID" or "select Target" capability.
  471. # From a protocol standpoint "select ID" usually means select the
  472. # Fibre channel "ALPA". In the FC-AL Profile there is an "informative
  473. # annex" which contains a table that maps a "select ID" (a number
  474. # between 0 and 7F) to an ALPA. By default, for compatibility with
  475. # older drivers, the lpfc driver scans this table from low ALPA to high
  476. # ALPA.
  477. #
  478. # Turning on the scan-down variable (on = 1, off = 0) will
  479. # cause the lpfc driver to use an inverted table, effectively
  480. # scanning ALPAs from high to low. Value range is [0,1]. Default value is 1.
  481. #
  482. # (Note: This "select ID" functionality is a LOOP ONLY characteristic
  483. # and will not work across a fabric. Also this parameter will take
  484. # effect only in the case when ALPA map is not available.)
  485. */
  486. LPFC_ATTR_R(scan_down, 1, 0, 1,
  487. "Start scanning for devices from highest ALPA to lowest");
  488. /*
  489. # lpfc_nodev_tmo: If set, it will hold all I/O errors on devices that disappear
  490. # until the timer expires. Value range is [0,255]. Default value is 30.
  491. # NOTE: this MUST be less then the SCSI Layer command timeout - 1.
  492. */
  493. LPFC_ATTR_RW(nodev_tmo, 30, 0, 255,
  494. "Seconds driver will hold I/O waiting for a device to come back");
  495. /*
  496. # lpfc_topology: link topology for init link
  497. # 0x0 = attempt loop mode then point-to-point
  498. # 0x02 = attempt point-to-point mode only
  499. # 0x04 = attempt loop mode only
  500. # 0x06 = attempt point-to-point mode then loop
  501. # Set point-to-point mode if you want to run as an N_Port.
  502. # Set loop mode if you want to run as an NL_Port. Value range is [0,0x6].
  503. # Default value is 0.
  504. */
  505. LPFC_ATTR_R(topology, 0, 0, 6, "Select Fibre Channel topology");
  506. /*
  507. # lpfc_link_speed: Link speed selection for initializing the Fibre Channel
  508. # connection.
  509. # 0 = auto select (default)
  510. # 1 = 1 Gigabaud
  511. # 2 = 2 Gigabaud
  512. # 4 = 4 Gigabaud
  513. # Value range is [0,4]. Default value is 0.
  514. */
  515. LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed");
  516. /*
  517. # lpfc_fcp_class: Determines FC class to use for the FCP protocol.
  518. # Value range is [2,3]. Default value is 3.
  519. */
  520. LPFC_ATTR_R(fcp_class, 3, 2, 3,
  521. "Select Fibre Channel class of service for FCP sequences");
  522. /*
  523. # lpfc_use_adisc: Use ADISC for FCP rediscovery instead of PLOGI. Value range
  524. # is [0,1]. Default value is 0.
  525. */
  526. LPFC_ATTR_RW(use_adisc, 0, 0, 1,
  527. "Use ADISC on rediscovery to authenticate FCP devices");
  528. /*
  529. # lpfc_ack0: Use ACK0, instead of ACK1 for class 2 acknowledgement. Value
  530. # range is [0,1]. Default value is 0.
  531. */
  532. LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
  533. /*
  534. # lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
  535. # cr_delay (msec) or cr_count outstanding commands. cr_delay can take
  536. # value [0,63]. cr_count can take value [0,255]. Default value of cr_delay
  537. # is 0. Default value of cr_count is 1. The cr_count feature is disabled if
  538. # cr_delay is set to 0.
  539. */
  540. LPFC_ATTR_RW(cr_delay, 0, 0, 63, "A count of milliseconds after which an"
  541. "interrupt response is generated");
  542. LPFC_ATTR_RW(cr_count, 1, 1, 255, "A count of I/O completions after which an"
  543. "interrupt response is generated");
  544. /*
  545. # lpfc_fdmi_on: controls FDMI support.
  546. # 0 = no FDMI support
  547. # 1 = support FDMI without attribute of hostname
  548. # 2 = support FDMI with attribute of hostname
  549. # Value range [0,2]. Default value is 0.
  550. */
  551. LPFC_ATTR_RW(fdmi_on, 0, 0, 2, "Enable FDMI support");
  552. /*
  553. # Specifies the maximum number of ELS cmds we can have outstanding (for
  554. # discovery). Value range is [1,64]. Default value = 32.
  555. */
  556. LPFC_ATTR(discovery_threads, 32, 1, 64, "Maximum number of ELS commands"
  557. "during discovery");
  558. /*
  559. # lpfc_max_luns: maximum number of LUNs per target driver will support
  560. # Value range is [1,32768]. Default value is 256.
  561. # NOTE: The SCSI layer will scan each target for this many luns
  562. */
  563. LPFC_ATTR_R(max_luns, 256, 1, 32768,
  564. "Maximum number of LUNs per target driver will support");
  565. /*
  566. # lpfc_poll_tmo: .Milliseconds driver will wait between polling FCP ring.
  567. # Value range is [1,255], default value is 10.
  568. */
  569. LPFC_ATTR_RW(poll_tmo, 10, 1, 255,
  570. "Milliseconds driver will wait between polling FCP ring");
  571. struct class_device_attribute *lpfc_host_attrs[] = {
  572. &class_device_attr_info,
  573. &class_device_attr_serialnum,
  574. &class_device_attr_modeldesc,
  575. &class_device_attr_modelname,
  576. &class_device_attr_programtype,
  577. &class_device_attr_portnum,
  578. &class_device_attr_fwrev,
  579. &class_device_attr_hdw,
  580. &class_device_attr_option_rom_version,
  581. &class_device_attr_state,
  582. &class_device_attr_num_discovered_ports,
  583. &class_device_attr_lpfc_drvr_version,
  584. &class_device_attr_lpfc_log_verbose,
  585. &class_device_attr_lpfc_lun_queue_depth,
  586. &class_device_attr_lpfc_hba_queue_depth,
  587. &class_device_attr_lpfc_nodev_tmo,
  588. &class_device_attr_lpfc_fcp_class,
  589. &class_device_attr_lpfc_use_adisc,
  590. &class_device_attr_lpfc_ack0,
  591. &class_device_attr_lpfc_topology,
  592. &class_device_attr_lpfc_scan_down,
  593. &class_device_attr_lpfc_link_speed,
  594. &class_device_attr_lpfc_cr_delay,
  595. &class_device_attr_lpfc_cr_count,
  596. &class_device_attr_lpfc_fdmi_on,
  597. &class_device_attr_lpfc_max_luns,
  598. &class_device_attr_nport_evt_cnt,
  599. &class_device_attr_management_version,
  600. &class_device_attr_board_online,
  601. &class_device_attr_lpfc_poll,
  602. &class_device_attr_lpfc_poll_tmo,
  603. NULL,
  604. };
  605. static ssize_t
  606. sysfs_ctlreg_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
  607. {
  608. size_t buf_off;
  609. struct Scsi_Host *host = class_to_shost(container_of(kobj,
  610. struct class_device, kobj));
  611. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  612. if ((off + count) > FF_REG_AREA_SIZE)
  613. return -ERANGE;
  614. if (count == 0) return 0;
  615. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  616. return -EINVAL;
  617. spin_lock_irq(phba->host->host_lock);
  618. if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
  619. spin_unlock_irq(phba->host->host_lock);
  620. return -EPERM;
  621. }
  622. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t))
  623. writel(*((uint32_t *)(buf + buf_off)),
  624. phba->ctrl_regs_memmap_p + off + buf_off);
  625. spin_unlock_irq(phba->host->host_lock);
  626. return count;
  627. }
  628. static ssize_t
  629. sysfs_ctlreg_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  630. {
  631. size_t buf_off;
  632. uint32_t * tmp_ptr;
  633. struct Scsi_Host *host = class_to_shost(container_of(kobj,
  634. struct class_device, kobj));
  635. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  636. if (off > FF_REG_AREA_SIZE)
  637. return -ERANGE;
  638. if ((off + count) > FF_REG_AREA_SIZE)
  639. count = FF_REG_AREA_SIZE - off;
  640. if (count == 0) return 0;
  641. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  642. return -EINVAL;
  643. spin_lock_irq(phba->host->host_lock);
  644. for (buf_off = 0; buf_off < count; buf_off += sizeof(uint32_t)) {
  645. tmp_ptr = (uint32_t *)(buf + buf_off);
  646. *tmp_ptr = readl(phba->ctrl_regs_memmap_p + off + buf_off);
  647. }
  648. spin_unlock_irq(phba->host->host_lock);
  649. return count;
  650. }
  651. static struct bin_attribute sysfs_ctlreg_attr = {
  652. .attr = {
  653. .name = "ctlreg",
  654. .mode = S_IRUSR | S_IWUSR,
  655. .owner = THIS_MODULE,
  656. },
  657. .size = 256,
  658. .read = sysfs_ctlreg_read,
  659. .write = sysfs_ctlreg_write,
  660. };
  661. static void
  662. sysfs_mbox_idle (struct lpfc_hba * phba)
  663. {
  664. phba->sysfs_mbox.state = SMBOX_IDLE;
  665. phba->sysfs_mbox.offset = 0;
  666. if (phba->sysfs_mbox.mbox) {
  667. mempool_free(phba->sysfs_mbox.mbox,
  668. phba->mbox_mem_pool);
  669. phba->sysfs_mbox.mbox = NULL;
  670. }
  671. }
  672. static ssize_t
  673. sysfs_mbox_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
  674. {
  675. struct Scsi_Host * host =
  676. class_to_shost(container_of(kobj, struct class_device, kobj));
  677. struct lpfc_hba * phba = (struct lpfc_hba*)host->hostdata[0];
  678. struct lpfcMboxq * mbox = NULL;
  679. if ((count + off) > MAILBOX_CMD_SIZE)
  680. return -ERANGE;
  681. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  682. return -EINVAL;
  683. if (count == 0)
  684. return 0;
  685. if (off == 0) {
  686. mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  687. if (!mbox)
  688. return -ENOMEM;
  689. }
  690. spin_lock_irq(host->host_lock);
  691. if (off == 0) {
  692. if (phba->sysfs_mbox.mbox)
  693. mempool_free(mbox, phba->mbox_mem_pool);
  694. else
  695. phba->sysfs_mbox.mbox = mbox;
  696. phba->sysfs_mbox.state = SMBOX_WRITING;
  697. } else {
  698. if (phba->sysfs_mbox.state != SMBOX_WRITING ||
  699. phba->sysfs_mbox.offset != off ||
  700. phba->sysfs_mbox.mbox == NULL ) {
  701. sysfs_mbox_idle(phba);
  702. spin_unlock_irq(host->host_lock);
  703. return -EINVAL;
  704. }
  705. }
  706. memcpy((uint8_t *) & phba->sysfs_mbox.mbox->mb + off,
  707. buf, count);
  708. phba->sysfs_mbox.offset = off + count;
  709. spin_unlock_irq(host->host_lock);
  710. return count;
  711. }
  712. static ssize_t
  713. sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
  714. {
  715. struct Scsi_Host *host =
  716. class_to_shost(container_of(kobj, struct class_device,
  717. kobj));
  718. struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata[0];
  719. int rc;
  720. if (off > sizeof(MAILBOX_t))
  721. return -ERANGE;
  722. if ((count + off) > sizeof(MAILBOX_t))
  723. count = sizeof(MAILBOX_t) - off;
  724. if (off % 4 || count % 4 || (unsigned long)buf % 4)
  725. return -EINVAL;
  726. if (off && count == 0)
  727. return 0;
  728. spin_lock_irq(phba->host->host_lock);
  729. if (off == 0 &&
  730. phba->sysfs_mbox.state == SMBOX_WRITING &&
  731. phba->sysfs_mbox.offset >= 2 * sizeof(uint32_t)) {
  732. switch (phba->sysfs_mbox.mbox->mb.mbxCommand) {
  733. /* Offline only */
  734. case MBX_WRITE_NV:
  735. case MBX_INIT_LINK:
  736. case MBX_DOWN_LINK:
  737. case MBX_CONFIG_LINK:
  738. case MBX_CONFIG_RING:
  739. case MBX_RESET_RING:
  740. case MBX_UNREG_LOGIN:
  741. case MBX_CLEAR_LA:
  742. case MBX_DUMP_CONTEXT:
  743. case MBX_RUN_DIAGS:
  744. case MBX_RESTART:
  745. case MBX_FLASH_WR_ULA:
  746. case MBX_SET_MASK:
  747. case MBX_SET_SLIM:
  748. case MBX_SET_DEBUG:
  749. if (!(phba->fc_flag & FC_OFFLINE_MODE)) {
  750. printk(KERN_WARNING "mbox_read:Command 0x%x "
  751. "is illegal in on-line state\n",
  752. phba->sysfs_mbox.mbox->mb.mbxCommand);
  753. sysfs_mbox_idle(phba);
  754. spin_unlock_irq(phba->host->host_lock);
  755. return -EPERM;
  756. }
  757. case MBX_LOAD_SM:
  758. case MBX_READ_NV:
  759. case MBX_READ_CONFIG:
  760. case MBX_READ_RCONFIG:
  761. case MBX_READ_STATUS:
  762. case MBX_READ_XRI:
  763. case MBX_READ_REV:
  764. case MBX_READ_LNK_STAT:
  765. case MBX_DUMP_MEMORY:
  766. case MBX_DOWN_LOAD:
  767. case MBX_UPDATE_CFG:
  768. case MBX_LOAD_AREA:
  769. case MBX_LOAD_EXP_ROM:
  770. break;
  771. case MBX_READ_SPARM64:
  772. case MBX_READ_LA:
  773. case MBX_READ_LA64:
  774. case MBX_REG_LOGIN:
  775. case MBX_REG_LOGIN64:
  776. case MBX_CONFIG_PORT:
  777. case MBX_RUN_BIU_DIAG:
  778. printk(KERN_WARNING "mbox_read: Illegal Command 0x%x\n",
  779. phba->sysfs_mbox.mbox->mb.mbxCommand);
  780. sysfs_mbox_idle(phba);
  781. spin_unlock_irq(phba->host->host_lock);
  782. return -EPERM;
  783. default:
  784. printk(KERN_WARNING "mbox_read: Unknown Command 0x%x\n",
  785. phba->sysfs_mbox.mbox->mb.mbxCommand);
  786. sysfs_mbox_idle(phba);
  787. spin_unlock_irq(phba->host->host_lock);
  788. return -EPERM;
  789. }
  790. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  791. (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
  792. spin_unlock_irq(phba->host->host_lock);
  793. rc = lpfc_sli_issue_mbox (phba,
  794. phba->sysfs_mbox.mbox,
  795. MBX_POLL);
  796. spin_lock_irq(phba->host->host_lock);
  797. } else {
  798. spin_unlock_irq(phba->host->host_lock);
  799. rc = lpfc_sli_issue_mbox_wait (phba,
  800. phba->sysfs_mbox.mbox,
  801. phba->fc_ratov * 2);
  802. spin_lock_irq(phba->host->host_lock);
  803. }
  804. if (rc != MBX_SUCCESS) {
  805. sysfs_mbox_idle(phba);
  806. spin_unlock_irq(host->host_lock);
  807. return -ENODEV;
  808. }
  809. phba->sysfs_mbox.state = SMBOX_READING;
  810. }
  811. else if (phba->sysfs_mbox.offset != off ||
  812. phba->sysfs_mbox.state != SMBOX_READING) {
  813. printk(KERN_WARNING "mbox_read: Bad State\n");
  814. sysfs_mbox_idle(phba);
  815. spin_unlock_irq(host->host_lock);
  816. return -EINVAL;
  817. }
  818. memcpy(buf, (uint8_t *) & phba->sysfs_mbox.mbox->mb + off, count);
  819. phba->sysfs_mbox.offset = off + count;
  820. if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t))
  821. sysfs_mbox_idle(phba);
  822. spin_unlock_irq(phba->host->host_lock);
  823. return count;
  824. }
  825. static struct bin_attribute sysfs_mbox_attr = {
  826. .attr = {
  827. .name = "mbox",
  828. .mode = S_IRUSR | S_IWUSR,
  829. .owner = THIS_MODULE,
  830. },
  831. .size = sizeof(MAILBOX_t),
  832. .read = sysfs_mbox_read,
  833. .write = sysfs_mbox_write,
  834. };
  835. int
  836. lpfc_alloc_sysfs_attr(struct lpfc_hba *phba)
  837. {
  838. struct Scsi_Host *host = phba->host;
  839. int error;
  840. error = sysfs_create_bin_file(&host->shost_classdev.kobj,
  841. &sysfs_ctlreg_attr);
  842. if (error)
  843. goto out;
  844. error = sysfs_create_bin_file(&host->shost_classdev.kobj,
  845. &sysfs_mbox_attr);
  846. if (error)
  847. goto out_remove_ctlreg_attr;
  848. return 0;
  849. out_remove_ctlreg_attr:
  850. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
  851. out:
  852. return error;
  853. }
  854. void
  855. lpfc_free_sysfs_attr(struct lpfc_hba *phba)
  856. {
  857. struct Scsi_Host *host = phba->host;
  858. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_mbox_attr);
  859. sysfs_remove_bin_file(&host->shost_classdev.kobj, &sysfs_ctlreg_attr);
  860. }
  861. /*
  862. * Dynamic FC Host Attributes Support
  863. */
  864. static void
  865. lpfc_get_host_port_id(struct Scsi_Host *shost)
  866. {
  867. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  868. /* note: fc_myDID already in cpu endianness */
  869. fc_host_port_id(shost) = phba->fc_myDID;
  870. }
  871. static void
  872. lpfc_get_host_port_type(struct Scsi_Host *shost)
  873. {
  874. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  875. spin_lock_irq(shost->host_lock);
  876. if (phba->hba_state == LPFC_HBA_READY) {
  877. if (phba->fc_topology == TOPOLOGY_LOOP) {
  878. if (phba->fc_flag & FC_PUBLIC_LOOP)
  879. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  880. else
  881. fc_host_port_type(shost) = FC_PORTTYPE_LPORT;
  882. } else {
  883. if (phba->fc_flag & FC_FABRIC)
  884. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  885. else
  886. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  887. }
  888. } else
  889. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  890. spin_unlock_irq(shost->host_lock);
  891. }
  892. static void
  893. lpfc_get_host_port_state(struct Scsi_Host *shost)
  894. {
  895. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  896. spin_lock_irq(shost->host_lock);
  897. if (phba->fc_flag & FC_OFFLINE_MODE)
  898. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  899. else {
  900. switch (phba->hba_state) {
  901. case LPFC_INIT_START:
  902. case LPFC_INIT_MBX_CMDS:
  903. case LPFC_LINK_DOWN:
  904. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  905. break;
  906. case LPFC_LINK_UP:
  907. case LPFC_LOCAL_CFG_LINK:
  908. case LPFC_FLOGI:
  909. case LPFC_FABRIC_CFG_LINK:
  910. case LPFC_NS_REG:
  911. case LPFC_NS_QRY:
  912. case LPFC_BUILD_DISC_LIST:
  913. case LPFC_DISC_AUTH:
  914. case LPFC_CLEAR_LA:
  915. case LPFC_HBA_READY:
  916. /* Links up, beyond this port_type reports state */
  917. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  918. break;
  919. case LPFC_HBA_ERROR:
  920. fc_host_port_state(shost) = FC_PORTSTATE_ERROR;
  921. break;
  922. default:
  923. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  924. break;
  925. }
  926. }
  927. spin_unlock_irq(shost->host_lock);
  928. }
  929. static void
  930. lpfc_get_host_speed(struct Scsi_Host *shost)
  931. {
  932. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  933. spin_lock_irq(shost->host_lock);
  934. if (phba->hba_state == LPFC_HBA_READY) {
  935. switch(phba->fc_linkspeed) {
  936. case LA_1GHZ_LINK:
  937. fc_host_speed(shost) = FC_PORTSPEED_1GBIT;
  938. break;
  939. case LA_2GHZ_LINK:
  940. fc_host_speed(shost) = FC_PORTSPEED_2GBIT;
  941. break;
  942. case LA_4GHZ_LINK:
  943. fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
  944. break;
  945. default:
  946. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  947. break;
  948. }
  949. }
  950. spin_unlock_irq(shost->host_lock);
  951. }
  952. static void
  953. lpfc_get_host_fabric_name (struct Scsi_Host *shost)
  954. {
  955. struct lpfc_hba *phba = (struct lpfc_hba*)shost->hostdata[0];
  956. u64 node_name;
  957. spin_lock_irq(shost->host_lock);
  958. if ((phba->fc_flag & FC_FABRIC) ||
  959. ((phba->fc_topology == TOPOLOGY_LOOP) &&
  960. (phba->fc_flag & FC_PUBLIC_LOOP)))
  961. node_name = wwn_to_u64(phba->fc_fabparam.nodeName.u.wwn);
  962. else
  963. /* fabric is local port if there is no F/FL_Port */
  964. node_name = wwn_to_u64(phba->fc_nodename.u.wwn);
  965. spin_unlock_irq(shost->host_lock);
  966. fc_host_fabric_name(shost) = node_name;
  967. }
  968. static struct fc_host_statistics *
  969. lpfc_get_stats(struct Scsi_Host *shost)
  970. {
  971. struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata[0];
  972. struct lpfc_sli *psli = &phba->sli;
  973. struct fc_host_statistics *hs = &phba->link_stats;
  974. LPFC_MBOXQ_t *pmboxq;
  975. MAILBOX_t *pmb;
  976. int rc = 0;
  977. pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
  978. if (!pmboxq)
  979. return NULL;
  980. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  981. pmb = &pmboxq->mb;
  982. pmb->mbxCommand = MBX_READ_STATUS;
  983. pmb->mbxOwner = OWN_HOST;
  984. pmboxq->context1 = NULL;
  985. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  986. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  987. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  988. else
  989. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  990. if (rc != MBX_SUCCESS) {
  991. if (rc == MBX_TIMEOUT)
  992. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  993. else
  994. mempool_free(pmboxq, phba->mbox_mem_pool);
  995. return NULL;
  996. }
  997. memset(hs, 0, sizeof (struct fc_host_statistics));
  998. hs->tx_frames = pmb->un.varRdStatus.xmitFrameCnt;
  999. hs->tx_words = (pmb->un.varRdStatus.xmitByteCnt * 256);
  1000. hs->rx_frames = pmb->un.varRdStatus.rcvFrameCnt;
  1001. hs->rx_words = (pmb->un.varRdStatus.rcvByteCnt * 256);
  1002. memset(pmboxq, 0, sizeof (LPFC_MBOXQ_t));
  1003. pmb->mbxCommand = MBX_READ_LNK_STAT;
  1004. pmb->mbxOwner = OWN_HOST;
  1005. pmboxq->context1 = NULL;
  1006. if ((phba->fc_flag & FC_OFFLINE_MODE) ||
  1007. (!(psli->sli_flag & LPFC_SLI2_ACTIVE)))
  1008. rc = lpfc_sli_issue_mbox(phba, pmboxq, MBX_POLL);
  1009. else
  1010. rc = lpfc_sli_issue_mbox_wait(phba, pmboxq, phba->fc_ratov * 2);
  1011. if (rc != MBX_SUCCESS) {
  1012. if (rc == MBX_TIMEOUT)
  1013. pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
  1014. else
  1015. mempool_free( pmboxq, phba->mbox_mem_pool);
  1016. return NULL;
  1017. }
  1018. hs->link_failure_count = pmb->un.varRdLnk.linkFailureCnt;
  1019. hs->loss_of_sync_count = pmb->un.varRdLnk.lossSyncCnt;
  1020. hs->loss_of_signal_count = pmb->un.varRdLnk.lossSignalCnt;
  1021. hs->prim_seq_protocol_err_count = pmb->un.varRdLnk.primSeqErrCnt;
  1022. hs->invalid_tx_word_count = pmb->un.varRdLnk.invalidXmitWord;
  1023. hs->invalid_crc_count = pmb->un.varRdLnk.crcCnt;
  1024. hs->error_frames = pmb->un.varRdLnk.crcCnt;
  1025. if (phba->fc_topology == TOPOLOGY_LOOP) {
  1026. hs->lip_count = (phba->fc_eventTag >> 1);
  1027. hs->nos_count = -1;
  1028. } else {
  1029. hs->lip_count = -1;
  1030. hs->nos_count = (phba->fc_eventTag >> 1);
  1031. }
  1032. hs->dumped_frames = -1;
  1033. /* FIX ME */
  1034. /*hs->SecondsSinceLastReset = (jiffies - lpfc_loadtime) / HZ;*/
  1035. return hs;
  1036. }
  1037. /*
  1038. * The LPFC driver treats linkdown handling as target loss events so there
  1039. * are no sysfs handlers for link_down_tmo.
  1040. */
  1041. static void
  1042. lpfc_get_starget_port_id(struct scsi_target *starget)
  1043. {
  1044. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1045. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
  1046. uint32_t did = -1;
  1047. struct lpfc_nodelist *ndlp = NULL;
  1048. spin_lock_irq(shost->host_lock);
  1049. /* Search the mapped list for this target ID */
  1050. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1051. if (starget->id == ndlp->nlp_sid) {
  1052. did = ndlp->nlp_DID;
  1053. break;
  1054. }
  1055. }
  1056. spin_unlock_irq(shost->host_lock);
  1057. fc_starget_port_id(starget) = did;
  1058. }
  1059. static void
  1060. lpfc_get_starget_node_name(struct scsi_target *starget)
  1061. {
  1062. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1063. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
  1064. u64 node_name = 0;
  1065. struct lpfc_nodelist *ndlp = NULL;
  1066. spin_lock_irq(shost->host_lock);
  1067. /* Search the mapped list for this target ID */
  1068. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1069. if (starget->id == ndlp->nlp_sid) {
  1070. node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
  1071. break;
  1072. }
  1073. }
  1074. spin_unlock_irq(shost->host_lock);
  1075. fc_starget_node_name(starget) = node_name;
  1076. }
  1077. static void
  1078. lpfc_get_starget_port_name(struct scsi_target *starget)
  1079. {
  1080. struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
  1081. struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata[0];
  1082. u64 port_name = 0;
  1083. struct lpfc_nodelist *ndlp = NULL;
  1084. spin_lock_irq(shost->host_lock);
  1085. /* Search the mapped list for this target ID */
  1086. list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
  1087. if (starget->id == ndlp->nlp_sid) {
  1088. port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
  1089. break;
  1090. }
  1091. }
  1092. spin_unlock_irq(shost->host_lock);
  1093. fc_starget_port_name(starget) = port_name;
  1094. }
  1095. static void
  1096. lpfc_get_rport_loss_tmo(struct fc_rport *rport)
  1097. {
  1098. /*
  1099. * Return the driver's global value for device loss timeout plus
  1100. * five seconds to allow the driver's nodev timer to run.
  1101. */
  1102. rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
  1103. }
  1104. static void
  1105. lpfc_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1106. {
  1107. /*
  1108. * The driver doesn't have a per-target timeout setting. Set
  1109. * this value globally. lpfc_nodev_tmo should be greater then 0.
  1110. */
  1111. if (timeout)
  1112. lpfc_nodev_tmo = timeout;
  1113. else
  1114. lpfc_nodev_tmo = 1;
  1115. rport->dev_loss_tmo = lpfc_nodev_tmo + 5;
  1116. }
  1117. #define lpfc_rport_show_function(field, format_string, sz, cast) \
  1118. static ssize_t \
  1119. lpfc_show_rport_##field (struct class_device *cdev, char *buf) \
  1120. { \
  1121. struct fc_rport *rport = transport_class_to_rport(cdev); \
  1122. struct lpfc_rport_data *rdata = rport->hostdata; \
  1123. return snprintf(buf, sz, format_string, \
  1124. (rdata->target) ? cast rdata->target->field : 0); \
  1125. }
  1126. #define lpfc_rport_rd_attr(field, format_string, sz) \
  1127. lpfc_rport_show_function(field, format_string, sz, ) \
  1128. static FC_RPORT_ATTR(field, S_IRUGO, lpfc_show_rport_##field, NULL)
  1129. struct fc_function_template lpfc_transport_functions = {
  1130. /* fixed attributes the driver supports */
  1131. .show_host_node_name = 1,
  1132. .show_host_port_name = 1,
  1133. .show_host_supported_classes = 1,
  1134. .show_host_supported_fc4s = 1,
  1135. .show_host_symbolic_name = 1,
  1136. .show_host_supported_speeds = 1,
  1137. .show_host_maxframe_size = 1,
  1138. /* dynamic attributes the driver supports */
  1139. .get_host_port_id = lpfc_get_host_port_id,
  1140. .show_host_port_id = 1,
  1141. .get_host_port_type = lpfc_get_host_port_type,
  1142. .show_host_port_type = 1,
  1143. .get_host_port_state = lpfc_get_host_port_state,
  1144. .show_host_port_state = 1,
  1145. /* active_fc4s is shown but doesn't change (thus no get function) */
  1146. .show_host_active_fc4s = 1,
  1147. .get_host_speed = lpfc_get_host_speed,
  1148. .show_host_speed = 1,
  1149. .get_host_fabric_name = lpfc_get_host_fabric_name,
  1150. .show_host_fabric_name = 1,
  1151. /*
  1152. * The LPFC driver treats linkdown handling as target loss events
  1153. * so there are no sysfs handlers for link_down_tmo.
  1154. */
  1155. .get_fc_host_stats = lpfc_get_stats,
  1156. /* the LPFC driver doesn't support resetting stats yet */
  1157. .dd_fcrport_size = sizeof(struct lpfc_rport_data),
  1158. .show_rport_maxframe_size = 1,
  1159. .show_rport_supported_classes = 1,
  1160. .get_rport_dev_loss_tmo = lpfc_get_rport_loss_tmo,
  1161. .set_rport_dev_loss_tmo = lpfc_set_rport_loss_tmo,
  1162. .show_rport_dev_loss_tmo = 1,
  1163. .get_starget_port_id = lpfc_get_starget_port_id,
  1164. .show_starget_port_id = 1,
  1165. .get_starget_node_name = lpfc_get_starget_node_name,
  1166. .show_starget_node_name = 1,
  1167. .get_starget_port_name = lpfc_get_starget_port_name,
  1168. .show_starget_port_name = 1,
  1169. .issue_fc_host_lip = lpfc_issue_lip,
  1170. };
  1171. void
  1172. lpfc_get_cfgparam(struct lpfc_hba *phba)
  1173. {
  1174. lpfc_log_verbose_init(phba, lpfc_log_verbose);
  1175. lpfc_cr_delay_init(phba, lpfc_cr_delay);
  1176. lpfc_cr_count_init(phba, lpfc_cr_count);
  1177. lpfc_lun_queue_depth_init(phba, lpfc_lun_queue_depth);
  1178. lpfc_fcp_class_init(phba, lpfc_fcp_class);
  1179. lpfc_use_adisc_init(phba, lpfc_use_adisc);
  1180. lpfc_ack0_init(phba, lpfc_ack0);
  1181. lpfc_topology_init(phba, lpfc_topology);
  1182. lpfc_scan_down_init(phba, lpfc_scan_down);
  1183. lpfc_nodev_tmo_init(phba, lpfc_nodev_tmo);
  1184. lpfc_link_speed_init(phba, lpfc_link_speed);
  1185. lpfc_fdmi_on_init(phba, lpfc_fdmi_on);
  1186. lpfc_discovery_threads_init(phba, lpfc_discovery_threads);
  1187. lpfc_max_luns_init(phba, lpfc_max_luns);
  1188. lpfc_poll_tmo_init(phba, lpfc_poll_tmo);
  1189. phba->cfg_poll = lpfc_poll;
  1190. /*
  1191. * The total number of segments is the configuration value plus 2
  1192. * since the IOCB need a command and response bde.
  1193. */
  1194. phba->cfg_sg_seg_cnt = LPFC_SG_SEG_CNT + 2;
  1195. /*
  1196. * Since the sg_tablesize is module parameter, the sg_dma_buf_size
  1197. * used to create the sg_dma_buf_pool must be dynamically calculated
  1198. */
  1199. phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd) +
  1200. sizeof(struct fcp_rsp) +
  1201. (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
  1202. switch (phba->pcidev->device) {
  1203. case PCI_DEVICE_ID_LP101:
  1204. case PCI_DEVICE_ID_BSMB:
  1205. case PCI_DEVICE_ID_ZSMB:
  1206. phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
  1207. break;
  1208. case PCI_DEVICE_ID_RFLY:
  1209. case PCI_DEVICE_ID_PFLY:
  1210. case PCI_DEVICE_ID_BMID:
  1211. case PCI_DEVICE_ID_ZMID:
  1212. case PCI_DEVICE_ID_TFLY:
  1213. phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
  1214. break;
  1215. default:
  1216. phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
  1217. }
  1218. if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth)
  1219. lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
  1220. return;
  1221. }