qla_attr.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  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. /* Read NVRAM data from cache. */
  84. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  85. ha->nvram_size);
  86. }
  87. static ssize_t
  88. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  89. struct bin_attribute *bin_attr,
  90. char *buf, loff_t off, size_t count)
  91. {
  92. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  93. struct device, kobj)));
  94. struct qla_hw_data *ha = vha->hw;
  95. uint16_t cnt;
  96. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
  97. return 0;
  98. /* Checksum NVRAM. */
  99. if (IS_FWI2_CAPABLE(ha)) {
  100. uint32_t *iter;
  101. uint32_t chksum;
  102. iter = (uint32_t *)buf;
  103. chksum = 0;
  104. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  105. chksum += le32_to_cpu(*iter++);
  106. chksum = ~chksum + 1;
  107. *iter = cpu_to_le32(chksum);
  108. } else {
  109. uint8_t *iter;
  110. uint8_t chksum;
  111. iter = (uint8_t *)buf;
  112. chksum = 0;
  113. for (cnt = 0; cnt < count - 1; cnt++)
  114. chksum += *iter++;
  115. chksum = ~chksum + 1;
  116. *iter = chksum;
  117. }
  118. /* Write NVRAM. */
  119. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  120. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  121. count);
  122. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  123. return (count);
  124. }
  125. static struct bin_attribute sysfs_nvram_attr = {
  126. .attr = {
  127. .name = "nvram",
  128. .mode = S_IRUSR | S_IWUSR,
  129. },
  130. .size = 512,
  131. .read = qla2x00_sysfs_read_nvram,
  132. .write = qla2x00_sysfs_write_nvram,
  133. };
  134. static ssize_t
  135. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  136. struct bin_attribute *bin_attr,
  137. char *buf, loff_t off, size_t count)
  138. {
  139. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  140. struct device, kobj)));
  141. struct qla_hw_data *ha = vha->hw;
  142. if (ha->optrom_state != QLA_SREADING)
  143. return 0;
  144. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  145. ha->optrom_region_size);
  146. }
  147. static ssize_t
  148. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  149. struct bin_attribute *bin_attr,
  150. char *buf, loff_t off, size_t count)
  151. {
  152. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  153. struct device, kobj)));
  154. struct qla_hw_data *ha = vha->hw;
  155. if (ha->optrom_state != QLA_SWRITING)
  156. return -EINVAL;
  157. if (off > ha->optrom_region_size)
  158. return -ERANGE;
  159. if (off + count > ha->optrom_region_size)
  160. count = ha->optrom_region_size - off;
  161. memcpy(&ha->optrom_buffer[off], buf, count);
  162. return count;
  163. }
  164. static struct bin_attribute sysfs_optrom_attr = {
  165. .attr = {
  166. .name = "optrom",
  167. .mode = S_IRUSR | S_IWUSR,
  168. },
  169. .size = 0,
  170. .read = qla2x00_sysfs_read_optrom,
  171. .write = qla2x00_sysfs_write_optrom,
  172. };
  173. static ssize_t
  174. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  175. struct bin_attribute *bin_attr,
  176. char *buf, loff_t off, size_t count)
  177. {
  178. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  179. struct device, kobj)));
  180. struct qla_hw_data *ha = vha->hw;
  181. uint32_t start = 0;
  182. uint32_t size = ha->optrom_size;
  183. int val, valid;
  184. if (off)
  185. return 0;
  186. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  187. return -EINVAL;
  188. if (start > ha->optrom_size)
  189. return -EINVAL;
  190. switch (val) {
  191. case 0:
  192. if (ha->optrom_state != QLA_SREADING &&
  193. ha->optrom_state != QLA_SWRITING)
  194. break;
  195. ha->optrom_state = QLA_SWAITING;
  196. DEBUG2(qla_printk(KERN_INFO, ha,
  197. "Freeing flash region allocation -- 0x%x bytes.\n",
  198. ha->optrom_region_size));
  199. vfree(ha->optrom_buffer);
  200. ha->optrom_buffer = NULL;
  201. break;
  202. case 1:
  203. if (ha->optrom_state != QLA_SWAITING)
  204. break;
  205. if (start & 0xfff) {
  206. qla_printk(KERN_WARNING, ha,
  207. "Invalid start region 0x%x/0x%x.\n", start, size);
  208. return -EINVAL;
  209. }
  210. ha->optrom_region_start = start;
  211. ha->optrom_region_size = start + size > ha->optrom_size ?
  212. ha->optrom_size - start : size;
  213. ha->optrom_state = QLA_SREADING;
  214. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  215. if (ha->optrom_buffer == NULL) {
  216. qla_printk(KERN_WARNING, ha,
  217. "Unable to allocate memory for optrom retrieval "
  218. "(%x).\n", ha->optrom_region_size);
  219. ha->optrom_state = QLA_SWAITING;
  220. return count;
  221. }
  222. DEBUG2(qla_printk(KERN_INFO, ha,
  223. "Reading flash region -- 0x%x/0x%x.\n",
  224. ha->optrom_region_start, ha->optrom_region_size));
  225. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  226. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  227. ha->optrom_region_start, ha->optrom_region_size);
  228. break;
  229. case 2:
  230. if (ha->optrom_state != QLA_SWAITING)
  231. break;
  232. /*
  233. * We need to be more restrictive on which FLASH regions are
  234. * allowed to be updated via user-space. Regions accessible
  235. * via this method include:
  236. *
  237. * ISP21xx/ISP22xx/ISP23xx type boards:
  238. *
  239. * 0x000000 -> 0x020000 -- Boot code.
  240. *
  241. * ISP2322/ISP24xx type boards:
  242. *
  243. * 0x000000 -> 0x07ffff -- Boot code.
  244. * 0x080000 -> 0x0fffff -- Firmware.
  245. *
  246. * ISP25xx type boards:
  247. *
  248. * 0x000000 -> 0x07ffff -- Boot code.
  249. * 0x080000 -> 0x0fffff -- Firmware.
  250. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  251. */
  252. valid = 0;
  253. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  254. valid = 1;
  255. else if (start == (ha->flt_region_boot * 4) ||
  256. start == (ha->flt_region_fw * 4))
  257. valid = 1;
  258. else if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) &&
  259. start == (ha->flt_region_vpd_nvram * 4))
  260. valid = 1;
  261. if (!valid) {
  262. qla_printk(KERN_WARNING, ha,
  263. "Invalid start region 0x%x/0x%x.\n", start, size);
  264. return -EINVAL;
  265. }
  266. ha->optrom_region_start = start;
  267. ha->optrom_region_size = start + size > ha->optrom_size ?
  268. ha->optrom_size - start : size;
  269. ha->optrom_state = QLA_SWRITING;
  270. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  271. if (ha->optrom_buffer == NULL) {
  272. qla_printk(KERN_WARNING, ha,
  273. "Unable to allocate memory for optrom update "
  274. "(%x).\n", ha->optrom_region_size);
  275. ha->optrom_state = QLA_SWAITING;
  276. return count;
  277. }
  278. DEBUG2(qla_printk(KERN_INFO, ha,
  279. "Staging flash region write -- 0x%x/0x%x.\n",
  280. ha->optrom_region_start, ha->optrom_region_size));
  281. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  282. break;
  283. case 3:
  284. if (ha->optrom_state != QLA_SWRITING)
  285. break;
  286. DEBUG2(qla_printk(KERN_INFO, ha,
  287. "Writing flash region -- 0x%x/0x%x.\n",
  288. ha->optrom_region_start, ha->optrom_region_size));
  289. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  290. ha->optrom_region_start, ha->optrom_region_size);
  291. break;
  292. default:
  293. count = -EINVAL;
  294. }
  295. return count;
  296. }
  297. static struct bin_attribute sysfs_optrom_ctl_attr = {
  298. .attr = {
  299. .name = "optrom_ctl",
  300. .mode = S_IWUSR,
  301. },
  302. .size = 0,
  303. .write = qla2x00_sysfs_write_optrom_ctl,
  304. };
  305. static ssize_t
  306. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  307. struct bin_attribute *bin_attr,
  308. char *buf, loff_t off, size_t count)
  309. {
  310. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  311. struct device, kobj)));
  312. struct qla_hw_data *ha = vha->hw;
  313. if (!capable(CAP_SYS_ADMIN))
  314. return 0;
  315. /* Read NVRAM data from cache. */
  316. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  317. }
  318. static ssize_t
  319. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  320. struct bin_attribute *bin_attr,
  321. char *buf, loff_t off, size_t count)
  322. {
  323. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  324. struct device, kobj)));
  325. struct qla_hw_data *ha = vha->hw;
  326. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
  327. return 0;
  328. /* Write NVRAM. */
  329. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  330. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  331. return count;
  332. }
  333. static struct bin_attribute sysfs_vpd_attr = {
  334. .attr = {
  335. .name = "vpd",
  336. .mode = S_IRUSR | S_IWUSR,
  337. },
  338. .size = 0,
  339. .read = qla2x00_sysfs_read_vpd,
  340. .write = qla2x00_sysfs_write_vpd,
  341. };
  342. static ssize_t
  343. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  344. struct bin_attribute *bin_attr,
  345. char *buf, loff_t off, size_t count)
  346. {
  347. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  348. struct device, kobj)));
  349. struct qla_hw_data *ha = vha->hw;
  350. uint16_t iter, addr, offset;
  351. int rval;
  352. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  353. return 0;
  354. if (ha->sfp_data)
  355. goto do_read;
  356. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  357. &ha->sfp_data_dma);
  358. if (!ha->sfp_data) {
  359. qla_printk(KERN_WARNING, ha,
  360. "Unable to allocate memory for SFP read-data.\n");
  361. return 0;
  362. }
  363. do_read:
  364. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  365. addr = 0xa0;
  366. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  367. iter++, offset += SFP_BLOCK_SIZE) {
  368. if (iter == 4) {
  369. /* Skip to next device address. */
  370. addr = 0xa2;
  371. offset = 0;
  372. }
  373. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  374. SFP_BLOCK_SIZE);
  375. if (rval != QLA_SUCCESS) {
  376. qla_printk(KERN_WARNING, ha,
  377. "Unable to read SFP data (%x/%x/%x).\n", rval,
  378. addr, offset);
  379. count = 0;
  380. break;
  381. }
  382. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  383. buf += SFP_BLOCK_SIZE;
  384. }
  385. return count;
  386. }
  387. static struct bin_attribute sysfs_sfp_attr = {
  388. .attr = {
  389. .name = "sfp",
  390. .mode = S_IRUSR | S_IWUSR,
  391. },
  392. .size = SFP_DEV_SIZE * 2,
  393. .read = qla2x00_sysfs_read_sfp,
  394. };
  395. static struct sysfs_entry {
  396. char *name;
  397. struct bin_attribute *attr;
  398. int is4GBp_only;
  399. } bin_file_entries[] = {
  400. { "fw_dump", &sysfs_fw_dump_attr, },
  401. { "nvram", &sysfs_nvram_attr, },
  402. { "optrom", &sysfs_optrom_attr, },
  403. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  404. { "vpd", &sysfs_vpd_attr, 1 },
  405. { "sfp", &sysfs_sfp_attr, 1 },
  406. { NULL },
  407. };
  408. void
  409. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  410. {
  411. struct Scsi_Host *host = vha->host;
  412. struct sysfs_entry *iter;
  413. int ret;
  414. for (iter = bin_file_entries; iter->name; iter++) {
  415. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  416. continue;
  417. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  418. iter->attr);
  419. if (ret)
  420. qla_printk(KERN_INFO, vha->hw,
  421. "Unable to create sysfs %s binary attribute "
  422. "(%d).\n", iter->name, ret);
  423. }
  424. }
  425. void
  426. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  427. {
  428. struct Scsi_Host *host = vha->host;
  429. struct sysfs_entry *iter;
  430. struct qla_hw_data *ha = vha->hw;
  431. for (iter = bin_file_entries; iter->name; iter++) {
  432. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  433. continue;
  434. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  435. iter->attr);
  436. }
  437. if (ha->beacon_blink_led == 1)
  438. ha->isp_ops->beacon_off(vha);
  439. }
  440. /* Scsi_Host attributes. */
  441. static ssize_t
  442. qla2x00_drvr_version_show(struct device *dev,
  443. struct device_attribute *attr, char *buf)
  444. {
  445. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  446. }
  447. static ssize_t
  448. qla2x00_fw_version_show(struct device *dev,
  449. struct device_attribute *attr, char *buf)
  450. {
  451. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  452. struct qla_hw_data *ha = vha->hw;
  453. char fw_str[128];
  454. return snprintf(buf, PAGE_SIZE, "%s\n",
  455. ha->isp_ops->fw_version_str(vha, fw_str));
  456. }
  457. static ssize_t
  458. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  459. char *buf)
  460. {
  461. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  462. struct qla_hw_data *ha = vha->hw;
  463. uint32_t sn;
  464. if (IS_FWI2_CAPABLE(ha)) {
  465. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  466. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  467. }
  468. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  469. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  470. sn % 100000);
  471. }
  472. static ssize_t
  473. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  474. char *buf)
  475. {
  476. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  477. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  478. }
  479. static ssize_t
  480. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  481. char *buf)
  482. {
  483. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  484. struct qla_hw_data *ha = vha->hw;
  485. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  486. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  487. ha->product_id[3]);
  488. }
  489. static ssize_t
  490. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  491. char *buf)
  492. {
  493. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  494. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  495. }
  496. static ssize_t
  497. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  498. char *buf)
  499. {
  500. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  501. return snprintf(buf, PAGE_SIZE, "%s\n",
  502. vha->hw->model_desc ? vha->hw->model_desc : "");
  503. }
  504. static ssize_t
  505. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  506. char *buf)
  507. {
  508. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  509. char pci_info[30];
  510. return snprintf(buf, PAGE_SIZE, "%s\n",
  511. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  512. }
  513. static ssize_t
  514. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  515. char *buf)
  516. {
  517. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  518. struct qla_hw_data *ha = vha->hw;
  519. int len = 0;
  520. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  521. atomic_read(&vha->loop_state) == LOOP_DEAD)
  522. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  523. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  524. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  525. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  526. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  527. else {
  528. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  529. switch (ha->current_topology) {
  530. case ISP_CFG_NL:
  531. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  532. break;
  533. case ISP_CFG_FL:
  534. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  535. break;
  536. case ISP_CFG_N:
  537. len += snprintf(buf + len, PAGE_SIZE-len,
  538. "N_Port to N_Port\n");
  539. break;
  540. case ISP_CFG_F:
  541. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  542. break;
  543. default:
  544. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  545. break;
  546. }
  547. }
  548. return len;
  549. }
  550. static ssize_t
  551. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  552. char *buf)
  553. {
  554. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  555. int len = 0;
  556. switch (vha->hw->zio_mode) {
  557. case QLA_ZIO_MODE_6:
  558. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  559. break;
  560. case QLA_ZIO_DISABLED:
  561. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  562. break;
  563. }
  564. return len;
  565. }
  566. static ssize_t
  567. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  568. const char *buf, size_t count)
  569. {
  570. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  571. struct qla_hw_data *ha = vha->hw;
  572. int val = 0;
  573. uint16_t zio_mode;
  574. if (!IS_ZIO_SUPPORTED(ha))
  575. return -ENOTSUPP;
  576. if (sscanf(buf, "%d", &val) != 1)
  577. return -EINVAL;
  578. if (val)
  579. zio_mode = QLA_ZIO_MODE_6;
  580. else
  581. zio_mode = QLA_ZIO_DISABLED;
  582. /* Update per-hba values and queue a reset. */
  583. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  584. ha->zio_mode = zio_mode;
  585. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  586. }
  587. return strlen(buf);
  588. }
  589. static ssize_t
  590. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  591. char *buf)
  592. {
  593. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  594. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  595. }
  596. static ssize_t
  597. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  598. const char *buf, size_t count)
  599. {
  600. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  601. int val = 0;
  602. uint16_t zio_timer;
  603. if (sscanf(buf, "%d", &val) != 1)
  604. return -EINVAL;
  605. if (val > 25500 || val < 100)
  606. return -ERANGE;
  607. zio_timer = (uint16_t)(val / 100);
  608. vha->hw->zio_timer = zio_timer;
  609. return strlen(buf);
  610. }
  611. static ssize_t
  612. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  613. char *buf)
  614. {
  615. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  616. int len = 0;
  617. if (vha->hw->beacon_blink_led)
  618. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  619. else
  620. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  621. return len;
  622. }
  623. static ssize_t
  624. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  625. const char *buf, size_t count)
  626. {
  627. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  628. struct qla_hw_data *ha = vha->hw;
  629. int val = 0;
  630. int rval;
  631. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  632. return -EPERM;
  633. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  634. qla_printk(KERN_WARNING, ha,
  635. "Abort ISP active -- ignoring beacon request.\n");
  636. return -EBUSY;
  637. }
  638. if (sscanf(buf, "%d", &val) != 1)
  639. return -EINVAL;
  640. if (val)
  641. rval = ha->isp_ops->beacon_on(vha);
  642. else
  643. rval = ha->isp_ops->beacon_off(vha);
  644. if (rval != QLA_SUCCESS)
  645. count = 0;
  646. return count;
  647. }
  648. static ssize_t
  649. qla2x00_optrom_bios_version_show(struct device *dev,
  650. struct device_attribute *attr, char *buf)
  651. {
  652. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  653. struct qla_hw_data *ha = vha->hw;
  654. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  655. ha->bios_revision[0]);
  656. }
  657. static ssize_t
  658. qla2x00_optrom_efi_version_show(struct device *dev,
  659. struct device_attribute *attr, char *buf)
  660. {
  661. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  662. struct qla_hw_data *ha = vha->hw;
  663. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  664. ha->efi_revision[0]);
  665. }
  666. static ssize_t
  667. qla2x00_optrom_fcode_version_show(struct device *dev,
  668. struct device_attribute *attr, char *buf)
  669. {
  670. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  671. struct qla_hw_data *ha = vha->hw;
  672. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  673. ha->fcode_revision[0]);
  674. }
  675. static ssize_t
  676. qla2x00_optrom_fw_version_show(struct device *dev,
  677. struct device_attribute *attr, char *buf)
  678. {
  679. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  680. struct qla_hw_data *ha = vha->hw;
  681. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  682. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  683. ha->fw_revision[3]);
  684. }
  685. static ssize_t
  686. qla2x00_total_isp_aborts_show(struct device *dev,
  687. struct device_attribute *attr, char *buf)
  688. {
  689. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  690. struct qla_hw_data *ha = vha->hw;
  691. return snprintf(buf, PAGE_SIZE, "%d\n",
  692. ha->qla_stats.total_isp_aborts);
  693. }
  694. static ssize_t
  695. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  696. char *buf)
  697. {
  698. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  699. struct qla_hw_data *ha = vha->hw;
  700. if (!IS_QLA81XX(ha))
  701. return snprintf(buf, PAGE_SIZE, "\n");
  702. return snprintf(buf, PAGE_SIZE, "%02x.%02x.%02x.%02x (%x)\n",
  703. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  704. ha->mpi_version[3], ha->mpi_capabilities);
  705. }
  706. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  707. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  708. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  709. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  710. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  711. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  712. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  713. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  714. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  715. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  716. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  717. qla2x00_zio_timer_store);
  718. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  719. qla2x00_beacon_store);
  720. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  721. qla2x00_optrom_bios_version_show, NULL);
  722. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  723. qla2x00_optrom_efi_version_show, NULL);
  724. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  725. qla2x00_optrom_fcode_version_show, NULL);
  726. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  727. NULL);
  728. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  729. NULL);
  730. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  731. struct device_attribute *qla2x00_host_attrs[] = {
  732. &dev_attr_driver_version,
  733. &dev_attr_fw_version,
  734. &dev_attr_serial_num,
  735. &dev_attr_isp_name,
  736. &dev_attr_isp_id,
  737. &dev_attr_model_name,
  738. &dev_attr_model_desc,
  739. &dev_attr_pci_info,
  740. &dev_attr_link_state,
  741. &dev_attr_zio,
  742. &dev_attr_zio_timer,
  743. &dev_attr_beacon,
  744. &dev_attr_optrom_bios_version,
  745. &dev_attr_optrom_efi_version,
  746. &dev_attr_optrom_fcode_version,
  747. &dev_attr_optrom_fw_version,
  748. &dev_attr_total_isp_aborts,
  749. &dev_attr_mpi_version,
  750. NULL,
  751. };
  752. /* Host attributes. */
  753. static void
  754. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  755. {
  756. scsi_qla_host_t *vha = shost_priv(shost);
  757. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  758. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  759. }
  760. static void
  761. qla2x00_get_host_speed(struct Scsi_Host *shost)
  762. {
  763. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  764. (shost_priv(shost)))->hw;
  765. u32 speed = FC_PORTSPEED_UNKNOWN;
  766. switch (ha->link_data_rate) {
  767. case PORT_SPEED_1GB:
  768. speed = FC_PORTSPEED_1GBIT;
  769. break;
  770. case PORT_SPEED_2GB:
  771. speed = FC_PORTSPEED_2GBIT;
  772. break;
  773. case PORT_SPEED_4GB:
  774. speed = FC_PORTSPEED_4GBIT;
  775. break;
  776. case PORT_SPEED_8GB:
  777. speed = FC_PORTSPEED_8GBIT;
  778. break;
  779. case PORT_SPEED_10GB:
  780. speed = FC_PORTSPEED_10GBIT;
  781. break;
  782. }
  783. fc_host_speed(shost) = speed;
  784. }
  785. static void
  786. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  787. {
  788. scsi_qla_host_t *vha = shost_priv(shost);
  789. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  790. if (vha->vp_idx) {
  791. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  792. return;
  793. }
  794. switch (vha->hw->current_topology) {
  795. case ISP_CFG_NL:
  796. port_type = FC_PORTTYPE_LPORT;
  797. break;
  798. case ISP_CFG_FL:
  799. port_type = FC_PORTTYPE_NLPORT;
  800. break;
  801. case ISP_CFG_N:
  802. port_type = FC_PORTTYPE_PTP;
  803. break;
  804. case ISP_CFG_F:
  805. port_type = FC_PORTTYPE_NPORT;
  806. break;
  807. }
  808. fc_host_port_type(shost) = port_type;
  809. }
  810. static void
  811. qla2x00_get_starget_node_name(struct scsi_target *starget)
  812. {
  813. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  814. scsi_qla_host_t *vha = shost_priv(host);
  815. fc_port_t *fcport;
  816. u64 node_name = 0;
  817. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  818. if (fcport->rport &&
  819. starget->id == fcport->rport->scsi_target_id) {
  820. node_name = wwn_to_u64(fcport->node_name);
  821. break;
  822. }
  823. }
  824. fc_starget_node_name(starget) = node_name;
  825. }
  826. static void
  827. qla2x00_get_starget_port_name(struct scsi_target *starget)
  828. {
  829. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  830. scsi_qla_host_t *vha = shost_priv(host);
  831. fc_port_t *fcport;
  832. u64 port_name = 0;
  833. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  834. if (fcport->rport &&
  835. starget->id == fcport->rport->scsi_target_id) {
  836. port_name = wwn_to_u64(fcport->port_name);
  837. break;
  838. }
  839. }
  840. fc_starget_port_name(starget) = port_name;
  841. }
  842. static void
  843. qla2x00_get_starget_port_id(struct scsi_target *starget)
  844. {
  845. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  846. scsi_qla_host_t *vha = shost_priv(host);
  847. fc_port_t *fcport;
  848. uint32_t port_id = ~0U;
  849. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  850. if (fcport->rport &&
  851. starget->id == fcport->rport->scsi_target_id) {
  852. port_id = fcport->d_id.b.domain << 16 |
  853. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  854. break;
  855. }
  856. }
  857. fc_starget_port_id(starget) = port_id;
  858. }
  859. static void
  860. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  861. {
  862. if (timeout)
  863. rport->dev_loss_tmo = timeout;
  864. else
  865. rport->dev_loss_tmo = 1;
  866. }
  867. static void
  868. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  869. {
  870. struct Scsi_Host *host = rport_to_shost(rport);
  871. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  872. if (!fcport)
  873. return;
  874. qla2x00_abort_fcport_cmds(fcport);
  875. /*
  876. * Transport has effectively 'deleted' the rport, clear
  877. * all local references.
  878. */
  879. spin_lock_irq(host->host_lock);
  880. fcport->rport = NULL;
  881. *((fc_port_t **)rport->dd_data) = NULL;
  882. spin_unlock_irq(host->host_lock);
  883. }
  884. static void
  885. qla2x00_terminate_rport_io(struct fc_rport *rport)
  886. {
  887. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  888. if (!fcport)
  889. return;
  890. /*
  891. * At this point all fcport's software-states are cleared. Perform any
  892. * final cleanup of firmware resources (PCBs and XCBs).
  893. */
  894. if (fcport->loop_id != FC_NO_LOOP_ID) {
  895. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  896. fcport->loop_id, fcport->d_id.b.domain,
  897. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  898. fcport->loop_id = FC_NO_LOOP_ID;
  899. }
  900. qla2x00_abort_fcport_cmds(fcport);
  901. }
  902. static int
  903. qla2x00_issue_lip(struct Scsi_Host *shost)
  904. {
  905. scsi_qla_host_t *vha = shost_priv(shost);
  906. qla2x00_loop_reset(vha);
  907. return 0;
  908. }
  909. static struct fc_host_statistics *
  910. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  911. {
  912. scsi_qla_host_t *vha = shost_priv(shost);
  913. struct qla_hw_data *ha = vha->hw;
  914. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  915. int rval;
  916. struct link_statistics *stats;
  917. dma_addr_t stats_dma;
  918. struct fc_host_statistics *pfc_host_stat;
  919. pfc_host_stat = &ha->fc_host_stat;
  920. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  921. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  922. if (stats == NULL) {
  923. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  924. __func__, base_vha->host_no));
  925. goto done;
  926. }
  927. memset(stats, 0, DMA_POOL_SIZE);
  928. rval = QLA_FUNCTION_FAILED;
  929. if (IS_FWI2_CAPABLE(ha)) {
  930. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  931. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  932. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  933. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  934. !ha->dpc_active) {
  935. /* Must be in a 'READY' state for statistics retrieval. */
  936. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  937. stats, stats_dma);
  938. }
  939. if (rval != QLA_SUCCESS)
  940. goto done_free;
  941. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  942. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  943. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  944. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  945. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  946. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  947. if (IS_FWI2_CAPABLE(ha)) {
  948. pfc_host_stat->lip_count = stats->lip_cnt;
  949. pfc_host_stat->tx_frames = stats->tx_frames;
  950. pfc_host_stat->rx_frames = stats->rx_frames;
  951. pfc_host_stat->dumped_frames = stats->dumped_frames;
  952. pfc_host_stat->nos_count = stats->nos_rcvd;
  953. }
  954. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  955. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  956. done_free:
  957. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  958. done:
  959. return pfc_host_stat;
  960. }
  961. static void
  962. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  963. {
  964. scsi_qla_host_t *vha = shost_priv(shost);
  965. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  966. }
  967. static void
  968. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  969. {
  970. scsi_qla_host_t *vha = shost_priv(shost);
  971. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  972. }
  973. static void
  974. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  975. {
  976. scsi_qla_host_t *vha = shost_priv(shost);
  977. u64 node_name;
  978. if (vha->device_flags & SWITCH_FOUND)
  979. node_name = wwn_to_u64(vha->fabric_node_name);
  980. else
  981. node_name = wwn_to_u64(vha->node_name);
  982. fc_host_fabric_name(shost) = node_name;
  983. }
  984. static void
  985. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  986. {
  987. scsi_qla_host_t *vha = shost_priv(shost);
  988. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  989. if (!base_vha->flags.online)
  990. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  991. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  992. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  993. else
  994. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  995. }
  996. static int
  997. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  998. {
  999. int ret = 0;
  1000. int cnt = 0;
  1001. uint8_t qos = QLA_DEFAULT_QUE_QOS;
  1002. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1003. scsi_qla_host_t *vha = NULL;
  1004. struct qla_hw_data *ha = base_vha->hw;
  1005. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1006. if (ret) {
  1007. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1008. "status %x\n", ret));
  1009. return (ret);
  1010. }
  1011. vha = qla24xx_create_vhost(fc_vport);
  1012. if (vha == NULL) {
  1013. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1014. vha));
  1015. return FC_VPORT_FAILED;
  1016. }
  1017. if (disable) {
  1018. atomic_set(&vha->vp_state, VP_OFFLINE);
  1019. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1020. } else
  1021. atomic_set(&vha->vp_state, VP_FAILED);
  1022. /* ready to create vport */
  1023. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1024. vha->vp_idx);
  1025. /* initialized vport states */
  1026. atomic_set(&vha->loop_state, LOOP_DOWN);
  1027. vha->vp_err_state= VP_ERR_PORTDWN;
  1028. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1029. /* Check if physical ha port is Up */
  1030. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1031. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1032. /* Don't retry or attempt login of this virtual port */
  1033. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1034. base_vha->host_no));
  1035. atomic_set(&vha->loop_state, LOOP_DEAD);
  1036. if (!disable)
  1037. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1038. }
  1039. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  1040. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1041. vha->host_no, vha->vp_idx));
  1042. goto vport_create_failed_2;
  1043. }
  1044. /* initialize attributes */
  1045. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1046. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1047. fc_host_supported_classes(vha->host) =
  1048. fc_host_supported_classes(base_vha->host);
  1049. fc_host_supported_speeds(vha->host) =
  1050. fc_host_supported_speeds(base_vha->host);
  1051. qla24xx_vport_disable(fc_vport, disable);
  1052. /* Create a queue pair for the vport */
  1053. if (ha->mqenable) {
  1054. if (ha->npiv_info) {
  1055. for (; cnt < ha->nvram_npiv_size; cnt++) {
  1056. if (ha->npiv_info[cnt].port_name ==
  1057. vha->port_name &&
  1058. ha->npiv_info[cnt].node_name ==
  1059. vha->node_name) {
  1060. qos = ha->npiv_info[cnt].q_qos;
  1061. break;
  1062. }
  1063. }
  1064. }
  1065. qla25xx_create_queues(vha, qos);
  1066. }
  1067. return 0;
  1068. vport_create_failed_2:
  1069. qla24xx_disable_vp(vha);
  1070. qla24xx_deallocate_vp_id(vha);
  1071. scsi_host_put(vha->host);
  1072. return FC_VPORT_FAILED;
  1073. }
  1074. static int
  1075. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1076. {
  1077. scsi_qla_host_t *vha = fc_vport->dd_data;
  1078. fc_port_t *fcport, *tfcport;
  1079. struct qla_hw_data *ha = vha->hw;
  1080. uint16_t id = vha->vp_idx;
  1081. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1082. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1083. msleep(1000);
  1084. if (ha->mqenable) {
  1085. if (qla25xx_delete_queues(vha, 0) != QLA_SUCCESS)
  1086. qla_printk(KERN_WARNING, ha,
  1087. "Queue delete failed.\n");
  1088. vha->req_ques[0] = ha->req_q_map[0]->id;
  1089. }
  1090. qla24xx_disable_vp(vha);
  1091. fc_remove_host(vha->host);
  1092. scsi_remove_host(vha->host);
  1093. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1094. list_del(&fcport->list);
  1095. kfree(fcport);
  1096. fcport = NULL;
  1097. }
  1098. qla24xx_deallocate_vp_id(vha);
  1099. if (vha->timer_active) {
  1100. qla2x00_vp_stop_timer(vha);
  1101. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1102. "has stopped\n",
  1103. vha->host_no, vha->vp_idx, vha));
  1104. }
  1105. scsi_host_put(vha->host);
  1106. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1107. return 0;
  1108. }
  1109. static int
  1110. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1111. {
  1112. scsi_qla_host_t *vha = fc_vport->dd_data;
  1113. if (disable)
  1114. qla24xx_disable_vp(vha);
  1115. else
  1116. qla24xx_enable_vp(vha);
  1117. return 0;
  1118. }
  1119. struct fc_function_template qla2xxx_transport_functions = {
  1120. .show_host_node_name = 1,
  1121. .show_host_port_name = 1,
  1122. .show_host_supported_classes = 1,
  1123. .show_host_supported_speeds = 1,
  1124. .get_host_port_id = qla2x00_get_host_port_id,
  1125. .show_host_port_id = 1,
  1126. .get_host_speed = qla2x00_get_host_speed,
  1127. .show_host_speed = 1,
  1128. .get_host_port_type = qla2x00_get_host_port_type,
  1129. .show_host_port_type = 1,
  1130. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1131. .show_host_symbolic_name = 1,
  1132. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1133. .show_host_system_hostname = 1,
  1134. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1135. .show_host_fabric_name = 1,
  1136. .get_host_port_state = qla2x00_get_host_port_state,
  1137. .show_host_port_state = 1,
  1138. .dd_fcrport_size = sizeof(struct fc_port *),
  1139. .show_rport_supported_classes = 1,
  1140. .get_starget_node_name = qla2x00_get_starget_node_name,
  1141. .show_starget_node_name = 1,
  1142. .get_starget_port_name = qla2x00_get_starget_port_name,
  1143. .show_starget_port_name = 1,
  1144. .get_starget_port_id = qla2x00_get_starget_port_id,
  1145. .show_starget_port_id = 1,
  1146. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1147. .show_rport_dev_loss_tmo = 1,
  1148. .issue_fc_host_lip = qla2x00_issue_lip,
  1149. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1150. .terminate_rport_io = qla2x00_terminate_rport_io,
  1151. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1152. .vport_create = qla24xx_vport_create,
  1153. .vport_disable = qla24xx_vport_disable,
  1154. .vport_delete = qla24xx_vport_delete,
  1155. };
  1156. struct fc_function_template qla2xxx_transport_vport_functions = {
  1157. .show_host_node_name = 1,
  1158. .show_host_port_name = 1,
  1159. .show_host_supported_classes = 1,
  1160. .get_host_port_id = qla2x00_get_host_port_id,
  1161. .show_host_port_id = 1,
  1162. .get_host_speed = qla2x00_get_host_speed,
  1163. .show_host_speed = 1,
  1164. .get_host_port_type = qla2x00_get_host_port_type,
  1165. .show_host_port_type = 1,
  1166. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1167. .show_host_symbolic_name = 1,
  1168. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1169. .show_host_system_hostname = 1,
  1170. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1171. .show_host_fabric_name = 1,
  1172. .get_host_port_state = qla2x00_get_host_port_state,
  1173. .show_host_port_state = 1,
  1174. .dd_fcrport_size = sizeof(struct fc_port *),
  1175. .show_rport_supported_classes = 1,
  1176. .get_starget_node_name = qla2x00_get_starget_node_name,
  1177. .show_starget_node_name = 1,
  1178. .get_starget_port_name = qla2x00_get_starget_port_name,
  1179. .show_starget_port_name = 1,
  1180. .get_starget_port_id = qla2x00_get_starget_port_id,
  1181. .show_starget_port_id = 1,
  1182. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1183. .show_rport_dev_loss_tmo = 1,
  1184. .issue_fc_host_lip = qla2x00_issue_lip,
  1185. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1186. .terminate_rport_io = qla2x00_terminate_rport_io,
  1187. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1188. };
  1189. void
  1190. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  1191. {
  1192. struct qla_hw_data *ha = vha->hw;
  1193. u32 speed = FC_PORTSPEED_UNKNOWN;
  1194. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1195. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1196. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  1197. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  1198. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  1199. if (IS_QLA81XX(ha))
  1200. speed = FC_PORTSPEED_10GBIT;
  1201. else if (IS_QLA25XX(ha))
  1202. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1203. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1204. else if (IS_QLA24XX_TYPE(ha))
  1205. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1206. FC_PORTSPEED_1GBIT;
  1207. else if (IS_QLA23XX(ha))
  1208. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1209. else
  1210. speed = FC_PORTSPEED_1GBIT;
  1211. fc_host_supported_speeds(vha->host) = speed;
  1212. }