qla_attr.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2013 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include "qla_target.h"
  9. #include <linux/kthread.h>
  10. #include <linux/vmalloc.h>
  11. #include <linux/slab.h>
  12. #include <linux/delay.h>
  13. static int qla24xx_vport_disable(struct fc_vport *, bool);
  14. /* SYSFS attributes --------------------------------------------------------- */
  15. static ssize_t
  16. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  17. struct bin_attribute *bin_attr,
  18. char *buf, loff_t off, size_t count)
  19. {
  20. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  21. struct device, kobj)));
  22. struct qla_hw_data *ha = vha->hw;
  23. int rval = 0;
  24. if (!(ha->fw_dump_reading || ha->mctp_dump_reading))
  25. return 0;
  26. if (IS_QLA82XX(ha)) {
  27. if (off < ha->md_template_size) {
  28. rval = memory_read_from_buffer(buf, count,
  29. &off, ha->md_tmplt_hdr, ha->md_template_size);
  30. return rval;
  31. }
  32. off -= ha->md_template_size;
  33. rval = memory_read_from_buffer(buf, count,
  34. &off, ha->md_dump, ha->md_dump_size);
  35. return rval;
  36. } else if (ha->mctp_dumped && ha->mctp_dump_reading)
  37. return memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
  38. MCTP_DUMP_SIZE);
  39. else if (ha->fw_dump_reading)
  40. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  41. ha->fw_dump_len);
  42. else
  43. return 0;
  44. }
  45. static ssize_t
  46. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  47. struct bin_attribute *bin_attr,
  48. char *buf, loff_t off, size_t count)
  49. {
  50. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  51. struct device, kobj)));
  52. struct qla_hw_data *ha = vha->hw;
  53. int reading;
  54. if (off != 0)
  55. return (0);
  56. reading = simple_strtol(buf, NULL, 10);
  57. switch (reading) {
  58. case 0:
  59. if (!ha->fw_dump_reading)
  60. break;
  61. ql_log(ql_log_info, vha, 0x705d,
  62. "Firmware dump cleared on (%ld).\n", vha->host_no);
  63. if (IS_QLA82XX(vha->hw)) {
  64. qla82xx_md_free(vha);
  65. qla82xx_md_prep(vha);
  66. }
  67. ha->fw_dump_reading = 0;
  68. ha->fw_dumped = 0;
  69. break;
  70. case 1:
  71. if (ha->fw_dumped && !ha->fw_dump_reading) {
  72. ha->fw_dump_reading = 1;
  73. ql_log(ql_log_info, vha, 0x705e,
  74. "Raw firmware dump ready for read on (%ld).\n",
  75. vha->host_no);
  76. }
  77. break;
  78. case 2:
  79. qla2x00_alloc_fw_dump(vha);
  80. break;
  81. case 3:
  82. if (IS_QLA82XX(ha)) {
  83. qla82xx_idc_lock(ha);
  84. qla82xx_set_reset_owner(vha);
  85. qla82xx_idc_unlock(ha);
  86. } else
  87. qla2x00_system_error(vha);
  88. break;
  89. case 4:
  90. if (IS_QLA82XX(ha)) {
  91. if (ha->md_tmplt_hdr)
  92. ql_dbg(ql_dbg_user, vha, 0x705b,
  93. "MiniDump supported with this firmware.\n");
  94. else
  95. ql_dbg(ql_dbg_user, vha, 0x709d,
  96. "MiniDump not supported with this firmware.\n");
  97. }
  98. break;
  99. case 5:
  100. if (IS_QLA82XX(ha))
  101. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  102. break;
  103. case 6:
  104. if (!ha->mctp_dump_reading)
  105. break;
  106. ql_log(ql_log_info, vha, 0x70c1,
  107. "MCTP dump cleared on (%ld).\n", vha->host_no);
  108. ha->mctp_dump_reading = 0;
  109. ha->mctp_dumped = 0;
  110. break;
  111. case 7:
  112. if (ha->mctp_dumped && !ha->mctp_dump_reading) {
  113. ha->mctp_dump_reading = 1;
  114. ql_log(ql_log_info, vha, 0x70c2,
  115. "Raw mctp dump ready for read on (%ld).\n",
  116. vha->host_no);
  117. }
  118. break;
  119. }
  120. return count;
  121. }
  122. static struct bin_attribute sysfs_fw_dump_attr = {
  123. .attr = {
  124. .name = "fw_dump",
  125. .mode = S_IRUSR | S_IWUSR,
  126. },
  127. .size = 0,
  128. .read = qla2x00_sysfs_read_fw_dump,
  129. .write = qla2x00_sysfs_write_fw_dump,
  130. };
  131. static ssize_t
  132. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  133. struct bin_attribute *bin_attr,
  134. char *buf, loff_t off, size_t count)
  135. {
  136. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  137. struct device, kobj)));
  138. struct qla_hw_data *ha = vha->hw;
  139. if (!capable(CAP_SYS_ADMIN))
  140. return 0;
  141. if (IS_NOCACHE_VPD_TYPE(ha))
  142. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  143. ha->nvram_size);
  144. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  145. ha->nvram_size);
  146. }
  147. static ssize_t
  148. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  149. struct bin_attribute *bin_attr,
  150. char *buf, loff_t off, size_t count)
  151. {
  152. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  153. struct device, kobj)));
  154. struct qla_hw_data *ha = vha->hw;
  155. uint16_t cnt;
  156. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  157. !ha->isp_ops->write_nvram)
  158. return -EINVAL;
  159. /* Checksum NVRAM. */
  160. if (IS_FWI2_CAPABLE(ha)) {
  161. uint32_t *iter;
  162. uint32_t chksum;
  163. iter = (uint32_t *)buf;
  164. chksum = 0;
  165. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  166. chksum += le32_to_cpu(*iter++);
  167. chksum = ~chksum + 1;
  168. *iter = cpu_to_le32(chksum);
  169. } else {
  170. uint8_t *iter;
  171. uint8_t chksum;
  172. iter = (uint8_t *)buf;
  173. chksum = 0;
  174. for (cnt = 0; cnt < count - 1; cnt++)
  175. chksum += *iter++;
  176. chksum = ~chksum + 1;
  177. *iter = chksum;
  178. }
  179. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  180. ql_log(ql_log_warn, vha, 0x705f,
  181. "HBA not online, failing NVRAM update.\n");
  182. return -EAGAIN;
  183. }
  184. /* Write NVRAM. */
  185. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  186. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  187. count);
  188. ql_dbg(ql_dbg_user, vha, 0x7060,
  189. "Setting ISP_ABORT_NEEDED\n");
  190. /* NVRAM settings take effect immediately. */
  191. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  192. qla2xxx_wake_dpc(vha);
  193. qla2x00_wait_for_chip_reset(vha);
  194. return count;
  195. }
  196. static struct bin_attribute sysfs_nvram_attr = {
  197. .attr = {
  198. .name = "nvram",
  199. .mode = S_IRUSR | S_IWUSR,
  200. },
  201. .size = 512,
  202. .read = qla2x00_sysfs_read_nvram,
  203. .write = qla2x00_sysfs_write_nvram,
  204. };
  205. static ssize_t
  206. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  207. struct bin_attribute *bin_attr,
  208. char *buf, loff_t off, size_t count)
  209. {
  210. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  211. struct device, kobj)));
  212. struct qla_hw_data *ha = vha->hw;
  213. if (ha->optrom_state != QLA_SREADING)
  214. return 0;
  215. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  216. ha->optrom_region_size);
  217. }
  218. static ssize_t
  219. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  220. struct bin_attribute *bin_attr,
  221. char *buf, loff_t off, size_t count)
  222. {
  223. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  224. struct device, kobj)));
  225. struct qla_hw_data *ha = vha->hw;
  226. if (ha->optrom_state != QLA_SWRITING)
  227. return -EINVAL;
  228. if (off > ha->optrom_region_size)
  229. return -ERANGE;
  230. if (off + count > ha->optrom_region_size)
  231. count = ha->optrom_region_size - off;
  232. memcpy(&ha->optrom_buffer[off], buf, count);
  233. return count;
  234. }
  235. static struct bin_attribute sysfs_optrom_attr = {
  236. .attr = {
  237. .name = "optrom",
  238. .mode = S_IRUSR | S_IWUSR,
  239. },
  240. .size = 0,
  241. .read = qla2x00_sysfs_read_optrom,
  242. .write = qla2x00_sysfs_write_optrom,
  243. };
  244. static ssize_t
  245. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  246. struct bin_attribute *bin_attr,
  247. char *buf, loff_t off, size_t count)
  248. {
  249. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  250. struct device, kobj)));
  251. struct qla_hw_data *ha = vha->hw;
  252. uint32_t start = 0;
  253. uint32_t size = ha->optrom_size;
  254. int val, valid;
  255. if (off)
  256. return -EINVAL;
  257. if (unlikely(pci_channel_offline(ha->pdev)))
  258. return -EAGAIN;
  259. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  260. return -EINVAL;
  261. if (start > ha->optrom_size)
  262. return -EINVAL;
  263. switch (val) {
  264. case 0:
  265. if (ha->optrom_state != QLA_SREADING &&
  266. ha->optrom_state != QLA_SWRITING)
  267. return -EINVAL;
  268. ha->optrom_state = QLA_SWAITING;
  269. ql_dbg(ql_dbg_user, vha, 0x7061,
  270. "Freeing flash region allocation -- 0x%x bytes.\n",
  271. ha->optrom_region_size);
  272. vfree(ha->optrom_buffer);
  273. ha->optrom_buffer = NULL;
  274. break;
  275. case 1:
  276. if (ha->optrom_state != QLA_SWAITING)
  277. return -EINVAL;
  278. ha->optrom_region_start = start;
  279. ha->optrom_region_size = start + size > ha->optrom_size ?
  280. ha->optrom_size - start : size;
  281. ha->optrom_state = QLA_SREADING;
  282. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  283. if (ha->optrom_buffer == NULL) {
  284. ql_log(ql_log_warn, vha, 0x7062,
  285. "Unable to allocate memory for optrom retrieval "
  286. "(%x).\n", ha->optrom_region_size);
  287. ha->optrom_state = QLA_SWAITING;
  288. return -ENOMEM;
  289. }
  290. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  291. ql_log(ql_log_warn, vha, 0x7063,
  292. "HBA not online, failing NVRAM update.\n");
  293. return -EAGAIN;
  294. }
  295. ql_dbg(ql_dbg_user, vha, 0x7064,
  296. "Reading flash region -- 0x%x/0x%x.\n",
  297. ha->optrom_region_start, ha->optrom_region_size);
  298. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  299. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  300. ha->optrom_region_start, ha->optrom_region_size);
  301. break;
  302. case 2:
  303. if (ha->optrom_state != QLA_SWAITING)
  304. return -EINVAL;
  305. /*
  306. * We need to be more restrictive on which FLASH regions are
  307. * allowed to be updated via user-space. Regions accessible
  308. * via this method include:
  309. *
  310. * ISP21xx/ISP22xx/ISP23xx type boards:
  311. *
  312. * 0x000000 -> 0x020000 -- Boot code.
  313. *
  314. * ISP2322/ISP24xx type boards:
  315. *
  316. * 0x000000 -> 0x07ffff -- Boot code.
  317. * 0x080000 -> 0x0fffff -- Firmware.
  318. *
  319. * ISP25xx type boards:
  320. *
  321. * 0x000000 -> 0x07ffff -- Boot code.
  322. * 0x080000 -> 0x0fffff -- Firmware.
  323. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  324. */
  325. valid = 0;
  326. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  327. valid = 1;
  328. else if (start == (ha->flt_region_boot * 4) ||
  329. start == (ha->flt_region_fw * 4))
  330. valid = 1;
  331. else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
  332. || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
  333. valid = 1;
  334. if (!valid) {
  335. ql_log(ql_log_warn, vha, 0x7065,
  336. "Invalid start region 0x%x/0x%x.\n", start, size);
  337. return -EINVAL;
  338. }
  339. ha->optrom_region_start = start;
  340. ha->optrom_region_size = start + size > ha->optrom_size ?
  341. ha->optrom_size - start : size;
  342. ha->optrom_state = QLA_SWRITING;
  343. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  344. if (ha->optrom_buffer == NULL) {
  345. ql_log(ql_log_warn, vha, 0x7066,
  346. "Unable to allocate memory for optrom update "
  347. "(%x)\n", ha->optrom_region_size);
  348. ha->optrom_state = QLA_SWAITING;
  349. return -ENOMEM;
  350. }
  351. ql_dbg(ql_dbg_user, vha, 0x7067,
  352. "Staging flash region write -- 0x%x/0x%x.\n",
  353. ha->optrom_region_start, ha->optrom_region_size);
  354. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  355. break;
  356. case 3:
  357. if (ha->optrom_state != QLA_SWRITING)
  358. return -EINVAL;
  359. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  360. ql_log(ql_log_warn, vha, 0x7068,
  361. "HBA not online, failing flash update.\n");
  362. return -EAGAIN;
  363. }
  364. ql_dbg(ql_dbg_user, vha, 0x7069,
  365. "Writing flash region -- 0x%x/0x%x.\n",
  366. ha->optrom_region_start, ha->optrom_region_size);
  367. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  368. ha->optrom_region_start, ha->optrom_region_size);
  369. break;
  370. default:
  371. return -EINVAL;
  372. }
  373. return count;
  374. }
  375. static struct bin_attribute sysfs_optrom_ctl_attr = {
  376. .attr = {
  377. .name = "optrom_ctl",
  378. .mode = S_IWUSR,
  379. },
  380. .size = 0,
  381. .write = qla2x00_sysfs_write_optrom_ctl,
  382. };
  383. static ssize_t
  384. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  385. struct bin_attribute *bin_attr,
  386. char *buf, loff_t off, size_t count)
  387. {
  388. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  389. struct device, kobj)));
  390. struct qla_hw_data *ha = vha->hw;
  391. if (unlikely(pci_channel_offline(ha->pdev)))
  392. return -EAGAIN;
  393. if (!capable(CAP_SYS_ADMIN))
  394. return -EINVAL;
  395. if (IS_NOCACHE_VPD_TYPE(ha))
  396. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  397. ha->vpd_size);
  398. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  399. }
  400. static ssize_t
  401. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  402. struct bin_attribute *bin_attr,
  403. char *buf, loff_t off, size_t count)
  404. {
  405. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  406. struct device, kobj)));
  407. struct qla_hw_data *ha = vha->hw;
  408. uint8_t *tmp_data;
  409. if (unlikely(pci_channel_offline(ha->pdev)))
  410. return 0;
  411. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  412. !ha->isp_ops->write_nvram)
  413. return 0;
  414. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  415. ql_log(ql_log_warn, vha, 0x706a,
  416. "HBA not online, failing VPD update.\n");
  417. return -EAGAIN;
  418. }
  419. /* Write NVRAM. */
  420. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  421. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  422. /* Update flash version information for 4Gb & above. */
  423. if (!IS_FWI2_CAPABLE(ha))
  424. return -EINVAL;
  425. tmp_data = vmalloc(256);
  426. if (!tmp_data) {
  427. ql_log(ql_log_warn, vha, 0x706b,
  428. "Unable to allocate memory for VPD information update.\n");
  429. return -ENOMEM;
  430. }
  431. ha->isp_ops->get_flash_version(vha, tmp_data);
  432. vfree(tmp_data);
  433. return count;
  434. }
  435. static struct bin_attribute sysfs_vpd_attr = {
  436. .attr = {
  437. .name = "vpd",
  438. .mode = S_IRUSR | S_IWUSR,
  439. },
  440. .size = 0,
  441. .read = qla2x00_sysfs_read_vpd,
  442. .write = qla2x00_sysfs_write_vpd,
  443. };
  444. static ssize_t
  445. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  446. struct bin_attribute *bin_attr,
  447. char *buf, loff_t off, size_t count)
  448. {
  449. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  450. struct device, kobj)));
  451. struct qla_hw_data *ha = vha->hw;
  452. uint16_t iter, addr, offset;
  453. int rval;
  454. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  455. return 0;
  456. if (ha->sfp_data)
  457. goto do_read;
  458. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  459. &ha->sfp_data_dma);
  460. if (!ha->sfp_data) {
  461. ql_log(ql_log_warn, vha, 0x706c,
  462. "Unable to allocate memory for SFP read-data.\n");
  463. return 0;
  464. }
  465. do_read:
  466. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  467. addr = 0xa0;
  468. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  469. iter++, offset += SFP_BLOCK_SIZE) {
  470. if (iter == 4) {
  471. /* Skip to next device address. */
  472. addr = 0xa2;
  473. offset = 0;
  474. }
  475. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  476. addr, offset, SFP_BLOCK_SIZE, 0);
  477. if (rval != QLA_SUCCESS) {
  478. ql_log(ql_log_warn, vha, 0x706d,
  479. "Unable to read SFP data (%x/%x/%x).\n", rval,
  480. addr, offset);
  481. return -EIO;
  482. }
  483. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  484. buf += SFP_BLOCK_SIZE;
  485. }
  486. return count;
  487. }
  488. static struct bin_attribute sysfs_sfp_attr = {
  489. .attr = {
  490. .name = "sfp",
  491. .mode = S_IRUSR | S_IWUSR,
  492. },
  493. .size = SFP_DEV_SIZE * 2,
  494. .read = qla2x00_sysfs_read_sfp,
  495. };
  496. static ssize_t
  497. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  498. struct bin_attribute *bin_attr,
  499. char *buf, loff_t off, size_t count)
  500. {
  501. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  502. struct device, kobj)));
  503. struct qla_hw_data *ha = vha->hw;
  504. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  505. int type;
  506. uint32_t idc_control;
  507. if (off != 0)
  508. return -EINVAL;
  509. type = simple_strtol(buf, NULL, 10);
  510. switch (type) {
  511. case 0x2025c:
  512. ql_log(ql_log_info, vha, 0x706e,
  513. "Issuing ISP reset.\n");
  514. scsi_block_requests(vha->host);
  515. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  516. if (IS_QLA82XX(ha)) {
  517. ha->flags.isp82xx_no_md_cap = 1;
  518. qla82xx_idc_lock(ha);
  519. qla82xx_set_reset_owner(vha);
  520. qla82xx_idc_unlock(ha);
  521. }
  522. qla2xxx_wake_dpc(vha);
  523. qla2x00_wait_for_chip_reset(vha);
  524. scsi_unblock_requests(vha->host);
  525. break;
  526. case 0x2025d:
  527. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  528. return -EPERM;
  529. ql_log(ql_log_info, vha, 0x706f,
  530. "Issuing MPI reset.\n");
  531. if (IS_QLA83XX(ha)) {
  532. uint32_t idc_control;
  533. qla83xx_idc_lock(vha, 0);
  534. __qla83xx_get_idc_control(vha, &idc_control);
  535. idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
  536. __qla83xx_set_idc_control(vha, idc_control);
  537. qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
  538. QLA8XXX_DEV_NEED_RESET);
  539. qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
  540. qla83xx_idc_unlock(vha, 0);
  541. break;
  542. } else {
  543. /* Make sure FC side is not in reset */
  544. qla2x00_wait_for_hba_online(vha);
  545. /* Issue MPI reset */
  546. scsi_block_requests(vha->host);
  547. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  548. ql_log(ql_log_warn, vha, 0x7070,
  549. "MPI reset failed.\n");
  550. scsi_unblock_requests(vha->host);
  551. break;
  552. }
  553. case 0x2025e:
  554. if (!IS_QLA82XX(ha) || vha != base_vha) {
  555. ql_log(ql_log_info, vha, 0x7071,
  556. "FCoE ctx reset no supported.\n");
  557. return -EPERM;
  558. }
  559. ql_log(ql_log_info, vha, 0x7072,
  560. "Issuing FCoE ctx reset.\n");
  561. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  562. qla2xxx_wake_dpc(vha);
  563. qla2x00_wait_for_fcoe_ctx_reset(vha);
  564. break;
  565. case 0x2025f:
  566. if (!IS_QLA8031(ha))
  567. return -EPERM;
  568. ql_log(ql_log_info, vha, 0x70bc,
  569. "Disabling Reset by IDC control\n");
  570. qla83xx_idc_lock(vha, 0);
  571. __qla83xx_get_idc_control(vha, &idc_control);
  572. idc_control |= QLA83XX_IDC_RESET_DISABLED;
  573. __qla83xx_set_idc_control(vha, idc_control);
  574. qla83xx_idc_unlock(vha, 0);
  575. break;
  576. case 0x20260:
  577. if (!IS_QLA8031(ha))
  578. return -EPERM;
  579. ql_log(ql_log_info, vha, 0x70bd,
  580. "Enabling Reset by IDC control\n");
  581. qla83xx_idc_lock(vha, 0);
  582. __qla83xx_get_idc_control(vha, &idc_control);
  583. idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
  584. __qla83xx_set_idc_control(vha, idc_control);
  585. qla83xx_idc_unlock(vha, 0);
  586. break;
  587. }
  588. return count;
  589. }
  590. static struct bin_attribute sysfs_reset_attr = {
  591. .attr = {
  592. .name = "reset",
  593. .mode = S_IWUSR,
  594. },
  595. .size = 0,
  596. .write = qla2x00_sysfs_write_reset,
  597. };
  598. static ssize_t
  599. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  600. struct bin_attribute *bin_attr,
  601. char *buf, loff_t off, size_t count)
  602. {
  603. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  604. struct device, kobj)));
  605. struct qla_hw_data *ha = vha->hw;
  606. int rval;
  607. uint16_t actual_size;
  608. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  609. return 0;
  610. if (ha->xgmac_data)
  611. goto do_read;
  612. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  613. &ha->xgmac_data_dma, GFP_KERNEL);
  614. if (!ha->xgmac_data) {
  615. ql_log(ql_log_warn, vha, 0x7076,
  616. "Unable to allocate memory for XGMAC read-data.\n");
  617. return 0;
  618. }
  619. do_read:
  620. actual_size = 0;
  621. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  622. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  623. XGMAC_DATA_SIZE, &actual_size);
  624. if (rval != QLA_SUCCESS) {
  625. ql_log(ql_log_warn, vha, 0x7077,
  626. "Unable to read XGMAC data (%x).\n", rval);
  627. count = 0;
  628. }
  629. count = actual_size > count ? count: actual_size;
  630. memcpy(buf, ha->xgmac_data, count);
  631. return count;
  632. }
  633. static struct bin_attribute sysfs_xgmac_stats_attr = {
  634. .attr = {
  635. .name = "xgmac_stats",
  636. .mode = S_IRUSR,
  637. },
  638. .size = 0,
  639. .read = qla2x00_sysfs_read_xgmac_stats,
  640. };
  641. static ssize_t
  642. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  643. struct bin_attribute *bin_attr,
  644. char *buf, loff_t off, size_t count)
  645. {
  646. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  647. struct device, kobj)));
  648. struct qla_hw_data *ha = vha->hw;
  649. int rval;
  650. uint16_t actual_size;
  651. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  652. return 0;
  653. if (ha->dcbx_tlv)
  654. goto do_read;
  655. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  656. &ha->dcbx_tlv_dma, GFP_KERNEL);
  657. if (!ha->dcbx_tlv) {
  658. ql_log(ql_log_warn, vha, 0x7078,
  659. "Unable to allocate memory for DCBX TLV read-data.\n");
  660. return -ENOMEM;
  661. }
  662. do_read:
  663. actual_size = 0;
  664. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  665. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  666. DCBX_TLV_DATA_SIZE);
  667. if (rval != QLA_SUCCESS) {
  668. ql_log(ql_log_warn, vha, 0x7079,
  669. "Unable to read DCBX TLV (%x).\n", rval);
  670. return -EIO;
  671. }
  672. memcpy(buf, ha->dcbx_tlv, count);
  673. return count;
  674. }
  675. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  676. .attr = {
  677. .name = "dcbx_tlv",
  678. .mode = S_IRUSR,
  679. },
  680. .size = 0,
  681. .read = qla2x00_sysfs_read_dcbx_tlv,
  682. };
  683. static struct sysfs_entry {
  684. char *name;
  685. struct bin_attribute *attr;
  686. int is4GBp_only;
  687. } bin_file_entries[] = {
  688. { "fw_dump", &sysfs_fw_dump_attr, },
  689. { "nvram", &sysfs_nvram_attr, },
  690. { "optrom", &sysfs_optrom_attr, },
  691. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  692. { "vpd", &sysfs_vpd_attr, 1 },
  693. { "sfp", &sysfs_sfp_attr, 1 },
  694. { "reset", &sysfs_reset_attr, },
  695. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  696. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  697. { NULL },
  698. };
  699. void
  700. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  701. {
  702. struct Scsi_Host *host = vha->host;
  703. struct sysfs_entry *iter;
  704. int ret;
  705. for (iter = bin_file_entries; iter->name; iter++) {
  706. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  707. continue;
  708. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  709. continue;
  710. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  711. continue;
  712. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  713. iter->attr);
  714. if (ret)
  715. ql_log(ql_log_warn, vha, 0x00f3,
  716. "Unable to create sysfs %s binary attribute (%d).\n",
  717. iter->name, ret);
  718. else
  719. ql_dbg(ql_dbg_init, vha, 0x00f4,
  720. "Successfully created sysfs %s binary attribure.\n",
  721. iter->name);
  722. }
  723. }
  724. void
  725. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  726. {
  727. struct Scsi_Host *host = vha->host;
  728. struct sysfs_entry *iter;
  729. struct qla_hw_data *ha = vha->hw;
  730. for (iter = bin_file_entries; iter->name; iter++) {
  731. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  732. continue;
  733. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  734. continue;
  735. if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
  736. continue;
  737. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  738. iter->attr);
  739. }
  740. if (ha->beacon_blink_led == 1)
  741. ha->isp_ops->beacon_off(vha);
  742. }
  743. /* Scsi_Host attributes. */
  744. static ssize_t
  745. qla2x00_drvr_version_show(struct device *dev,
  746. struct device_attribute *attr, char *buf)
  747. {
  748. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  749. }
  750. static ssize_t
  751. qla2x00_fw_version_show(struct device *dev,
  752. struct device_attribute *attr, char *buf)
  753. {
  754. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  755. struct qla_hw_data *ha = vha->hw;
  756. char fw_str[128];
  757. return snprintf(buf, PAGE_SIZE, "%s\n",
  758. ha->isp_ops->fw_version_str(vha, fw_str));
  759. }
  760. static ssize_t
  761. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  762. char *buf)
  763. {
  764. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  765. struct qla_hw_data *ha = vha->hw;
  766. uint32_t sn;
  767. if (IS_QLAFX00(vha->hw)) {
  768. return snprintf(buf, PAGE_SIZE, "%s\n",
  769. vha->hw->mr.serial_num);
  770. } else if (IS_FWI2_CAPABLE(ha)) {
  771. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  772. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  773. }
  774. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  775. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  776. sn % 100000);
  777. }
  778. static ssize_t
  779. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  780. char *buf)
  781. {
  782. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  783. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  784. }
  785. static ssize_t
  786. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  787. char *buf)
  788. {
  789. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  790. struct qla_hw_data *ha = vha->hw;
  791. if (IS_QLAFX00(vha->hw))
  792. return snprintf(buf, PAGE_SIZE, "%s\n",
  793. vha->hw->mr.hw_version);
  794. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  795. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  796. ha->product_id[3]);
  797. }
  798. static ssize_t
  799. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  800. char *buf)
  801. {
  802. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  803. if (IS_QLAFX00(vha->hw))
  804. return snprintf(buf, PAGE_SIZE, "%s\n",
  805. vha->hw->mr.product_name);
  806. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  807. }
  808. static ssize_t
  809. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  810. char *buf)
  811. {
  812. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  813. return snprintf(buf, PAGE_SIZE, "%s\n",
  814. vha->hw->model_desc ? vha->hw->model_desc : "");
  815. }
  816. static ssize_t
  817. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  818. char *buf)
  819. {
  820. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  821. char pci_info[30];
  822. return snprintf(buf, PAGE_SIZE, "%s\n",
  823. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  824. }
  825. static ssize_t
  826. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  827. char *buf)
  828. {
  829. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  830. struct qla_hw_data *ha = vha->hw;
  831. int len = 0;
  832. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  833. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  834. vha->device_flags & DFLG_NO_CABLE)
  835. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  836. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  837. qla2x00_reset_active(vha))
  838. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  839. else {
  840. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  841. switch (ha->current_topology) {
  842. case ISP_CFG_NL:
  843. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  844. break;
  845. case ISP_CFG_FL:
  846. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  847. break;
  848. case ISP_CFG_N:
  849. len += snprintf(buf + len, PAGE_SIZE-len,
  850. "N_Port to N_Port\n");
  851. break;
  852. case ISP_CFG_F:
  853. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  854. break;
  855. default:
  856. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  857. break;
  858. }
  859. }
  860. return len;
  861. }
  862. static ssize_t
  863. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  864. char *buf)
  865. {
  866. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  867. int len = 0;
  868. switch (vha->hw->zio_mode) {
  869. case QLA_ZIO_MODE_6:
  870. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  871. break;
  872. case QLA_ZIO_DISABLED:
  873. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  874. break;
  875. }
  876. return len;
  877. }
  878. static ssize_t
  879. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  880. const char *buf, size_t count)
  881. {
  882. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  883. struct qla_hw_data *ha = vha->hw;
  884. int val = 0;
  885. uint16_t zio_mode;
  886. if (!IS_ZIO_SUPPORTED(ha))
  887. return -ENOTSUPP;
  888. if (sscanf(buf, "%d", &val) != 1)
  889. return -EINVAL;
  890. if (val)
  891. zio_mode = QLA_ZIO_MODE_6;
  892. else
  893. zio_mode = QLA_ZIO_DISABLED;
  894. /* Update per-hba values and queue a reset. */
  895. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  896. ha->zio_mode = zio_mode;
  897. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  898. }
  899. return strlen(buf);
  900. }
  901. static ssize_t
  902. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  903. char *buf)
  904. {
  905. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  906. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  907. }
  908. static ssize_t
  909. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  910. const char *buf, size_t count)
  911. {
  912. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  913. int val = 0;
  914. uint16_t zio_timer;
  915. if (sscanf(buf, "%d", &val) != 1)
  916. return -EINVAL;
  917. if (val > 25500 || val < 100)
  918. return -ERANGE;
  919. zio_timer = (uint16_t)(val / 100);
  920. vha->hw->zio_timer = zio_timer;
  921. return strlen(buf);
  922. }
  923. static ssize_t
  924. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  925. char *buf)
  926. {
  927. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  928. int len = 0;
  929. if (vha->hw->beacon_blink_led)
  930. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  931. else
  932. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  933. return len;
  934. }
  935. static ssize_t
  936. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  937. const char *buf, size_t count)
  938. {
  939. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  940. struct qla_hw_data *ha = vha->hw;
  941. int val = 0;
  942. int rval;
  943. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  944. return -EPERM;
  945. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  946. ql_log(ql_log_warn, vha, 0x707a,
  947. "Abort ISP active -- ignoring beacon request.\n");
  948. return -EBUSY;
  949. }
  950. if (sscanf(buf, "%d", &val) != 1)
  951. return -EINVAL;
  952. if (val)
  953. rval = ha->isp_ops->beacon_on(vha);
  954. else
  955. rval = ha->isp_ops->beacon_off(vha);
  956. if (rval != QLA_SUCCESS)
  957. count = 0;
  958. return count;
  959. }
  960. static ssize_t
  961. qla2x00_optrom_bios_version_show(struct device *dev,
  962. struct device_attribute *attr, char *buf)
  963. {
  964. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  965. struct qla_hw_data *ha = vha->hw;
  966. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  967. ha->bios_revision[0]);
  968. }
  969. static ssize_t
  970. qla2x00_optrom_efi_version_show(struct device *dev,
  971. struct device_attribute *attr, char *buf)
  972. {
  973. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  974. struct qla_hw_data *ha = vha->hw;
  975. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  976. ha->efi_revision[0]);
  977. }
  978. static ssize_t
  979. qla2x00_optrom_fcode_version_show(struct device *dev,
  980. struct device_attribute *attr, char *buf)
  981. {
  982. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  983. struct qla_hw_data *ha = vha->hw;
  984. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  985. ha->fcode_revision[0]);
  986. }
  987. static ssize_t
  988. qla2x00_optrom_fw_version_show(struct device *dev,
  989. struct device_attribute *attr, char *buf)
  990. {
  991. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  992. struct qla_hw_data *ha = vha->hw;
  993. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  994. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  995. ha->fw_revision[3]);
  996. }
  997. static ssize_t
  998. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  999. struct device_attribute *attr, char *buf)
  1000. {
  1001. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1002. struct qla_hw_data *ha = vha->hw;
  1003. if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
  1004. return snprintf(buf, PAGE_SIZE, "\n");
  1005. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  1006. ha->gold_fw_version[0], ha->gold_fw_version[1],
  1007. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  1008. }
  1009. static ssize_t
  1010. qla2x00_total_isp_aborts_show(struct device *dev,
  1011. struct device_attribute *attr, char *buf)
  1012. {
  1013. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1014. return snprintf(buf, PAGE_SIZE, "%d\n",
  1015. vha->qla_stats.total_isp_aborts);
  1016. }
  1017. static ssize_t
  1018. qla24xx_84xx_fw_version_show(struct device *dev,
  1019. struct device_attribute *attr, char *buf)
  1020. {
  1021. int rval = QLA_SUCCESS;
  1022. uint16_t status[2] = {0, 0};
  1023. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1024. struct qla_hw_data *ha = vha->hw;
  1025. if (!IS_QLA84XX(ha))
  1026. return snprintf(buf, PAGE_SIZE, "\n");
  1027. if (ha->cs84xx->op_fw_version == 0)
  1028. rval = qla84xx_verify_chip(vha, status);
  1029. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1030. return snprintf(buf, PAGE_SIZE, "%u\n",
  1031. (uint32_t)ha->cs84xx->op_fw_version);
  1032. return snprintf(buf, PAGE_SIZE, "\n");
  1033. }
  1034. static ssize_t
  1035. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1036. char *buf)
  1037. {
  1038. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1039. struct qla_hw_data *ha = vha->hw;
  1040. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  1041. return snprintf(buf, PAGE_SIZE, "\n");
  1042. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1043. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1044. ha->mpi_capabilities);
  1045. }
  1046. static ssize_t
  1047. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1048. char *buf)
  1049. {
  1050. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1051. struct qla_hw_data *ha = vha->hw;
  1052. if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
  1053. return snprintf(buf, PAGE_SIZE, "\n");
  1054. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1055. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1056. }
  1057. static ssize_t
  1058. qla2x00_flash_block_size_show(struct device *dev,
  1059. struct device_attribute *attr, char *buf)
  1060. {
  1061. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1062. struct qla_hw_data *ha = vha->hw;
  1063. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1064. }
  1065. static ssize_t
  1066. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1067. char *buf)
  1068. {
  1069. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1070. if (!IS_CNA_CAPABLE(vha->hw))
  1071. return snprintf(buf, PAGE_SIZE, "\n");
  1072. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1073. }
  1074. static ssize_t
  1075. qla2x00_vn_port_mac_address_show(struct device *dev,
  1076. struct device_attribute *attr, char *buf)
  1077. {
  1078. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1079. if (!IS_CNA_CAPABLE(vha->hw))
  1080. return snprintf(buf, PAGE_SIZE, "\n");
  1081. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1082. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1083. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1084. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1085. }
  1086. static ssize_t
  1087. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1088. char *buf)
  1089. {
  1090. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1091. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1092. }
  1093. static ssize_t
  1094. qla2x00_thermal_temp_show(struct device *dev,
  1095. struct device_attribute *attr, char *buf)
  1096. {
  1097. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1098. uint16_t temp = 0;
  1099. if (!vha->hw->thermal_support) {
  1100. ql_log(ql_log_warn, vha, 0x70db,
  1101. "Thermal not supported by this card.\n");
  1102. goto done;
  1103. }
  1104. if (qla2x00_reset_active(vha)) {
  1105. ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
  1106. goto done;
  1107. }
  1108. if (vha->hw->flags.eeh_busy) {
  1109. ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
  1110. goto done;
  1111. }
  1112. if (qla2x00_get_thermal_temp(vha, &temp) == QLA_SUCCESS)
  1113. return snprintf(buf, PAGE_SIZE, "%d\n", temp);
  1114. done:
  1115. return snprintf(buf, PAGE_SIZE, "\n");
  1116. }
  1117. static ssize_t
  1118. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1119. char *buf)
  1120. {
  1121. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1122. int rval = QLA_FUNCTION_FAILED;
  1123. uint16_t state[5];
  1124. uint32_t pstate;
  1125. if (IS_QLAFX00(vha->hw)) {
  1126. pstate = qlafx00_fw_state_show(dev, attr, buf);
  1127. return snprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
  1128. }
  1129. if (qla2x00_reset_active(vha))
  1130. ql_log(ql_log_warn, vha, 0x707c,
  1131. "ISP reset active.\n");
  1132. else if (!vha->hw->flags.eeh_busy)
  1133. rval = qla2x00_get_firmware_state(vha, state);
  1134. if (rval != QLA_SUCCESS)
  1135. memset(state, -1, sizeof(state));
  1136. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1137. state[1], state[2], state[3], state[4]);
  1138. }
  1139. static ssize_t
  1140. qla2x00_diag_requests_show(struct device *dev,
  1141. struct device_attribute *attr, char *buf)
  1142. {
  1143. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1144. if (!IS_BIDI_CAPABLE(vha->hw))
  1145. return snprintf(buf, PAGE_SIZE, "\n");
  1146. return snprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
  1147. }
  1148. static ssize_t
  1149. qla2x00_diag_megabytes_show(struct device *dev,
  1150. struct device_attribute *attr, char *buf)
  1151. {
  1152. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1153. if (!IS_BIDI_CAPABLE(vha->hw))
  1154. return snprintf(buf, PAGE_SIZE, "\n");
  1155. return snprintf(buf, PAGE_SIZE, "%llu\n",
  1156. vha->bidi_stats.transfer_bytes >> 20);
  1157. }
  1158. static ssize_t
  1159. qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
  1160. char *buf)
  1161. {
  1162. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1163. struct qla_hw_data *ha = vha->hw;
  1164. uint32_t size;
  1165. if (!ha->fw_dumped)
  1166. size = 0;
  1167. else if (IS_QLA82XX(ha))
  1168. size = ha->md_template_size + ha->md_dump_size;
  1169. else
  1170. size = ha->fw_dump_len;
  1171. return snprintf(buf, PAGE_SIZE, "%d\n", size);
  1172. }
  1173. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1174. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1175. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1176. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1177. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1178. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1179. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1180. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1181. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1182. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1183. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1184. qla2x00_zio_timer_store);
  1185. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1186. qla2x00_beacon_store);
  1187. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1188. qla2x00_optrom_bios_version_show, NULL);
  1189. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1190. qla2x00_optrom_efi_version_show, NULL);
  1191. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1192. qla2x00_optrom_fcode_version_show, NULL);
  1193. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1194. NULL);
  1195. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1196. qla2x00_optrom_gold_fw_version_show, NULL);
  1197. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1198. NULL);
  1199. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1200. NULL);
  1201. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1202. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1203. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1204. NULL);
  1205. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1206. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1207. qla2x00_vn_port_mac_address_show, NULL);
  1208. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1209. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1210. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1211. static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
  1212. static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
  1213. static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
  1214. struct device_attribute *qla2x00_host_attrs[] = {
  1215. &dev_attr_driver_version,
  1216. &dev_attr_fw_version,
  1217. &dev_attr_serial_num,
  1218. &dev_attr_isp_name,
  1219. &dev_attr_isp_id,
  1220. &dev_attr_model_name,
  1221. &dev_attr_model_desc,
  1222. &dev_attr_pci_info,
  1223. &dev_attr_link_state,
  1224. &dev_attr_zio,
  1225. &dev_attr_zio_timer,
  1226. &dev_attr_beacon,
  1227. &dev_attr_optrom_bios_version,
  1228. &dev_attr_optrom_efi_version,
  1229. &dev_attr_optrom_fcode_version,
  1230. &dev_attr_optrom_fw_version,
  1231. &dev_attr_84xx_fw_version,
  1232. &dev_attr_total_isp_aborts,
  1233. &dev_attr_mpi_version,
  1234. &dev_attr_phy_version,
  1235. &dev_attr_flash_block_size,
  1236. &dev_attr_vlan_id,
  1237. &dev_attr_vn_port_mac_address,
  1238. &dev_attr_fabric_param,
  1239. &dev_attr_fw_state,
  1240. &dev_attr_optrom_gold_fw_version,
  1241. &dev_attr_thermal_temp,
  1242. &dev_attr_diag_requests,
  1243. &dev_attr_diag_megabytes,
  1244. &dev_attr_fw_dump_size,
  1245. NULL,
  1246. };
  1247. /* Host attributes. */
  1248. static void
  1249. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1250. {
  1251. scsi_qla_host_t *vha = shost_priv(shost);
  1252. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1253. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1254. }
  1255. static void
  1256. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1257. {
  1258. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1259. (shost_priv(shost)))->hw;
  1260. u32 speed = FC_PORTSPEED_UNKNOWN;
  1261. if (IS_QLAFX00(ha)) {
  1262. qlafx00_get_host_speed(shost);
  1263. return;
  1264. }
  1265. switch (ha->link_data_rate) {
  1266. case PORT_SPEED_1GB:
  1267. speed = FC_PORTSPEED_1GBIT;
  1268. break;
  1269. case PORT_SPEED_2GB:
  1270. speed = FC_PORTSPEED_2GBIT;
  1271. break;
  1272. case PORT_SPEED_4GB:
  1273. speed = FC_PORTSPEED_4GBIT;
  1274. break;
  1275. case PORT_SPEED_8GB:
  1276. speed = FC_PORTSPEED_8GBIT;
  1277. break;
  1278. case PORT_SPEED_10GB:
  1279. speed = FC_PORTSPEED_10GBIT;
  1280. break;
  1281. case PORT_SPEED_16GB:
  1282. speed = FC_PORTSPEED_16GBIT;
  1283. break;
  1284. }
  1285. fc_host_speed(shost) = speed;
  1286. }
  1287. static void
  1288. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1289. {
  1290. scsi_qla_host_t *vha = shost_priv(shost);
  1291. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1292. if (vha->vp_idx) {
  1293. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1294. return;
  1295. }
  1296. switch (vha->hw->current_topology) {
  1297. case ISP_CFG_NL:
  1298. port_type = FC_PORTTYPE_LPORT;
  1299. break;
  1300. case ISP_CFG_FL:
  1301. port_type = FC_PORTTYPE_NLPORT;
  1302. break;
  1303. case ISP_CFG_N:
  1304. port_type = FC_PORTTYPE_PTP;
  1305. break;
  1306. case ISP_CFG_F:
  1307. port_type = FC_PORTTYPE_NPORT;
  1308. break;
  1309. }
  1310. fc_host_port_type(shost) = port_type;
  1311. }
  1312. static void
  1313. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1314. {
  1315. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1316. scsi_qla_host_t *vha = shost_priv(host);
  1317. fc_port_t *fcport;
  1318. u64 node_name = 0;
  1319. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1320. if (fcport->rport &&
  1321. starget->id == fcport->rport->scsi_target_id) {
  1322. node_name = wwn_to_u64(fcport->node_name);
  1323. break;
  1324. }
  1325. }
  1326. fc_starget_node_name(starget) = node_name;
  1327. }
  1328. static void
  1329. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1330. {
  1331. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1332. scsi_qla_host_t *vha = shost_priv(host);
  1333. fc_port_t *fcport;
  1334. u64 port_name = 0;
  1335. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1336. if (fcport->rport &&
  1337. starget->id == fcport->rport->scsi_target_id) {
  1338. port_name = wwn_to_u64(fcport->port_name);
  1339. break;
  1340. }
  1341. }
  1342. fc_starget_port_name(starget) = port_name;
  1343. }
  1344. static void
  1345. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1346. {
  1347. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1348. scsi_qla_host_t *vha = shost_priv(host);
  1349. fc_port_t *fcport;
  1350. uint32_t port_id = ~0U;
  1351. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1352. if (fcport->rport &&
  1353. starget->id == fcport->rport->scsi_target_id) {
  1354. port_id = fcport->d_id.b.domain << 16 |
  1355. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1356. break;
  1357. }
  1358. }
  1359. fc_starget_port_id(starget) = port_id;
  1360. }
  1361. static void
  1362. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1363. {
  1364. if (timeout)
  1365. rport->dev_loss_tmo = timeout;
  1366. else
  1367. rport->dev_loss_tmo = 1;
  1368. }
  1369. static void
  1370. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1371. {
  1372. struct Scsi_Host *host = rport_to_shost(rport);
  1373. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1374. unsigned long flags;
  1375. if (!fcport)
  1376. return;
  1377. /* Now that the rport has been deleted, set the fcport state to
  1378. FCS_DEVICE_DEAD */
  1379. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1380. /*
  1381. * Transport has effectively 'deleted' the rport, clear
  1382. * all local references.
  1383. */
  1384. spin_lock_irqsave(host->host_lock, flags);
  1385. fcport->rport = fcport->drport = NULL;
  1386. *((fc_port_t **)rport->dd_data) = NULL;
  1387. spin_unlock_irqrestore(host->host_lock, flags);
  1388. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1389. return;
  1390. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1391. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1392. return;
  1393. }
  1394. }
  1395. static void
  1396. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1397. {
  1398. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1399. if (!fcport)
  1400. return;
  1401. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1402. return;
  1403. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1404. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1405. return;
  1406. }
  1407. /*
  1408. * At this point all fcport's software-states are cleared. Perform any
  1409. * final cleanup of firmware resources (PCBs and XCBs).
  1410. */
  1411. if (fcport->loop_id != FC_NO_LOOP_ID) {
  1412. if (IS_FWI2_CAPABLE(fcport->vha->hw))
  1413. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1414. fcport->loop_id, fcport->d_id.b.domain,
  1415. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1416. else
  1417. qla2x00_port_logout(fcport->vha, fcport);
  1418. }
  1419. }
  1420. static int
  1421. qla2x00_issue_lip(struct Scsi_Host *shost)
  1422. {
  1423. scsi_qla_host_t *vha = shost_priv(shost);
  1424. if (IS_QLAFX00(vha->hw))
  1425. return 0;
  1426. qla2x00_loop_reset(vha);
  1427. return 0;
  1428. }
  1429. static struct fc_host_statistics *
  1430. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1431. {
  1432. scsi_qla_host_t *vha = shost_priv(shost);
  1433. struct qla_hw_data *ha = vha->hw;
  1434. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1435. int rval;
  1436. struct link_statistics *stats;
  1437. dma_addr_t stats_dma;
  1438. struct fc_host_statistics *pfc_host_stat;
  1439. pfc_host_stat = &vha->fc_host_stat;
  1440. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1441. if (IS_QLAFX00(vha->hw))
  1442. goto done;
  1443. if (test_bit(UNLOADING, &vha->dpc_flags))
  1444. goto done;
  1445. if (unlikely(pci_channel_offline(ha->pdev)))
  1446. goto done;
  1447. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1448. if (stats == NULL) {
  1449. ql_log(ql_log_warn, vha, 0x707d,
  1450. "Failed to allocate memory for stats.\n");
  1451. goto done;
  1452. }
  1453. memset(stats, 0, DMA_POOL_SIZE);
  1454. rval = QLA_FUNCTION_FAILED;
  1455. if (IS_FWI2_CAPABLE(ha)) {
  1456. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1457. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1458. !qla2x00_reset_active(vha) && !ha->dpc_active) {
  1459. /* Must be in a 'READY' state for statistics retrieval. */
  1460. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1461. stats, stats_dma);
  1462. }
  1463. if (rval != QLA_SUCCESS)
  1464. goto done_free;
  1465. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1466. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1467. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1468. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1469. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1470. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1471. if (IS_FWI2_CAPABLE(ha)) {
  1472. pfc_host_stat->lip_count = stats->lip_cnt;
  1473. pfc_host_stat->tx_frames = stats->tx_frames;
  1474. pfc_host_stat->rx_frames = stats->rx_frames;
  1475. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1476. pfc_host_stat->nos_count = stats->nos_rcvd;
  1477. }
  1478. pfc_host_stat->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
  1479. pfc_host_stat->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
  1480. done_free:
  1481. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1482. done:
  1483. return pfc_host_stat;
  1484. }
  1485. static void
  1486. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1487. {
  1488. scsi_qla_host_t *vha = shost_priv(shost);
  1489. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1490. }
  1491. static void
  1492. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1493. {
  1494. scsi_qla_host_t *vha = shost_priv(shost);
  1495. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1496. }
  1497. static void
  1498. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1499. {
  1500. scsi_qla_host_t *vha = shost_priv(shost);
  1501. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1502. 0xFF, 0xFF, 0xFF, 0xFF};
  1503. u64 fabric_name = wwn_to_u64(node_name);
  1504. if (vha->device_flags & SWITCH_FOUND)
  1505. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1506. fc_host_fabric_name(shost) = fabric_name;
  1507. }
  1508. static void
  1509. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1510. {
  1511. scsi_qla_host_t *vha = shost_priv(shost);
  1512. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1513. if (!base_vha->flags.online) {
  1514. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1515. return;
  1516. }
  1517. switch (atomic_read(&base_vha->loop_state)) {
  1518. case LOOP_UPDATE:
  1519. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1520. break;
  1521. case LOOP_DOWN:
  1522. if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
  1523. fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
  1524. else
  1525. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1526. break;
  1527. case LOOP_DEAD:
  1528. fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
  1529. break;
  1530. case LOOP_READY:
  1531. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1532. break;
  1533. default:
  1534. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1535. break;
  1536. }
  1537. }
  1538. static int
  1539. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1540. {
  1541. int ret = 0;
  1542. uint8_t qos = 0;
  1543. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1544. scsi_qla_host_t *vha = NULL;
  1545. struct qla_hw_data *ha = base_vha->hw;
  1546. uint16_t options = 0;
  1547. int cnt;
  1548. struct req_que *req = ha->req_q_map[0];
  1549. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1550. if (ret) {
  1551. ql_log(ql_log_warn, vha, 0x707e,
  1552. "Vport sanity check failed, status %x\n", ret);
  1553. return (ret);
  1554. }
  1555. vha = qla24xx_create_vhost(fc_vport);
  1556. if (vha == NULL) {
  1557. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1558. return FC_VPORT_FAILED;
  1559. }
  1560. if (disable) {
  1561. atomic_set(&vha->vp_state, VP_OFFLINE);
  1562. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1563. } else
  1564. atomic_set(&vha->vp_state, VP_FAILED);
  1565. /* ready to create vport */
  1566. ql_log(ql_log_info, vha, 0x7080,
  1567. "VP entry id %d assigned.\n", vha->vp_idx);
  1568. /* initialized vport states */
  1569. atomic_set(&vha->loop_state, LOOP_DOWN);
  1570. vha->vp_err_state= VP_ERR_PORTDWN;
  1571. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1572. /* Check if physical ha port is Up */
  1573. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1574. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1575. /* Don't retry or attempt login of this virtual port */
  1576. ql_dbg(ql_dbg_user, vha, 0x7081,
  1577. "Vport loop state is not UP.\n");
  1578. atomic_set(&vha->loop_state, LOOP_DEAD);
  1579. if (!disable)
  1580. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1581. }
  1582. if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
  1583. if (ha->fw_attributes & BIT_4) {
  1584. int prot = 0, guard;
  1585. vha->flags.difdix_supported = 1;
  1586. ql_dbg(ql_dbg_user, vha, 0x7082,
  1587. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1588. if (ql2xenabledif == 1)
  1589. prot = SHOST_DIX_TYPE0_PROTECTION;
  1590. scsi_host_set_prot(vha->host,
  1591. prot | SHOST_DIF_TYPE1_PROTECTION
  1592. | SHOST_DIF_TYPE2_PROTECTION
  1593. | SHOST_DIF_TYPE3_PROTECTION
  1594. | SHOST_DIX_TYPE1_PROTECTION
  1595. | SHOST_DIX_TYPE2_PROTECTION
  1596. | SHOST_DIX_TYPE3_PROTECTION);
  1597. guard = SHOST_DIX_GUARD_CRC;
  1598. if (IS_PI_IPGUARD_CAPABLE(ha) &&
  1599. (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
  1600. guard |= SHOST_DIX_GUARD_IP;
  1601. scsi_host_set_guard(vha->host, guard);
  1602. } else
  1603. vha->flags.difdix_supported = 0;
  1604. }
  1605. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1606. &ha->pdev->dev)) {
  1607. ql_dbg(ql_dbg_user, vha, 0x7083,
  1608. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1609. goto vport_create_failed_2;
  1610. }
  1611. /* initialize attributes */
  1612. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1613. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1614. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1615. fc_host_supported_classes(vha->host) =
  1616. fc_host_supported_classes(base_vha->host);
  1617. fc_host_supported_speeds(vha->host) =
  1618. fc_host_supported_speeds(base_vha->host);
  1619. qlt_vport_create(vha, ha);
  1620. qla24xx_vport_disable(fc_vport, disable);
  1621. if (ha->flags.cpu_affinity_enabled) {
  1622. req = ha->req_q_map[1];
  1623. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1624. "Request queue %p attached with "
  1625. "VP[%d], cpu affinity =%d\n",
  1626. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1627. goto vport_queue;
  1628. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1629. goto vport_queue;
  1630. /* Create a request queue in QoS mode for the vport */
  1631. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1632. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1633. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1634. 8) == 0) {
  1635. qos = ha->npiv_info[cnt].q_qos;
  1636. break;
  1637. }
  1638. }
  1639. if (qos) {
  1640. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1641. qos);
  1642. if (!ret)
  1643. ql_log(ql_log_warn, vha, 0x7084,
  1644. "Can't create request queue for VP[%d]\n",
  1645. vha->vp_idx);
  1646. else {
  1647. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1648. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1649. ret, qos, vha->vp_idx);
  1650. ql_dbg(ql_dbg_user, vha, 0x7085,
  1651. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1652. ret, qos, vha->vp_idx);
  1653. req = ha->req_q_map[ret];
  1654. }
  1655. }
  1656. vport_queue:
  1657. vha->req = req;
  1658. return 0;
  1659. vport_create_failed_2:
  1660. qla24xx_disable_vp(vha);
  1661. qla24xx_deallocate_vp_id(vha);
  1662. scsi_host_put(vha->host);
  1663. return FC_VPORT_FAILED;
  1664. }
  1665. static int
  1666. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1667. {
  1668. scsi_qla_host_t *vha = fc_vport->dd_data;
  1669. struct qla_hw_data *ha = vha->hw;
  1670. uint16_t id = vha->vp_idx;
  1671. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1672. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1673. msleep(1000);
  1674. qla24xx_disable_vp(vha);
  1675. vha->flags.delete_progress = 1;
  1676. fc_remove_host(vha->host);
  1677. scsi_remove_host(vha->host);
  1678. /* Allow timer to run to drain queued items, when removing vp */
  1679. qla24xx_deallocate_vp_id(vha);
  1680. if (vha->timer_active) {
  1681. qla2x00_vp_stop_timer(vha);
  1682. ql_dbg(ql_dbg_user, vha, 0x7086,
  1683. "Timer for the VP[%d] has stopped\n", vha->vp_idx);
  1684. }
  1685. BUG_ON(atomic_read(&vha->vref_count));
  1686. qla2x00_free_fcports(vha);
  1687. mutex_lock(&ha->vport_lock);
  1688. ha->cur_vport_count--;
  1689. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1690. mutex_unlock(&ha->vport_lock);
  1691. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1692. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1693. ql_log(ql_log_warn, vha, 0x7087,
  1694. "Queue delete failed.\n");
  1695. }
  1696. ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
  1697. scsi_host_put(vha->host);
  1698. return 0;
  1699. }
  1700. static int
  1701. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1702. {
  1703. scsi_qla_host_t *vha = fc_vport->dd_data;
  1704. if (disable)
  1705. qla24xx_disable_vp(vha);
  1706. else
  1707. qla24xx_enable_vp(vha);
  1708. return 0;
  1709. }
  1710. struct fc_function_template qla2xxx_transport_functions = {
  1711. .show_host_node_name = 1,
  1712. .show_host_port_name = 1,
  1713. .show_host_supported_classes = 1,
  1714. .show_host_supported_speeds = 1,
  1715. .get_host_port_id = qla2x00_get_host_port_id,
  1716. .show_host_port_id = 1,
  1717. .get_host_speed = qla2x00_get_host_speed,
  1718. .show_host_speed = 1,
  1719. .get_host_port_type = qla2x00_get_host_port_type,
  1720. .show_host_port_type = 1,
  1721. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1722. .show_host_symbolic_name = 1,
  1723. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1724. .show_host_system_hostname = 1,
  1725. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1726. .show_host_fabric_name = 1,
  1727. .get_host_port_state = qla2x00_get_host_port_state,
  1728. .show_host_port_state = 1,
  1729. .dd_fcrport_size = sizeof(struct fc_port *),
  1730. .show_rport_supported_classes = 1,
  1731. .get_starget_node_name = qla2x00_get_starget_node_name,
  1732. .show_starget_node_name = 1,
  1733. .get_starget_port_name = qla2x00_get_starget_port_name,
  1734. .show_starget_port_name = 1,
  1735. .get_starget_port_id = qla2x00_get_starget_port_id,
  1736. .show_starget_port_id = 1,
  1737. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1738. .show_rport_dev_loss_tmo = 1,
  1739. .issue_fc_host_lip = qla2x00_issue_lip,
  1740. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1741. .terminate_rport_io = qla2x00_terminate_rport_io,
  1742. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1743. .vport_create = qla24xx_vport_create,
  1744. .vport_disable = qla24xx_vport_disable,
  1745. .vport_delete = qla24xx_vport_delete,
  1746. .bsg_request = qla24xx_bsg_request,
  1747. .bsg_timeout = qla24xx_bsg_timeout,
  1748. };
  1749. struct fc_function_template qla2xxx_transport_vport_functions = {
  1750. .show_host_node_name = 1,
  1751. .show_host_port_name = 1,
  1752. .show_host_supported_classes = 1,
  1753. .get_host_port_id = qla2x00_get_host_port_id,
  1754. .show_host_port_id = 1,
  1755. .get_host_speed = qla2x00_get_host_speed,
  1756. .show_host_speed = 1,
  1757. .get_host_port_type = qla2x00_get_host_port_type,
  1758. .show_host_port_type = 1,
  1759. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1760. .show_host_symbolic_name = 1,
  1761. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1762. .show_host_system_hostname = 1,
  1763. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1764. .show_host_fabric_name = 1,
  1765. .get_host_port_state = qla2x00_get_host_port_state,
  1766. .show_host_port_state = 1,
  1767. .dd_fcrport_size = sizeof(struct fc_port *),
  1768. .show_rport_supported_classes = 1,
  1769. .get_starget_node_name = qla2x00_get_starget_node_name,
  1770. .show_starget_node_name = 1,
  1771. .get_starget_port_name = qla2x00_get_starget_port_name,
  1772. .show_starget_port_name = 1,
  1773. .get_starget_port_id = qla2x00_get_starget_port_id,
  1774. .show_starget_port_id = 1,
  1775. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1776. .show_rport_dev_loss_tmo = 1,
  1777. .issue_fc_host_lip = qla2x00_issue_lip,
  1778. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1779. .terminate_rport_io = qla2x00_terminate_rport_io,
  1780. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1781. .bsg_request = qla24xx_bsg_request,
  1782. .bsg_timeout = qla24xx_bsg_timeout,
  1783. };
  1784. void
  1785. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1786. {
  1787. struct qla_hw_data *ha = vha->hw;
  1788. u32 speed = FC_PORTSPEED_UNKNOWN;
  1789. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1790. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1791. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1792. fc_host_supported_classes(vha->host) = ha->tgt.enable_class_2 ?
  1793. (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
  1794. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1795. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1796. if (IS_CNA_CAPABLE(ha))
  1797. speed = FC_PORTSPEED_10GBIT;
  1798. else if (IS_QLA2031(ha))
  1799. speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
  1800. FC_PORTSPEED_4GBIT;
  1801. else if (IS_QLA25XX(ha))
  1802. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1803. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1804. else if (IS_QLA24XX_TYPE(ha))
  1805. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1806. FC_PORTSPEED_1GBIT;
  1807. else if (IS_QLA23XX(ha))
  1808. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1809. else if (IS_QLAFX00(ha))
  1810. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1811. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1812. else
  1813. speed = FC_PORTSPEED_1GBIT;
  1814. fc_host_supported_speeds(vha->host) = speed;
  1815. }