qla_attr.c 49 KB

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