qla_attr.c 54 KB

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