qla_attr.c 34 KB

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