qla_attr.c 62 KB

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