qla_attr.c 57 KB

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