qla_attr.c 53 KB

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