qla_attr.c 55 KB

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