qla_attr.c 52 KB

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