qla_attr.c 62 KB

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