qla_attr.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349
  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. qla2xxx_get_vpd_field(ha, "SN", buf, PAGE_SIZE);
  473. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  474. }
  475. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  476. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  477. sn % 100000);
  478. }
  479. static ssize_t
  480. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  481. char *buf)
  482. {
  483. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  484. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  485. }
  486. static ssize_t
  487. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  488. char *buf)
  489. {
  490. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  491. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  492. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  493. ha->product_id[3]);
  494. }
  495. static ssize_t
  496. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  497. char *buf)
  498. {
  499. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  500. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  501. }
  502. static ssize_t
  503. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  504. char *buf)
  505. {
  506. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  507. return snprintf(buf, PAGE_SIZE, "%s\n",
  508. ha->model_desc ? ha->model_desc: "");
  509. }
  510. static ssize_t
  511. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  512. char *buf)
  513. {
  514. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  515. char pci_info[30];
  516. return snprintf(buf, PAGE_SIZE, "%s\n",
  517. ha->isp_ops->pci_info_str(ha, pci_info));
  518. }
  519. static ssize_t
  520. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  521. char *buf)
  522. {
  523. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  524. int len = 0;
  525. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  526. atomic_read(&ha->loop_state) == LOOP_DEAD)
  527. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  528. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  529. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  530. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  531. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  532. else {
  533. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  534. switch (ha->current_topology) {
  535. case ISP_CFG_NL:
  536. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  537. break;
  538. case ISP_CFG_FL:
  539. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  540. break;
  541. case ISP_CFG_N:
  542. len += snprintf(buf + len, PAGE_SIZE-len,
  543. "N_Port to N_Port\n");
  544. break;
  545. case ISP_CFG_F:
  546. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  547. break;
  548. default:
  549. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  550. break;
  551. }
  552. }
  553. return len;
  554. }
  555. static ssize_t
  556. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  557. char *buf)
  558. {
  559. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  560. int len = 0;
  561. switch (ha->zio_mode) {
  562. case QLA_ZIO_MODE_6:
  563. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  564. break;
  565. case QLA_ZIO_DISABLED:
  566. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  567. break;
  568. }
  569. return len;
  570. }
  571. static ssize_t
  572. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  573. const char *buf, size_t count)
  574. {
  575. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  576. int val = 0;
  577. uint16_t zio_mode;
  578. if (!IS_ZIO_SUPPORTED(ha))
  579. return -ENOTSUPP;
  580. if (sscanf(buf, "%d", &val) != 1)
  581. return -EINVAL;
  582. if (val)
  583. zio_mode = QLA_ZIO_MODE_6;
  584. else
  585. zio_mode = QLA_ZIO_DISABLED;
  586. /* Update per-hba values and queue a reset. */
  587. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  588. ha->zio_mode = zio_mode;
  589. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  590. }
  591. return strlen(buf);
  592. }
  593. static ssize_t
  594. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  595. char *buf)
  596. {
  597. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  598. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  599. }
  600. static ssize_t
  601. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  602. const char *buf, size_t count)
  603. {
  604. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  605. int val = 0;
  606. uint16_t zio_timer;
  607. if (sscanf(buf, "%d", &val) != 1)
  608. return -EINVAL;
  609. if (val > 25500 || val < 100)
  610. return -ERANGE;
  611. zio_timer = (uint16_t)(val / 100);
  612. ha->zio_timer = zio_timer;
  613. return strlen(buf);
  614. }
  615. static ssize_t
  616. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  617. char *buf)
  618. {
  619. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  620. int len = 0;
  621. if (ha->beacon_blink_led)
  622. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  623. else
  624. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  625. return len;
  626. }
  627. static ssize_t
  628. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  629. const char *buf, size_t count)
  630. {
  631. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  632. int val = 0;
  633. int rval;
  634. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  635. return -EPERM;
  636. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  637. qla_printk(KERN_WARNING, ha,
  638. "Abort ISP active -- ignoring beacon request.\n");
  639. return -EBUSY;
  640. }
  641. if (sscanf(buf, "%d", &val) != 1)
  642. return -EINVAL;
  643. if (val)
  644. rval = ha->isp_ops->beacon_on(ha);
  645. else
  646. rval = ha->isp_ops->beacon_off(ha);
  647. if (rval != QLA_SUCCESS)
  648. count = 0;
  649. return count;
  650. }
  651. static ssize_t
  652. qla2x00_optrom_bios_version_show(struct device *dev,
  653. struct device_attribute *attr, char *buf)
  654. {
  655. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  656. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  657. ha->bios_revision[0]);
  658. }
  659. static ssize_t
  660. qla2x00_optrom_efi_version_show(struct device *dev,
  661. struct device_attribute *attr, char *buf)
  662. {
  663. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  664. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  665. ha->efi_revision[0]);
  666. }
  667. static ssize_t
  668. qla2x00_optrom_fcode_version_show(struct device *dev,
  669. struct device_attribute *attr, char *buf)
  670. {
  671. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  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 *ha = shost_priv(class_to_shost(dev));
  680. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  681. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  682. ha->fw_revision[3]);
  683. }
  684. static ssize_t
  685. qla2x00_total_isp_aborts_show(struct device *dev,
  686. struct device_attribute *attr, char *buf)
  687. {
  688. scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
  689. return snprintf(buf, PAGE_SIZE, "%d\n",
  690. ha->qla_stats.total_isp_aborts);
  691. }
  692. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  693. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  694. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  695. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  696. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  697. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  698. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  699. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  700. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  701. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  702. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  703. qla2x00_zio_timer_store);
  704. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  705. qla2x00_beacon_store);
  706. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  707. qla2x00_optrom_bios_version_show, NULL);
  708. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  709. qla2x00_optrom_efi_version_show, NULL);
  710. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  711. qla2x00_optrom_fcode_version_show, NULL);
  712. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  713. NULL);
  714. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  715. NULL);
  716. struct device_attribute *qla2x00_host_attrs[] = {
  717. &dev_attr_driver_version,
  718. &dev_attr_fw_version,
  719. &dev_attr_serial_num,
  720. &dev_attr_isp_name,
  721. &dev_attr_isp_id,
  722. &dev_attr_model_name,
  723. &dev_attr_model_desc,
  724. &dev_attr_pci_info,
  725. &dev_attr_link_state,
  726. &dev_attr_zio,
  727. &dev_attr_zio_timer,
  728. &dev_attr_beacon,
  729. &dev_attr_optrom_bios_version,
  730. &dev_attr_optrom_efi_version,
  731. &dev_attr_optrom_fcode_version,
  732. &dev_attr_optrom_fw_version,
  733. &dev_attr_total_isp_aborts,
  734. NULL,
  735. };
  736. /* Host attributes. */
  737. static void
  738. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  739. {
  740. scsi_qla_host_t *ha = shost_priv(shost);
  741. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  742. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  743. }
  744. static void
  745. qla2x00_get_host_speed(struct Scsi_Host *shost)
  746. {
  747. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  748. u32 speed = FC_PORTSPEED_UNKNOWN;
  749. switch (ha->link_data_rate) {
  750. case PORT_SPEED_1GB:
  751. speed = FC_PORTSPEED_1GBIT;
  752. break;
  753. case PORT_SPEED_2GB:
  754. speed = FC_PORTSPEED_2GBIT;
  755. break;
  756. case PORT_SPEED_4GB:
  757. speed = FC_PORTSPEED_4GBIT;
  758. break;
  759. case PORT_SPEED_8GB:
  760. speed = FC_PORTSPEED_8GBIT;
  761. break;
  762. }
  763. fc_host_speed(shost) = speed;
  764. }
  765. static void
  766. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  767. {
  768. scsi_qla_host_t *ha = shost_priv(shost);
  769. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  770. if (ha->parent) {
  771. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  772. return;
  773. }
  774. switch (ha->current_topology) {
  775. case ISP_CFG_NL:
  776. port_type = FC_PORTTYPE_LPORT;
  777. break;
  778. case ISP_CFG_FL:
  779. port_type = FC_PORTTYPE_NLPORT;
  780. break;
  781. case ISP_CFG_N:
  782. port_type = FC_PORTTYPE_PTP;
  783. break;
  784. case ISP_CFG_F:
  785. port_type = FC_PORTTYPE_NPORT;
  786. break;
  787. }
  788. fc_host_port_type(shost) = port_type;
  789. }
  790. static void
  791. qla2x00_get_starget_node_name(struct scsi_target *starget)
  792. {
  793. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  794. scsi_qla_host_t *ha = shost_priv(host);
  795. fc_port_t *fcport;
  796. u64 node_name = 0;
  797. list_for_each_entry(fcport, &ha->fcports, list) {
  798. if (fcport->rport &&
  799. starget->id == fcport->rport->scsi_target_id) {
  800. node_name = wwn_to_u64(fcport->node_name);
  801. break;
  802. }
  803. }
  804. fc_starget_node_name(starget) = node_name;
  805. }
  806. static void
  807. qla2x00_get_starget_port_name(struct scsi_target *starget)
  808. {
  809. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  810. scsi_qla_host_t *ha = shost_priv(host);
  811. fc_port_t *fcport;
  812. u64 port_name = 0;
  813. list_for_each_entry(fcport, &ha->fcports, list) {
  814. if (fcport->rport &&
  815. starget->id == fcport->rport->scsi_target_id) {
  816. port_name = wwn_to_u64(fcport->port_name);
  817. break;
  818. }
  819. }
  820. fc_starget_port_name(starget) = port_name;
  821. }
  822. static void
  823. qla2x00_get_starget_port_id(struct scsi_target *starget)
  824. {
  825. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  826. scsi_qla_host_t *ha = shost_priv(host);
  827. fc_port_t *fcport;
  828. uint32_t port_id = ~0U;
  829. list_for_each_entry(fcport, &ha->fcports, list) {
  830. if (fcport->rport &&
  831. starget->id == fcport->rport->scsi_target_id) {
  832. port_id = fcport->d_id.b.domain << 16 |
  833. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  834. break;
  835. }
  836. }
  837. fc_starget_port_id(starget) = port_id;
  838. }
  839. static void
  840. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  841. {
  842. if (timeout)
  843. rport->dev_loss_tmo = timeout;
  844. else
  845. rport->dev_loss_tmo = 1;
  846. }
  847. static void
  848. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  849. {
  850. struct Scsi_Host *host = rport_to_shost(rport);
  851. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  852. qla2x00_abort_fcport_cmds(fcport);
  853. /*
  854. * Transport has effectively 'deleted' the rport, clear
  855. * all local references.
  856. */
  857. spin_lock_irq(host->host_lock);
  858. fcport->rport = NULL;
  859. *((fc_port_t **)rport->dd_data) = NULL;
  860. spin_unlock_irq(host->host_lock);
  861. }
  862. static void
  863. qla2x00_terminate_rport_io(struct fc_rport *rport)
  864. {
  865. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  866. qla2x00_abort_fcport_cmds(fcport);
  867. scsi_target_unblock(&rport->dev);
  868. }
  869. static int
  870. qla2x00_issue_lip(struct Scsi_Host *shost)
  871. {
  872. scsi_qla_host_t *ha = shost_priv(shost);
  873. qla2x00_loop_reset(ha);
  874. return 0;
  875. }
  876. static struct fc_host_statistics *
  877. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  878. {
  879. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  880. int rval;
  881. struct link_statistics *stats;
  882. dma_addr_t stats_dma;
  883. struct fc_host_statistics *pfc_host_stat;
  884. pfc_host_stat = &ha->fc_host_stat;
  885. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  886. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  887. if (stats == NULL) {
  888. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  889. __func__, ha->host_no));
  890. goto done;
  891. }
  892. memset(stats, 0, DMA_POOL_SIZE);
  893. rval = QLA_FUNCTION_FAILED;
  894. if (IS_FWI2_CAPABLE(ha)) {
  895. rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
  896. } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
  897. !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
  898. !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
  899. !ha->dpc_active) {
  900. /* Must be in a 'READY' state for statistics retrieval. */
  901. rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
  902. stats_dma);
  903. }
  904. if (rval != QLA_SUCCESS)
  905. goto done_free;
  906. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  907. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  908. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  909. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  910. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  911. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  912. if (IS_FWI2_CAPABLE(ha)) {
  913. pfc_host_stat->lip_count = stats->lip_cnt;
  914. pfc_host_stat->tx_frames = stats->tx_frames;
  915. pfc_host_stat->rx_frames = stats->rx_frames;
  916. pfc_host_stat->dumped_frames = stats->dumped_frames;
  917. pfc_host_stat->nos_count = stats->nos_rcvd;
  918. }
  919. done_free:
  920. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  921. done:
  922. return pfc_host_stat;
  923. }
  924. static void
  925. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  926. {
  927. scsi_qla_host_t *ha = shost_priv(shost);
  928. qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
  929. }
  930. static void
  931. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  932. {
  933. scsi_qla_host_t *ha = shost_priv(shost);
  934. set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
  935. }
  936. static void
  937. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  938. {
  939. scsi_qla_host_t *ha = shost_priv(shost);
  940. u64 node_name;
  941. if (ha->device_flags & SWITCH_FOUND)
  942. node_name = wwn_to_u64(ha->fabric_node_name);
  943. else
  944. node_name = wwn_to_u64(ha->node_name);
  945. fc_host_fabric_name(shost) = node_name;
  946. }
  947. static void
  948. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  949. {
  950. scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
  951. if (!ha->flags.online)
  952. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  953. else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
  954. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  955. else
  956. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  957. }
  958. static int
  959. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  960. {
  961. int ret = 0;
  962. scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
  963. scsi_qla_host_t *vha;
  964. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  965. if (ret) {
  966. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  967. "status %x\n", ret));
  968. return (ret);
  969. }
  970. vha = qla24xx_create_vhost(fc_vport);
  971. if (vha == NULL) {
  972. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  973. vha));
  974. return FC_VPORT_FAILED;
  975. }
  976. if (disable) {
  977. atomic_set(&vha->vp_state, VP_OFFLINE);
  978. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  979. } else
  980. atomic_set(&vha->vp_state, VP_FAILED);
  981. /* ready to create vport */
  982. qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
  983. /* initialized vport states */
  984. atomic_set(&vha->loop_state, LOOP_DOWN);
  985. vha->vp_err_state= VP_ERR_PORTDWN;
  986. vha->vp_prev_err_state= VP_ERR_UNKWN;
  987. /* Check if physical ha port is Up */
  988. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  989. atomic_read(&ha->loop_state) == LOOP_DEAD) {
  990. /* Don't retry or attempt login of this virtual port */
  991. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  992. vha->host_no));
  993. atomic_set(&vha->loop_state, LOOP_DEAD);
  994. if (!disable)
  995. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  996. }
  997. if (scsi_add_host(vha->host, &fc_vport->dev)) {
  998. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  999. vha->host_no, vha->vp_idx));
  1000. goto vport_create_failed_2;
  1001. }
  1002. /* initialize attributes */
  1003. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1004. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1005. fc_host_supported_classes(vha->host) =
  1006. fc_host_supported_classes(ha->host);
  1007. fc_host_supported_speeds(vha->host) =
  1008. fc_host_supported_speeds(ha->host);
  1009. qla24xx_vport_disable(fc_vport, disable);
  1010. return 0;
  1011. vport_create_failed_2:
  1012. qla24xx_disable_vp(vha);
  1013. qla24xx_deallocate_vp_id(vha);
  1014. kfree(vha->port_name);
  1015. kfree(vha->node_name);
  1016. scsi_host_put(vha->host);
  1017. return FC_VPORT_FAILED;
  1018. }
  1019. static int
  1020. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1021. {
  1022. scsi_qla_host_t *vha = fc_vport->dd_data;
  1023. qla24xx_disable_vp(vha);
  1024. qla24xx_deallocate_vp_id(vha);
  1025. kfree(vha->node_name);
  1026. kfree(vha->port_name);
  1027. if (vha->timer_active) {
  1028. qla2x00_vp_stop_timer(vha);
  1029. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1030. "has stopped\n",
  1031. vha->host_no, vha->vp_idx, vha));
  1032. }
  1033. fc_remove_host(vha->host);
  1034. scsi_remove_host(vha->host);
  1035. scsi_host_put(vha->host);
  1036. return 0;
  1037. }
  1038. static int
  1039. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1040. {
  1041. scsi_qla_host_t *vha = fc_vport->dd_data;
  1042. if (disable)
  1043. qla24xx_disable_vp(vha);
  1044. else
  1045. qla24xx_enable_vp(vha);
  1046. return 0;
  1047. }
  1048. struct fc_function_template qla2xxx_transport_functions = {
  1049. .show_host_node_name = 1,
  1050. .show_host_port_name = 1,
  1051. .show_host_supported_classes = 1,
  1052. .show_host_supported_speeds = 1,
  1053. .get_host_port_id = qla2x00_get_host_port_id,
  1054. .show_host_port_id = 1,
  1055. .get_host_speed = qla2x00_get_host_speed,
  1056. .show_host_speed = 1,
  1057. .get_host_port_type = qla2x00_get_host_port_type,
  1058. .show_host_port_type = 1,
  1059. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1060. .show_host_symbolic_name = 1,
  1061. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1062. .show_host_system_hostname = 1,
  1063. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1064. .show_host_fabric_name = 1,
  1065. .get_host_port_state = qla2x00_get_host_port_state,
  1066. .show_host_port_state = 1,
  1067. .dd_fcrport_size = sizeof(struct fc_port *),
  1068. .show_rport_supported_classes = 1,
  1069. .get_starget_node_name = qla2x00_get_starget_node_name,
  1070. .show_starget_node_name = 1,
  1071. .get_starget_port_name = qla2x00_get_starget_port_name,
  1072. .show_starget_port_name = 1,
  1073. .get_starget_port_id = qla2x00_get_starget_port_id,
  1074. .show_starget_port_id = 1,
  1075. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1076. .show_rport_dev_loss_tmo = 1,
  1077. .issue_fc_host_lip = qla2x00_issue_lip,
  1078. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1079. .terminate_rport_io = qla2x00_terminate_rport_io,
  1080. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1081. .vport_create = qla24xx_vport_create,
  1082. .vport_disable = qla24xx_vport_disable,
  1083. .vport_delete = qla24xx_vport_delete,
  1084. };
  1085. struct fc_function_template qla2xxx_transport_vport_functions = {
  1086. .show_host_node_name = 1,
  1087. .show_host_port_name = 1,
  1088. .show_host_supported_classes = 1,
  1089. .get_host_port_id = qla2x00_get_host_port_id,
  1090. .show_host_port_id = 1,
  1091. .get_host_speed = qla2x00_get_host_speed,
  1092. .show_host_speed = 1,
  1093. .get_host_port_type = qla2x00_get_host_port_type,
  1094. .show_host_port_type = 1,
  1095. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  1096. .show_host_symbolic_name = 1,
  1097. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  1098. .show_host_system_hostname = 1,
  1099. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  1100. .show_host_fabric_name = 1,
  1101. .get_host_port_state = qla2x00_get_host_port_state,
  1102. .show_host_port_state = 1,
  1103. .dd_fcrport_size = sizeof(struct fc_port *),
  1104. .show_rport_supported_classes = 1,
  1105. .get_starget_node_name = qla2x00_get_starget_node_name,
  1106. .show_starget_node_name = 1,
  1107. .get_starget_port_name = qla2x00_get_starget_port_name,
  1108. .show_starget_port_name = 1,
  1109. .get_starget_port_id = qla2x00_get_starget_port_id,
  1110. .show_starget_port_id = 1,
  1111. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  1112. .show_rport_dev_loss_tmo = 1,
  1113. .issue_fc_host_lip = qla2x00_issue_lip,
  1114. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  1115. .terminate_rport_io = qla2x00_terminate_rport_io,
  1116. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  1117. };
  1118. void
  1119. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  1120. {
  1121. u32 speed = FC_PORTSPEED_UNKNOWN;
  1122. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  1123. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  1124. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  1125. fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
  1126. fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
  1127. if (IS_QLA25XX(ha))
  1128. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  1129. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1130. else if (IS_QLA24XX_TYPE(ha))
  1131. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  1132. FC_PORTSPEED_1GBIT;
  1133. else if (IS_QLA23XX(ha))
  1134. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  1135. else
  1136. speed = FC_PORTSPEED_1GBIT;
  1137. fc_host_supported_speeds(ha->host) = speed;
  1138. }