qla_attr.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652
  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. static int qla84xx_reset(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  13. int qla84xx_reset_chip(scsi_qla_host_t *, uint16_t, uint16_t *);
  14. static int qla84xx_mgmt_cmd(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
  15. /* SYSFS attributes --------------------------------------------------------- */
  16. static ssize_t
  17. qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
  18. struct bin_attribute *bin_attr,
  19. char *buf, loff_t off, size_t count)
  20. {
  21. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  22. struct device, kobj)));
  23. struct qla_hw_data *ha = vha->hw;
  24. if (ha->fw_dump_reading == 0)
  25. return 0;
  26. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  27. ha->fw_dump_len);
  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 *vha = shost_priv(dev_to_shost(container_of(kobj,
  35. struct device, kobj)));
  36. struct qla_hw_data *ha = vha->hw;
  37. int reading;
  38. if (off != 0)
  39. return (0);
  40. reading = simple_strtol(buf, NULL, 10);
  41. switch (reading) {
  42. case 0:
  43. if (!ha->fw_dump_reading)
  44. break;
  45. qla_printk(KERN_INFO, ha,
  46. "Firmware dump cleared on (%ld).\n", vha->host_no);
  47. ha->fw_dump_reading = 0;
  48. ha->fw_dumped = 0;
  49. break;
  50. case 1:
  51. if (ha->fw_dumped && !ha->fw_dump_reading) {
  52. ha->fw_dump_reading = 1;
  53. qla_printk(KERN_INFO, ha,
  54. "Raw firmware dump ready for read on (%ld).\n",
  55. vha->host_no);
  56. }
  57. break;
  58. case 2:
  59. qla2x00_alloc_fw_dump(vha);
  60. break;
  61. case 3:
  62. qla2x00_system_error(vha);
  63. break;
  64. }
  65. return (count);
  66. }
  67. static struct bin_attribute sysfs_fw_dump_attr = {
  68. .attr = {
  69. .name = "fw_dump",
  70. .mode = S_IRUSR | S_IWUSR,
  71. },
  72. .size = 0,
  73. .read = qla2x00_sysfs_read_fw_dump,
  74. .write = qla2x00_sysfs_write_fw_dump,
  75. };
  76. static ssize_t
  77. qla2x00_sysfs_read_nvram(struct kobject *kobj,
  78. struct bin_attribute *bin_attr,
  79. char *buf, loff_t off, size_t count)
  80. {
  81. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  82. struct device, kobj)));
  83. struct qla_hw_data *ha = vha->hw;
  84. if (!capable(CAP_SYS_ADMIN))
  85. return 0;
  86. if (IS_NOCACHE_VPD_TYPE(ha))
  87. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  88. ha->nvram_size);
  89. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  90. ha->nvram_size);
  91. }
  92. static ssize_t
  93. qla2x00_sysfs_write_nvram(struct kobject *kobj,
  94. struct bin_attribute *bin_attr,
  95. char *buf, loff_t off, size_t count)
  96. {
  97. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  98. struct device, kobj)));
  99. struct qla_hw_data *ha = vha->hw;
  100. uint16_t cnt;
  101. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  102. !ha->isp_ops->write_nvram)
  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. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  125. qla_printk(KERN_WARNING, ha,
  126. "HBA not online, failing NVRAM update.\n");
  127. return -EAGAIN;
  128. }
  129. /* Write NVRAM. */
  130. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  131. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  132. count);
  133. /* NVRAM settings take effect immediately. */
  134. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  135. qla2xxx_wake_dpc(vha);
  136. qla2x00_wait_for_chip_reset(vha);
  137. return (count);
  138. }
  139. static struct bin_attribute sysfs_nvram_attr = {
  140. .attr = {
  141. .name = "nvram",
  142. .mode = S_IRUSR | S_IWUSR,
  143. },
  144. .size = 512,
  145. .read = qla2x00_sysfs_read_nvram,
  146. .write = qla2x00_sysfs_write_nvram,
  147. };
  148. static ssize_t
  149. qla2x00_sysfs_read_optrom(struct kobject *kobj,
  150. struct bin_attribute *bin_attr,
  151. char *buf, loff_t off, size_t count)
  152. {
  153. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  154. struct device, kobj)));
  155. struct qla_hw_data *ha = vha->hw;
  156. if (ha->optrom_state != QLA_SREADING)
  157. return 0;
  158. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  159. ha->optrom_region_size);
  160. }
  161. static ssize_t
  162. qla2x00_sysfs_write_optrom(struct kobject *kobj,
  163. struct bin_attribute *bin_attr,
  164. char *buf, loff_t off, size_t count)
  165. {
  166. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  167. struct device, kobj)));
  168. struct qla_hw_data *ha = vha->hw;
  169. if (ha->optrom_state != QLA_SWRITING)
  170. return -EINVAL;
  171. if (off > ha->optrom_region_size)
  172. return -ERANGE;
  173. if (off + count > ha->optrom_region_size)
  174. count = ha->optrom_region_size - off;
  175. memcpy(&ha->optrom_buffer[off], buf, count);
  176. return count;
  177. }
  178. static struct bin_attribute sysfs_optrom_attr = {
  179. .attr = {
  180. .name = "optrom",
  181. .mode = S_IRUSR | S_IWUSR,
  182. },
  183. .size = 0,
  184. .read = qla2x00_sysfs_read_optrom,
  185. .write = qla2x00_sysfs_write_optrom,
  186. };
  187. static ssize_t
  188. qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
  189. struct bin_attribute *bin_attr,
  190. char *buf, loff_t off, size_t count)
  191. {
  192. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  193. struct device, kobj)));
  194. struct qla_hw_data *ha = vha->hw;
  195. uint32_t start = 0;
  196. uint32_t size = ha->optrom_size;
  197. int val, valid;
  198. if (off)
  199. return 0;
  200. if (unlikely(pci_channel_offline(ha->pdev)))
  201. return 0;
  202. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  203. return -EINVAL;
  204. if (start > ha->optrom_size)
  205. return -EINVAL;
  206. switch (val) {
  207. case 0:
  208. if (ha->optrom_state != QLA_SREADING &&
  209. ha->optrom_state != QLA_SWRITING)
  210. break;
  211. ha->optrom_state = QLA_SWAITING;
  212. DEBUG2(qla_printk(KERN_INFO, ha,
  213. "Freeing flash region allocation -- 0x%x bytes.\n",
  214. ha->optrom_region_size));
  215. vfree(ha->optrom_buffer);
  216. ha->optrom_buffer = NULL;
  217. break;
  218. case 1:
  219. if (ha->optrom_state != QLA_SWAITING)
  220. break;
  221. ha->optrom_region_start = start;
  222. ha->optrom_region_size = start + size > ha->optrom_size ?
  223. ha->optrom_size - start : size;
  224. ha->optrom_state = QLA_SREADING;
  225. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  226. if (ha->optrom_buffer == NULL) {
  227. qla_printk(KERN_WARNING, ha,
  228. "Unable to allocate memory for optrom retrieval "
  229. "(%x).\n", ha->optrom_region_size);
  230. ha->optrom_state = QLA_SWAITING;
  231. return count;
  232. }
  233. DEBUG2(qla_printk(KERN_INFO, ha,
  234. "Reading flash region -- 0x%x/0x%x.\n",
  235. ha->optrom_region_start, ha->optrom_region_size));
  236. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  237. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  238. ha->optrom_region_start, ha->optrom_region_size);
  239. break;
  240. case 2:
  241. if (ha->optrom_state != QLA_SWAITING)
  242. break;
  243. /*
  244. * We need to be more restrictive on which FLASH regions are
  245. * allowed to be updated via user-space. Regions accessible
  246. * via this method include:
  247. *
  248. * ISP21xx/ISP22xx/ISP23xx type boards:
  249. *
  250. * 0x000000 -> 0x020000 -- Boot code.
  251. *
  252. * ISP2322/ISP24xx type boards:
  253. *
  254. * 0x000000 -> 0x07ffff -- Boot code.
  255. * 0x080000 -> 0x0fffff -- Firmware.
  256. *
  257. * ISP25xx type boards:
  258. *
  259. * 0x000000 -> 0x07ffff -- Boot code.
  260. * 0x080000 -> 0x0fffff -- Firmware.
  261. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  262. */
  263. valid = 0;
  264. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  265. valid = 1;
  266. else if (start == (ha->flt_region_boot * 4) ||
  267. start == (ha->flt_region_fw * 4))
  268. valid = 1;
  269. else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
  270. valid = 1;
  271. if (!valid) {
  272. qla_printk(KERN_WARNING, ha,
  273. "Invalid start region 0x%x/0x%x.\n", start, size);
  274. return -EINVAL;
  275. }
  276. ha->optrom_region_start = start;
  277. ha->optrom_region_size = start + size > ha->optrom_size ?
  278. ha->optrom_size - start : size;
  279. ha->optrom_state = QLA_SWRITING;
  280. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  281. if (ha->optrom_buffer == NULL) {
  282. qla_printk(KERN_WARNING, ha,
  283. "Unable to allocate memory for optrom update "
  284. "(%x).\n", ha->optrom_region_size);
  285. ha->optrom_state = QLA_SWAITING;
  286. return count;
  287. }
  288. DEBUG2(qla_printk(KERN_INFO, ha,
  289. "Staging flash region write -- 0x%x/0x%x.\n",
  290. ha->optrom_region_start, ha->optrom_region_size));
  291. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  292. break;
  293. case 3:
  294. if (ha->optrom_state != QLA_SWRITING)
  295. break;
  296. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  297. qla_printk(KERN_WARNING, ha,
  298. "HBA not online, failing flash update.\n");
  299. return -EAGAIN;
  300. }
  301. DEBUG2(qla_printk(KERN_INFO, ha,
  302. "Writing flash region -- 0x%x/0x%x.\n",
  303. ha->optrom_region_start, ha->optrom_region_size));
  304. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  305. ha->optrom_region_start, ha->optrom_region_size);
  306. break;
  307. default:
  308. count = -EINVAL;
  309. }
  310. return count;
  311. }
  312. static struct bin_attribute sysfs_optrom_ctl_attr = {
  313. .attr = {
  314. .name = "optrom_ctl",
  315. .mode = S_IWUSR,
  316. },
  317. .size = 0,
  318. .write = qla2x00_sysfs_write_optrom_ctl,
  319. };
  320. static ssize_t
  321. qla2x00_sysfs_read_vpd(struct kobject *kobj,
  322. struct bin_attribute *bin_attr,
  323. char *buf, loff_t off, size_t count)
  324. {
  325. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  326. struct device, kobj)));
  327. struct qla_hw_data *ha = vha->hw;
  328. if (unlikely(pci_channel_offline(ha->pdev)))
  329. return 0;
  330. if (!capable(CAP_SYS_ADMIN))
  331. return 0;
  332. if (IS_NOCACHE_VPD_TYPE(ha))
  333. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  334. ha->vpd_size);
  335. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  336. }
  337. static ssize_t
  338. qla2x00_sysfs_write_vpd(struct kobject *kobj,
  339. struct bin_attribute *bin_attr,
  340. char *buf, loff_t off, size_t count)
  341. {
  342. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  343. struct device, kobj)));
  344. struct qla_hw_data *ha = vha->hw;
  345. uint8_t *tmp_data;
  346. if (unlikely(pci_channel_offline(ha->pdev)))
  347. return 0;
  348. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  349. !ha->isp_ops->write_nvram)
  350. return 0;
  351. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  352. qla_printk(KERN_WARNING, ha,
  353. "HBA not online, failing VPD update.\n");
  354. return -EAGAIN;
  355. }
  356. /* Write NVRAM. */
  357. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  358. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  359. /* Update flash version information for 4Gb & above. */
  360. if (!IS_FWI2_CAPABLE(ha))
  361. goto done;
  362. tmp_data = vmalloc(256);
  363. if (!tmp_data) {
  364. qla_printk(KERN_WARNING, ha,
  365. "Unable to allocate memory for VPD information update.\n");
  366. goto done;
  367. }
  368. ha->isp_ops->get_flash_version(vha, tmp_data);
  369. vfree(tmp_data);
  370. done:
  371. return count;
  372. }
  373. static struct bin_attribute sysfs_vpd_attr = {
  374. .attr = {
  375. .name = "vpd",
  376. .mode = S_IRUSR | S_IWUSR,
  377. },
  378. .size = 0,
  379. .read = qla2x00_sysfs_read_vpd,
  380. .write = qla2x00_sysfs_write_vpd,
  381. };
  382. static ssize_t
  383. qla2x00_sysfs_read_sfp(struct kobject *kobj,
  384. struct bin_attribute *bin_attr,
  385. char *buf, loff_t off, size_t count)
  386. {
  387. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  388. struct device, kobj)));
  389. struct qla_hw_data *ha = vha->hw;
  390. uint16_t iter, addr, offset;
  391. int rval;
  392. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  393. return 0;
  394. if (ha->sfp_data)
  395. goto do_read;
  396. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  397. &ha->sfp_data_dma);
  398. if (!ha->sfp_data) {
  399. qla_printk(KERN_WARNING, ha,
  400. "Unable to allocate memory for SFP read-data.\n");
  401. return 0;
  402. }
  403. do_read:
  404. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  405. addr = 0xa0;
  406. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  407. iter++, offset += SFP_BLOCK_SIZE) {
  408. if (iter == 4) {
  409. /* Skip to next device address. */
  410. addr = 0xa2;
  411. offset = 0;
  412. }
  413. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
  414. SFP_BLOCK_SIZE);
  415. if (rval != QLA_SUCCESS) {
  416. qla_printk(KERN_WARNING, ha,
  417. "Unable to read SFP data (%x/%x/%x).\n", rval,
  418. addr, offset);
  419. count = 0;
  420. break;
  421. }
  422. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  423. buf += SFP_BLOCK_SIZE;
  424. }
  425. return count;
  426. }
  427. static struct bin_attribute sysfs_sfp_attr = {
  428. .attr = {
  429. .name = "sfp",
  430. .mode = S_IRUSR | S_IWUSR,
  431. },
  432. .size = SFP_DEV_SIZE * 2,
  433. .read = qla2x00_sysfs_read_sfp,
  434. };
  435. static ssize_t
  436. qla2x00_sysfs_write_reset(struct kobject *kobj,
  437. struct bin_attribute *bin_attr,
  438. char *buf, loff_t off, size_t count)
  439. {
  440. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  441. struct device, kobj)));
  442. struct qla_hw_data *ha = vha->hw;
  443. int type;
  444. if (off != 0)
  445. return 0;
  446. type = simple_strtol(buf, NULL, 10);
  447. switch (type) {
  448. case 0x2025c:
  449. qla_printk(KERN_INFO, ha,
  450. "Issuing ISP reset on (%ld).\n", vha->host_no);
  451. scsi_block_requests(vha->host);
  452. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  453. qla2xxx_wake_dpc(vha);
  454. qla2x00_wait_for_chip_reset(vha);
  455. scsi_unblock_requests(vha->host);
  456. break;
  457. case 0x2025d:
  458. if (!IS_QLA81XX(ha))
  459. break;
  460. qla_printk(KERN_INFO, ha,
  461. "Issuing MPI reset on (%ld).\n", vha->host_no);
  462. /* Make sure FC side is not in reset */
  463. qla2x00_wait_for_hba_online(vha);
  464. /* Issue MPI reset */
  465. scsi_block_requests(vha->host);
  466. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  467. qla_printk(KERN_WARNING, ha,
  468. "MPI reset failed on (%ld).\n", vha->host_no);
  469. scsi_unblock_requests(vha->host);
  470. break;
  471. }
  472. return count;
  473. }
  474. static struct bin_attribute sysfs_reset_attr = {
  475. .attr = {
  476. .name = "reset",
  477. .mode = S_IWUSR,
  478. },
  479. .size = 0,
  480. .write = qla2x00_sysfs_write_reset,
  481. };
  482. static ssize_t
  483. qla2x00_sysfs_write_edc(struct kobject *kobj,
  484. struct bin_attribute *bin_attr,
  485. char *buf, loff_t off, size_t count)
  486. {
  487. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  488. struct device, kobj)));
  489. struct qla_hw_data *ha = vha->hw;
  490. uint16_t dev, adr, opt, len;
  491. int rval;
  492. ha->edc_data_len = 0;
  493. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  494. return 0;
  495. if (!ha->edc_data) {
  496. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  497. &ha->edc_data_dma);
  498. if (!ha->edc_data) {
  499. DEBUG2(qla_printk(KERN_INFO, ha,
  500. "Unable to allocate memory for EDC write.\n"));
  501. return 0;
  502. }
  503. }
  504. dev = le16_to_cpup((void *)&buf[0]);
  505. adr = le16_to_cpup((void *)&buf[2]);
  506. opt = le16_to_cpup((void *)&buf[4]);
  507. len = le16_to_cpup((void *)&buf[6]);
  508. if (!(opt & BIT_0))
  509. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  510. return -EINVAL;
  511. memcpy(ha->edc_data, &buf[8], len);
  512. rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
  513. ha->edc_data, len, opt);
  514. if (rval != QLA_SUCCESS) {
  515. DEBUG2(qla_printk(KERN_INFO, ha,
  516. "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
  517. rval, dev, adr, opt, len, *buf));
  518. return 0;
  519. }
  520. return count;
  521. }
  522. static struct bin_attribute sysfs_edc_attr = {
  523. .attr = {
  524. .name = "edc",
  525. .mode = S_IWUSR,
  526. },
  527. .size = 0,
  528. .write = qla2x00_sysfs_write_edc,
  529. };
  530. static ssize_t
  531. qla2x00_sysfs_write_edc_status(struct kobject *kobj,
  532. struct bin_attribute *bin_attr,
  533. char *buf, loff_t off, size_t count)
  534. {
  535. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  536. struct device, kobj)));
  537. struct qla_hw_data *ha = vha->hw;
  538. uint16_t dev, adr, opt, len;
  539. int rval;
  540. ha->edc_data_len = 0;
  541. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  542. return 0;
  543. if (!ha->edc_data) {
  544. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  545. &ha->edc_data_dma);
  546. if (!ha->edc_data) {
  547. DEBUG2(qla_printk(KERN_INFO, ha,
  548. "Unable to allocate memory for EDC status.\n"));
  549. return 0;
  550. }
  551. }
  552. dev = le16_to_cpup((void *)&buf[0]);
  553. adr = le16_to_cpup((void *)&buf[2]);
  554. opt = le16_to_cpup((void *)&buf[4]);
  555. len = le16_to_cpup((void *)&buf[6]);
  556. if (!(opt & BIT_0))
  557. if (len == 0 || len > DMA_POOL_SIZE)
  558. return -EINVAL;
  559. memset(ha->edc_data, 0, len);
  560. rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
  561. ha->edc_data, len, opt);
  562. if (rval != QLA_SUCCESS) {
  563. DEBUG2(qla_printk(KERN_INFO, ha,
  564. "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
  565. rval, dev, adr, opt, len));
  566. return 0;
  567. }
  568. ha->edc_data_len = len;
  569. return count;
  570. }
  571. static ssize_t
  572. qla2x00_sysfs_read_edc_status(struct kobject *kobj,
  573. struct bin_attribute *bin_attr,
  574. char *buf, loff_t off, size_t count)
  575. {
  576. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  577. struct device, kobj)));
  578. struct qla_hw_data *ha = vha->hw;
  579. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  580. return 0;
  581. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  582. return -EINVAL;
  583. memcpy(buf, ha->edc_data, ha->edc_data_len);
  584. return ha->edc_data_len;
  585. }
  586. static struct bin_attribute sysfs_edc_status_attr = {
  587. .attr = {
  588. .name = "edc_status",
  589. .mode = S_IRUSR | S_IWUSR,
  590. },
  591. .size = 0,
  592. .write = qla2x00_sysfs_write_edc_status,
  593. .read = qla2x00_sysfs_read_edc_status,
  594. };
  595. static ssize_t
  596. qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
  597. struct bin_attribute *bin_attr,
  598. char *buf, loff_t off, size_t count)
  599. {
  600. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  601. struct device, kobj)));
  602. struct qla_hw_data *ha = vha->hw;
  603. int rval;
  604. uint16_t actual_size;
  605. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  606. return 0;
  607. if (ha->xgmac_data)
  608. goto do_read;
  609. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  610. &ha->xgmac_data_dma, GFP_KERNEL);
  611. if (!ha->xgmac_data) {
  612. qla_printk(KERN_WARNING, ha,
  613. "Unable to allocate memory for XGMAC read-data.\n");
  614. return 0;
  615. }
  616. do_read:
  617. actual_size = 0;
  618. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  619. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  620. XGMAC_DATA_SIZE, &actual_size);
  621. if (rval != QLA_SUCCESS) {
  622. qla_printk(KERN_WARNING, ha,
  623. "Unable to read XGMAC data (%x).\n", rval);
  624. count = 0;
  625. }
  626. count = actual_size > count ? count: actual_size;
  627. memcpy(buf, ha->xgmac_data, count);
  628. return count;
  629. }
  630. static struct bin_attribute sysfs_xgmac_stats_attr = {
  631. .attr = {
  632. .name = "xgmac_stats",
  633. .mode = S_IRUSR,
  634. },
  635. .size = 0,
  636. .read = qla2x00_sysfs_read_xgmac_stats,
  637. };
  638. static ssize_t
  639. qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj,
  640. struct bin_attribute *bin_attr,
  641. char *buf, loff_t off, size_t count)
  642. {
  643. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  644. struct device, kobj)));
  645. struct qla_hw_data *ha = vha->hw;
  646. int rval;
  647. uint16_t actual_size;
  648. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  649. return 0;
  650. if (ha->dcbx_tlv)
  651. goto do_read;
  652. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  653. &ha->dcbx_tlv_dma, GFP_KERNEL);
  654. if (!ha->dcbx_tlv) {
  655. qla_printk(KERN_WARNING, ha,
  656. "Unable to allocate memory for DCBX TLV read-data.\n");
  657. return 0;
  658. }
  659. do_read:
  660. actual_size = 0;
  661. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  662. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  663. DCBX_TLV_DATA_SIZE);
  664. if (rval != QLA_SUCCESS) {
  665. qla_printk(KERN_WARNING, ha,
  666. "Unable to read DCBX TLV data (%x).\n", rval);
  667. count = 0;
  668. }
  669. memcpy(buf, ha->dcbx_tlv, count);
  670. return count;
  671. }
  672. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  673. .attr = {
  674. .name = "dcbx_tlv",
  675. .mode = S_IRUSR,
  676. },
  677. .size = 0,
  678. .read = qla2x00_sysfs_read_dcbx_tlv,
  679. };
  680. static struct sysfs_entry {
  681. char *name;
  682. struct bin_attribute *attr;
  683. int is4GBp_only;
  684. } bin_file_entries[] = {
  685. { "fw_dump", &sysfs_fw_dump_attr, },
  686. { "nvram", &sysfs_nvram_attr, },
  687. { "optrom", &sysfs_optrom_attr, },
  688. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  689. { "vpd", &sysfs_vpd_attr, 1 },
  690. { "sfp", &sysfs_sfp_attr, 1 },
  691. { "reset", &sysfs_reset_attr, },
  692. { "edc", &sysfs_edc_attr, 2 },
  693. { "edc_status", &sysfs_edc_status_attr, 2 },
  694. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  695. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  696. { NULL },
  697. };
  698. void
  699. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  700. {
  701. struct Scsi_Host *host = vha->host;
  702. struct sysfs_entry *iter;
  703. int ret;
  704. for (iter = bin_file_entries; iter->name; iter++) {
  705. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  706. continue;
  707. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  708. continue;
  709. if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
  710. continue;
  711. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  712. iter->attr);
  713. if (ret)
  714. qla_printk(KERN_INFO, vha->hw,
  715. "Unable to create sysfs %s binary attribute "
  716. "(%d).\n", iter->name, ret);
  717. }
  718. }
  719. void
  720. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  721. {
  722. struct Scsi_Host *host = vha->host;
  723. struct sysfs_entry *iter;
  724. struct qla_hw_data *ha = vha->hw;
  725. for (iter = bin_file_entries; iter->name; iter++) {
  726. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  727. continue;
  728. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  729. continue;
  730. if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
  731. continue;
  732. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  733. iter->attr);
  734. }
  735. if (ha->beacon_blink_led == 1)
  736. ha->isp_ops->beacon_off(vha);
  737. }
  738. /* Scsi_Host attributes. */
  739. static ssize_t
  740. qla2x00_drvr_version_show(struct device *dev,
  741. struct device_attribute *attr, char *buf)
  742. {
  743. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  744. }
  745. static ssize_t
  746. qla2x00_fw_version_show(struct device *dev,
  747. struct device_attribute *attr, char *buf)
  748. {
  749. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  750. struct qla_hw_data *ha = vha->hw;
  751. char fw_str[128];
  752. return snprintf(buf, PAGE_SIZE, "%s\n",
  753. ha->isp_ops->fw_version_str(vha, fw_str));
  754. }
  755. static ssize_t
  756. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  757. char *buf)
  758. {
  759. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  760. struct qla_hw_data *ha = vha->hw;
  761. uint32_t sn;
  762. if (IS_FWI2_CAPABLE(ha)) {
  763. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  764. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  765. }
  766. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  767. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  768. sn % 100000);
  769. }
  770. static ssize_t
  771. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  772. char *buf)
  773. {
  774. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  775. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  776. }
  777. static ssize_t
  778. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  779. char *buf)
  780. {
  781. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  782. struct qla_hw_data *ha = vha->hw;
  783. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  784. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  785. ha->product_id[3]);
  786. }
  787. static ssize_t
  788. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  789. char *buf)
  790. {
  791. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  792. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  793. }
  794. static ssize_t
  795. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  796. char *buf)
  797. {
  798. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  799. return snprintf(buf, PAGE_SIZE, "%s\n",
  800. vha->hw->model_desc ? vha->hw->model_desc : "");
  801. }
  802. static ssize_t
  803. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  804. char *buf)
  805. {
  806. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  807. char pci_info[30];
  808. return snprintf(buf, PAGE_SIZE, "%s\n",
  809. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  810. }
  811. static ssize_t
  812. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  813. char *buf)
  814. {
  815. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  816. struct qla_hw_data *ha = vha->hw;
  817. int len = 0;
  818. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  819. atomic_read(&vha->loop_state) == LOOP_DEAD)
  820. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  821. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  822. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  823. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  824. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  825. else {
  826. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  827. switch (ha->current_topology) {
  828. case ISP_CFG_NL:
  829. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  830. break;
  831. case ISP_CFG_FL:
  832. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  833. break;
  834. case ISP_CFG_N:
  835. len += snprintf(buf + len, PAGE_SIZE-len,
  836. "N_Port to N_Port\n");
  837. break;
  838. case ISP_CFG_F:
  839. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  840. break;
  841. default:
  842. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  843. break;
  844. }
  845. }
  846. return len;
  847. }
  848. static ssize_t
  849. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  850. char *buf)
  851. {
  852. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  853. int len = 0;
  854. switch (vha->hw->zio_mode) {
  855. case QLA_ZIO_MODE_6:
  856. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  857. break;
  858. case QLA_ZIO_DISABLED:
  859. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  860. break;
  861. }
  862. return len;
  863. }
  864. static ssize_t
  865. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  866. const char *buf, size_t count)
  867. {
  868. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  869. struct qla_hw_data *ha = vha->hw;
  870. int val = 0;
  871. uint16_t zio_mode;
  872. if (!IS_ZIO_SUPPORTED(ha))
  873. return -ENOTSUPP;
  874. if (sscanf(buf, "%d", &val) != 1)
  875. return -EINVAL;
  876. if (val)
  877. zio_mode = QLA_ZIO_MODE_6;
  878. else
  879. zio_mode = QLA_ZIO_DISABLED;
  880. /* Update per-hba values and queue a reset. */
  881. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  882. ha->zio_mode = zio_mode;
  883. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  884. }
  885. return strlen(buf);
  886. }
  887. static ssize_t
  888. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  889. char *buf)
  890. {
  891. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  892. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  893. }
  894. static ssize_t
  895. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  896. const char *buf, size_t count)
  897. {
  898. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  899. int val = 0;
  900. uint16_t zio_timer;
  901. if (sscanf(buf, "%d", &val) != 1)
  902. return -EINVAL;
  903. if (val > 25500 || val < 100)
  904. return -ERANGE;
  905. zio_timer = (uint16_t)(val / 100);
  906. vha->hw->zio_timer = zio_timer;
  907. return strlen(buf);
  908. }
  909. static ssize_t
  910. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  911. char *buf)
  912. {
  913. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  914. int len = 0;
  915. if (vha->hw->beacon_blink_led)
  916. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  917. else
  918. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  919. return len;
  920. }
  921. static ssize_t
  922. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  923. const char *buf, size_t count)
  924. {
  925. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  926. struct qla_hw_data *ha = vha->hw;
  927. int val = 0;
  928. int rval;
  929. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  930. return -EPERM;
  931. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  932. qla_printk(KERN_WARNING, ha,
  933. "Abort ISP active -- ignoring beacon request.\n");
  934. return -EBUSY;
  935. }
  936. if (sscanf(buf, "%d", &val) != 1)
  937. return -EINVAL;
  938. if (val)
  939. rval = ha->isp_ops->beacon_on(vha);
  940. else
  941. rval = ha->isp_ops->beacon_off(vha);
  942. if (rval != QLA_SUCCESS)
  943. count = 0;
  944. return count;
  945. }
  946. static ssize_t
  947. qla2x00_optrom_bios_version_show(struct device *dev,
  948. struct device_attribute *attr, char *buf)
  949. {
  950. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  951. struct qla_hw_data *ha = vha->hw;
  952. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  953. ha->bios_revision[0]);
  954. }
  955. static ssize_t
  956. qla2x00_optrom_efi_version_show(struct device *dev,
  957. struct device_attribute *attr, char *buf)
  958. {
  959. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  960. struct qla_hw_data *ha = vha->hw;
  961. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  962. ha->efi_revision[0]);
  963. }
  964. static ssize_t
  965. qla2x00_optrom_fcode_version_show(struct device *dev,
  966. struct device_attribute *attr, char *buf)
  967. {
  968. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  969. struct qla_hw_data *ha = vha->hw;
  970. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  971. ha->fcode_revision[0]);
  972. }
  973. static ssize_t
  974. qla2x00_optrom_fw_version_show(struct device *dev,
  975. struct device_attribute *attr, char *buf)
  976. {
  977. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  978. struct qla_hw_data *ha = vha->hw;
  979. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  980. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  981. ha->fw_revision[3]);
  982. }
  983. static ssize_t
  984. qla2x00_total_isp_aborts_show(struct device *dev,
  985. struct device_attribute *attr, char *buf)
  986. {
  987. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  988. struct qla_hw_data *ha = vha->hw;
  989. return snprintf(buf, PAGE_SIZE, "%d\n",
  990. ha->qla_stats.total_isp_aborts);
  991. }
  992. static ssize_t
  993. qla24xx_84xx_fw_version_show(struct device *dev,
  994. struct device_attribute *attr, char *buf)
  995. {
  996. int rval = QLA_SUCCESS;
  997. uint16_t status[2] = {0, 0};
  998. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  999. struct qla_hw_data *ha = vha->hw;
  1000. if (IS_QLA84XX(ha) && ha->cs84xx) {
  1001. if (ha->cs84xx->op_fw_version == 0) {
  1002. rval = qla84xx_verify_chip(vha, status);
  1003. }
  1004. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1005. return snprintf(buf, PAGE_SIZE, "%u\n",
  1006. (uint32_t)ha->cs84xx->op_fw_version);
  1007. }
  1008. return snprintf(buf, PAGE_SIZE, "\n");
  1009. }
  1010. static ssize_t
  1011. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1012. char *buf)
  1013. {
  1014. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1015. struct qla_hw_data *ha = vha->hw;
  1016. if (!IS_QLA81XX(ha))
  1017. return snprintf(buf, PAGE_SIZE, "\n");
  1018. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1019. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1020. ha->mpi_capabilities);
  1021. }
  1022. static ssize_t
  1023. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1024. char *buf)
  1025. {
  1026. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1027. struct qla_hw_data *ha = vha->hw;
  1028. if (!IS_QLA81XX(ha))
  1029. return snprintf(buf, PAGE_SIZE, "\n");
  1030. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1031. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1032. }
  1033. static ssize_t
  1034. qla2x00_flash_block_size_show(struct device *dev,
  1035. struct device_attribute *attr, char *buf)
  1036. {
  1037. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1038. struct qla_hw_data *ha = vha->hw;
  1039. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1040. }
  1041. static ssize_t
  1042. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1043. char *buf)
  1044. {
  1045. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1046. if (!IS_QLA81XX(vha->hw))
  1047. return snprintf(buf, PAGE_SIZE, "\n");
  1048. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1049. }
  1050. static ssize_t
  1051. qla2x00_vn_port_mac_address_show(struct device *dev,
  1052. struct device_attribute *attr, char *buf)
  1053. {
  1054. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1055. if (!IS_QLA81XX(vha->hw))
  1056. return snprintf(buf, PAGE_SIZE, "\n");
  1057. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1058. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1059. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1060. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1061. }
  1062. static ssize_t
  1063. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1064. char *buf)
  1065. {
  1066. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1067. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1068. }
  1069. static ssize_t
  1070. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1071. char *buf)
  1072. {
  1073. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1074. int rval = QLA_FUNCTION_FAILED;
  1075. uint16_t state[5];
  1076. if (!vha->hw->flags.eeh_busy)
  1077. rval = qla2x00_get_firmware_state(vha, state);
  1078. if (rval != QLA_SUCCESS)
  1079. memset(state, -1, sizeof(state));
  1080. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1081. state[1], state[2], state[3], state[4]);
  1082. }
  1083. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1084. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1085. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1086. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1087. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1088. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1089. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1090. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1091. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1092. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1093. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1094. qla2x00_zio_timer_store);
  1095. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1096. qla2x00_beacon_store);
  1097. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1098. qla2x00_optrom_bios_version_show, NULL);
  1099. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1100. qla2x00_optrom_efi_version_show, NULL);
  1101. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1102. qla2x00_optrom_fcode_version_show, NULL);
  1103. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1104. NULL);
  1105. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1106. NULL);
  1107. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1108. NULL);
  1109. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1110. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1111. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1112. NULL);
  1113. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1114. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1115. qla2x00_vn_port_mac_address_show, NULL);
  1116. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1117. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1118. struct device_attribute *qla2x00_host_attrs[] = {
  1119. &dev_attr_driver_version,
  1120. &dev_attr_fw_version,
  1121. &dev_attr_serial_num,
  1122. &dev_attr_isp_name,
  1123. &dev_attr_isp_id,
  1124. &dev_attr_model_name,
  1125. &dev_attr_model_desc,
  1126. &dev_attr_pci_info,
  1127. &dev_attr_link_state,
  1128. &dev_attr_zio,
  1129. &dev_attr_zio_timer,
  1130. &dev_attr_beacon,
  1131. &dev_attr_optrom_bios_version,
  1132. &dev_attr_optrom_efi_version,
  1133. &dev_attr_optrom_fcode_version,
  1134. &dev_attr_optrom_fw_version,
  1135. &dev_attr_84xx_fw_version,
  1136. &dev_attr_total_isp_aborts,
  1137. &dev_attr_mpi_version,
  1138. &dev_attr_phy_version,
  1139. &dev_attr_flash_block_size,
  1140. &dev_attr_vlan_id,
  1141. &dev_attr_vn_port_mac_address,
  1142. &dev_attr_fabric_param,
  1143. &dev_attr_fw_state,
  1144. NULL,
  1145. };
  1146. /* Host attributes. */
  1147. static void
  1148. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1149. {
  1150. scsi_qla_host_t *vha = shost_priv(shost);
  1151. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1152. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1153. }
  1154. static void
  1155. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1156. {
  1157. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1158. (shost_priv(shost)))->hw;
  1159. u32 speed = FC_PORTSPEED_UNKNOWN;
  1160. switch (ha->link_data_rate) {
  1161. case PORT_SPEED_1GB:
  1162. speed = FC_PORTSPEED_1GBIT;
  1163. break;
  1164. case PORT_SPEED_2GB:
  1165. speed = FC_PORTSPEED_2GBIT;
  1166. break;
  1167. case PORT_SPEED_4GB:
  1168. speed = FC_PORTSPEED_4GBIT;
  1169. break;
  1170. case PORT_SPEED_8GB:
  1171. speed = FC_PORTSPEED_8GBIT;
  1172. break;
  1173. case PORT_SPEED_10GB:
  1174. speed = FC_PORTSPEED_10GBIT;
  1175. break;
  1176. }
  1177. fc_host_speed(shost) = speed;
  1178. }
  1179. static void
  1180. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1181. {
  1182. scsi_qla_host_t *vha = shost_priv(shost);
  1183. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1184. if (vha->vp_idx) {
  1185. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1186. return;
  1187. }
  1188. switch (vha->hw->current_topology) {
  1189. case ISP_CFG_NL:
  1190. port_type = FC_PORTTYPE_LPORT;
  1191. break;
  1192. case ISP_CFG_FL:
  1193. port_type = FC_PORTTYPE_NLPORT;
  1194. break;
  1195. case ISP_CFG_N:
  1196. port_type = FC_PORTTYPE_PTP;
  1197. break;
  1198. case ISP_CFG_F:
  1199. port_type = FC_PORTTYPE_NPORT;
  1200. break;
  1201. }
  1202. fc_host_port_type(shost) = port_type;
  1203. }
  1204. static void
  1205. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1206. {
  1207. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1208. scsi_qla_host_t *vha = shost_priv(host);
  1209. fc_port_t *fcport;
  1210. u64 node_name = 0;
  1211. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1212. if (fcport->rport &&
  1213. starget->id == fcport->rport->scsi_target_id) {
  1214. node_name = wwn_to_u64(fcport->node_name);
  1215. break;
  1216. }
  1217. }
  1218. fc_starget_node_name(starget) = node_name;
  1219. }
  1220. static void
  1221. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1222. {
  1223. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1224. scsi_qla_host_t *vha = shost_priv(host);
  1225. fc_port_t *fcport;
  1226. u64 port_name = 0;
  1227. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1228. if (fcport->rport &&
  1229. starget->id == fcport->rport->scsi_target_id) {
  1230. port_name = wwn_to_u64(fcport->port_name);
  1231. break;
  1232. }
  1233. }
  1234. fc_starget_port_name(starget) = port_name;
  1235. }
  1236. static void
  1237. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1238. {
  1239. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1240. scsi_qla_host_t *vha = shost_priv(host);
  1241. fc_port_t *fcport;
  1242. uint32_t port_id = ~0U;
  1243. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1244. if (fcport->rport &&
  1245. starget->id == fcport->rport->scsi_target_id) {
  1246. port_id = fcport->d_id.b.domain << 16 |
  1247. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1248. break;
  1249. }
  1250. }
  1251. fc_starget_port_id(starget) = port_id;
  1252. }
  1253. static void
  1254. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1255. {
  1256. if (timeout)
  1257. rport->dev_loss_tmo = timeout;
  1258. else
  1259. rport->dev_loss_tmo = 1;
  1260. }
  1261. static void
  1262. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1263. {
  1264. struct Scsi_Host *host = rport_to_shost(rport);
  1265. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1266. if (!fcport)
  1267. return;
  1268. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1269. return;
  1270. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1271. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1272. return;
  1273. }
  1274. /*
  1275. * Transport has effectively 'deleted' the rport, clear
  1276. * all local references.
  1277. */
  1278. spin_lock_irq(host->host_lock);
  1279. fcport->rport = NULL;
  1280. *((fc_port_t **)rport->dd_data) = NULL;
  1281. spin_unlock_irq(host->host_lock);
  1282. }
  1283. static void
  1284. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1285. {
  1286. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1287. if (!fcport)
  1288. return;
  1289. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1290. return;
  1291. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1292. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1293. return;
  1294. }
  1295. /*
  1296. * At this point all fcport's software-states are cleared. Perform any
  1297. * final cleanup of firmware resources (PCBs and XCBs).
  1298. */
  1299. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1300. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1301. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1302. fcport->loop_id, fcport->d_id.b.domain,
  1303. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1304. qla2x00_abort_fcport_cmds(fcport);
  1305. }
  1306. static int
  1307. qla2x00_issue_lip(struct Scsi_Host *shost)
  1308. {
  1309. scsi_qla_host_t *vha = shost_priv(shost);
  1310. qla2x00_loop_reset(vha);
  1311. return 0;
  1312. }
  1313. static struct fc_host_statistics *
  1314. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1315. {
  1316. scsi_qla_host_t *vha = shost_priv(shost);
  1317. struct qla_hw_data *ha = vha->hw;
  1318. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1319. int rval;
  1320. struct link_statistics *stats;
  1321. dma_addr_t stats_dma;
  1322. struct fc_host_statistics *pfc_host_stat;
  1323. pfc_host_stat = &ha->fc_host_stat;
  1324. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1325. if (test_bit(UNLOADING, &vha->dpc_flags))
  1326. goto done;
  1327. if (unlikely(pci_channel_offline(ha->pdev)))
  1328. goto done;
  1329. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1330. if (stats == NULL) {
  1331. DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
  1332. __func__, base_vha->host_no));
  1333. goto done;
  1334. }
  1335. memset(stats, 0, DMA_POOL_SIZE);
  1336. rval = QLA_FUNCTION_FAILED;
  1337. if (IS_FWI2_CAPABLE(ha)) {
  1338. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1339. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1340. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1341. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1342. !ha->dpc_active) {
  1343. /* Must be in a 'READY' state for statistics retrieval. */
  1344. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1345. stats, stats_dma);
  1346. }
  1347. if (rval != QLA_SUCCESS)
  1348. goto done_free;
  1349. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1350. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1351. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1352. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1353. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1354. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1355. if (IS_FWI2_CAPABLE(ha)) {
  1356. pfc_host_stat->lip_count = stats->lip_cnt;
  1357. pfc_host_stat->tx_frames = stats->tx_frames;
  1358. pfc_host_stat->rx_frames = stats->rx_frames;
  1359. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1360. pfc_host_stat->nos_count = stats->nos_rcvd;
  1361. }
  1362. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1363. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1364. done_free:
  1365. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1366. done:
  1367. return pfc_host_stat;
  1368. }
  1369. static void
  1370. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1371. {
  1372. scsi_qla_host_t *vha = shost_priv(shost);
  1373. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1374. }
  1375. static void
  1376. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1377. {
  1378. scsi_qla_host_t *vha = shost_priv(shost);
  1379. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1380. }
  1381. static void
  1382. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1383. {
  1384. scsi_qla_host_t *vha = shost_priv(shost);
  1385. u64 node_name;
  1386. if (vha->device_flags & SWITCH_FOUND)
  1387. node_name = wwn_to_u64(vha->fabric_node_name);
  1388. else
  1389. node_name = wwn_to_u64(vha->node_name);
  1390. fc_host_fabric_name(shost) = node_name;
  1391. }
  1392. static void
  1393. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1394. {
  1395. scsi_qla_host_t *vha = shost_priv(shost);
  1396. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1397. if (!base_vha->flags.online)
  1398. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1399. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1400. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1401. else
  1402. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1403. }
  1404. static int
  1405. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1406. {
  1407. int ret = 0;
  1408. uint8_t qos = 0;
  1409. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1410. scsi_qla_host_t *vha = NULL;
  1411. struct qla_hw_data *ha = base_vha->hw;
  1412. uint16_t options = 0;
  1413. int cnt;
  1414. struct req_que *req = ha->req_q_map[0];
  1415. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1416. if (ret) {
  1417. DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
  1418. "status %x\n", ret));
  1419. return (ret);
  1420. }
  1421. vha = qla24xx_create_vhost(fc_vport);
  1422. if (vha == NULL) {
  1423. DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
  1424. vha));
  1425. return FC_VPORT_FAILED;
  1426. }
  1427. if (disable) {
  1428. atomic_set(&vha->vp_state, VP_OFFLINE);
  1429. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1430. } else
  1431. atomic_set(&vha->vp_state, VP_FAILED);
  1432. /* ready to create vport */
  1433. qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
  1434. vha->vp_idx);
  1435. /* initialized vport states */
  1436. atomic_set(&vha->loop_state, LOOP_DOWN);
  1437. vha->vp_err_state= VP_ERR_PORTDWN;
  1438. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1439. /* Check if physical ha port is Up */
  1440. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1441. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1442. /* Don't retry or attempt login of this virtual port */
  1443. DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
  1444. base_vha->host_no));
  1445. atomic_set(&vha->loop_state, LOOP_DEAD);
  1446. if (!disable)
  1447. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1448. }
  1449. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1450. &ha->pdev->dev)) {
  1451. DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
  1452. vha->host_no, vha->vp_idx));
  1453. goto vport_create_failed_2;
  1454. }
  1455. /* initialize attributes */
  1456. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1457. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1458. fc_host_supported_classes(vha->host) =
  1459. fc_host_supported_classes(base_vha->host);
  1460. fc_host_supported_speeds(vha->host) =
  1461. fc_host_supported_speeds(base_vha->host);
  1462. qla24xx_vport_disable(fc_vport, disable);
  1463. if (ha->flags.cpu_affinity_enabled) {
  1464. req = ha->req_q_map[1];
  1465. goto vport_queue;
  1466. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1467. goto vport_queue;
  1468. /* Create a request queue in QoS mode for the vport */
  1469. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1470. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1471. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1472. 8) == 0) {
  1473. qos = ha->npiv_info[cnt].q_qos;
  1474. break;
  1475. }
  1476. }
  1477. if (qos) {
  1478. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1479. qos);
  1480. if (!ret)
  1481. qla_printk(KERN_WARNING, ha,
  1482. "Can't create request queue for vp_idx:%d\n",
  1483. vha->vp_idx);
  1484. else {
  1485. DEBUG2(qla_printk(KERN_INFO, ha,
  1486. "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
  1487. ret, qos, vha->vp_idx));
  1488. req = ha->req_q_map[ret];
  1489. }
  1490. }
  1491. vport_queue:
  1492. vha->req = req;
  1493. return 0;
  1494. vport_create_failed_2:
  1495. qla24xx_disable_vp(vha);
  1496. qla24xx_deallocate_vp_id(vha);
  1497. scsi_host_put(vha->host);
  1498. return FC_VPORT_FAILED;
  1499. }
  1500. static int
  1501. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1502. {
  1503. scsi_qla_host_t *vha = fc_vport->dd_data;
  1504. fc_port_t *fcport, *tfcport;
  1505. struct qla_hw_data *ha = vha->hw;
  1506. uint16_t id = vha->vp_idx;
  1507. while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
  1508. test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
  1509. msleep(1000);
  1510. qla24xx_disable_vp(vha);
  1511. fc_remove_host(vha->host);
  1512. scsi_remove_host(vha->host);
  1513. list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
  1514. list_del(&fcport->list);
  1515. kfree(fcport);
  1516. fcport = NULL;
  1517. }
  1518. qla24xx_deallocate_vp_id(vha);
  1519. mutex_lock(&ha->vport_lock);
  1520. ha->cur_vport_count--;
  1521. clear_bit(vha->vp_idx, ha->vp_idx_map);
  1522. mutex_unlock(&ha->vport_lock);
  1523. if (vha->timer_active) {
  1524. qla2x00_vp_stop_timer(vha);
  1525. DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
  1526. "has stopped\n",
  1527. vha->host_no, vha->vp_idx, vha));
  1528. }
  1529. if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
  1530. if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
  1531. qla_printk(KERN_WARNING, ha,
  1532. "Queue delete failed.\n");
  1533. }
  1534. scsi_host_put(vha->host);
  1535. qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
  1536. return 0;
  1537. }
  1538. static int
  1539. qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
  1540. {
  1541. scsi_qla_host_t *vha = fc_vport->dd_data;
  1542. if (disable)
  1543. qla24xx_disable_vp(vha);
  1544. else
  1545. qla24xx_enable_vp(vha);
  1546. return 0;
  1547. }
  1548. /* BSG support for ELS/CT pass through */
  1549. inline srb_t *
  1550. qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
  1551. {
  1552. srb_t *sp;
  1553. struct qla_hw_data *ha = vha->hw;
  1554. struct srb_bsg_ctx *ctx;
  1555. sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
  1556. if (!sp)
  1557. goto done;
  1558. ctx = kzalloc(size, GFP_KERNEL);
  1559. if (!ctx) {
  1560. mempool_free(sp, ha->srb_mempool);
  1561. goto done;
  1562. }
  1563. memset(sp, 0, sizeof(*sp));
  1564. sp->fcport = fcport;
  1565. sp->ctx = ctx;
  1566. done:
  1567. return sp;
  1568. }
  1569. static int
  1570. qla2x00_process_els(struct fc_bsg_job *bsg_job)
  1571. {
  1572. struct fc_rport *rport;
  1573. fc_port_t *fcport;
  1574. struct Scsi_Host *host;
  1575. scsi_qla_host_t *vha;
  1576. struct qla_hw_data *ha;
  1577. srb_t *sp;
  1578. const char *type;
  1579. int req_sg_cnt, rsp_sg_cnt;
  1580. int rval = (DRIVER_ERROR << 16);
  1581. uint16_t nextlid = 0;
  1582. struct srb_bsg *els;
  1583. /* Multiple SG's are not supported for ELS requests */
  1584. if (bsg_job->request_payload.sg_cnt > 1 ||
  1585. bsg_job->reply_payload.sg_cnt > 1) {
  1586. DEBUG2(printk(KERN_INFO
  1587. "multiple SG's are not supported for ELS requests"
  1588. " [request_sg_cnt: %x reply_sg_cnt: %x]\n",
  1589. bsg_job->request_payload.sg_cnt,
  1590. bsg_job->reply_payload.sg_cnt));
  1591. rval = -EPERM;
  1592. goto done;
  1593. }
  1594. /* ELS request for rport */
  1595. if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
  1596. rport = bsg_job->rport;
  1597. fcport = *(fc_port_t **) rport->dd_data;
  1598. host = rport_to_shost(rport);
  1599. vha = shost_priv(host);
  1600. ha = vha->hw;
  1601. type = "FC_BSG_RPT_ELS";
  1602. DEBUG2(printk(KERN_INFO
  1603. "scsi(%ld): loop-id=%x portid=%02x%02x%02x.\n",
  1604. fcport->vha->host_no, fcport->loop_id,
  1605. fcport->d_id.b.domain, fcport->d_id.b.area,
  1606. fcport->d_id.b.al_pa));
  1607. /* make sure the rport is logged in,
  1608. * if not perform fabric login
  1609. */
  1610. if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
  1611. DEBUG2(qla_printk(KERN_WARNING, ha,
  1612. "failed to login port %06X for ELS passthru\n",
  1613. fcport->d_id.b24));
  1614. rval = -EIO;
  1615. goto done;
  1616. }
  1617. } else {
  1618. host = bsg_job->shost;
  1619. vha = shost_priv(host);
  1620. ha = vha->hw;
  1621. type = "FC_BSG_HST_ELS_NOLOGIN";
  1622. DEBUG2(printk(KERN_INFO
  1623. "scsi(%ld): loop-id=%x portid=%02x%02x%02x.\n",
  1624. vha->host_no, vha->loop_id,
  1625. vha->d_id.b.domain, vha->d_id.b.area, vha->d_id.b.al_pa));
  1626. /* Allocate a dummy fcport structure, since functions
  1627. * preparing the IOCB and mailbox command retrieves port
  1628. * specific information from fcport structure. For Host based
  1629. * ELS commands there will be no fcport structure allocated
  1630. */
  1631. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1632. if (!fcport) {
  1633. rval = -ENOMEM;
  1634. goto done;
  1635. }
  1636. /* Initialize all required fields of fcport */
  1637. fcport->vha = vha;
  1638. fcport->vp_idx = vha->vp_idx;
  1639. fcport->d_id.b.al_pa =
  1640. bsg_job->request->rqst_data.h_els.port_id[0];
  1641. fcport->d_id.b.area =
  1642. bsg_job->request->rqst_data.h_els.port_id[1];
  1643. fcport->d_id.b.domain =
  1644. bsg_job->request->rqst_data.h_els.port_id[2];
  1645. fcport->loop_id =
  1646. (fcport->d_id.b.al_pa == 0xFD) ?
  1647. NPH_FABRIC_CONTROLLER : NPH_F_PORT;
  1648. }
  1649. DEBUG2(printk(KERN_INFO
  1650. "scsi(%ld): vendor-id = %llu\n",
  1651. vha->host_no, host->hostt->vendor_id));
  1652. req_sg_cnt =
  1653. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1654. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1655. if (!req_sg_cnt) {
  1656. rval = -ENOMEM;
  1657. goto done_free_fcport;
  1658. }
  1659. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1660. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1661. if (!rsp_sg_cnt) {
  1662. rval = -ENOMEM;
  1663. goto done_free_fcport;
  1664. }
  1665. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1666. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1667. {
  1668. DEBUG2(printk(KERN_INFO
  1669. "dma mapping resulted in different sg counts \
  1670. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1671. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1672. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1673. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1674. rval = -EAGAIN;
  1675. goto done_unmap_sg;
  1676. }
  1677. /* Alloc SRB structure */
  1678. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1679. if (!sp) {
  1680. rval = -ENOMEM;
  1681. goto done_unmap_sg;
  1682. }
  1683. els = sp->ctx;
  1684. els->ctx.type =
  1685. (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
  1686. SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
  1687. els->bsg_job = bsg_job;
  1688. DEBUG2(qla_printk(KERN_INFO, ha,
  1689. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1690. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1691. bsg_job->request->rqst_data.h_els.command_code,
  1692. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1693. fcport->d_id.b.al_pa));
  1694. rval = qla2x00_start_sp(sp);
  1695. if (rval != QLA_SUCCESS) {
  1696. kfree(sp->ctx);
  1697. mempool_free(sp, ha->srb_mempool);
  1698. rval = -EIO;
  1699. goto done_unmap_sg;
  1700. }
  1701. return rval;
  1702. done_unmap_sg:
  1703. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1704. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1705. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1706. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1707. goto done_free_fcport;
  1708. done_free_fcport:
  1709. if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
  1710. kfree(fcport);
  1711. done:
  1712. return rval;
  1713. }
  1714. static int
  1715. qla2x00_process_ct(struct fc_bsg_job *bsg_job)
  1716. {
  1717. srb_t *sp;
  1718. struct Scsi_Host *host = bsg_job->shost;
  1719. scsi_qla_host_t *vha = shost_priv(host);
  1720. struct qla_hw_data *ha = vha->hw;
  1721. int rval = (DRIVER_ERROR << 16);
  1722. int req_sg_cnt, rsp_sg_cnt;
  1723. uint16_t loop_id;
  1724. struct fc_port *fcport;
  1725. char *type = "FC_BSG_HST_CT";
  1726. struct srb_bsg *ct;
  1727. /* pass through is supported only for ISP 4Gb or higher */
  1728. if (!IS_FWI2_CAPABLE(ha)) {
  1729. DEBUG2(qla_printk(KERN_INFO, ha,
  1730. "scsi(%ld):Firmware is not capable to support FC "
  1731. "CT pass thru\n", vha->host_no));
  1732. rval = -EPERM;
  1733. goto done;
  1734. }
  1735. req_sg_cnt =
  1736. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1737. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1738. if (!req_sg_cnt) {
  1739. rval = -ENOMEM;
  1740. goto done;
  1741. }
  1742. rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1743. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1744. if (!rsp_sg_cnt) {
  1745. rval = -ENOMEM;
  1746. goto done;
  1747. }
  1748. if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1749. (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1750. {
  1751. DEBUG2(qla_printk(KERN_WARNING, ha,
  1752. "dma mapping resulted in different sg counts \
  1753. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1754. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1755. bsg_job->request_payload.sg_cnt, req_sg_cnt,
  1756. bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
  1757. rval = -EAGAIN;
  1758. goto done_unmap_sg;
  1759. }
  1760. loop_id =
  1761. (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
  1762. >> 24;
  1763. switch (loop_id) {
  1764. case 0xFC:
  1765. loop_id = cpu_to_le16(NPH_SNS);
  1766. break;
  1767. case 0xFA:
  1768. loop_id = vha->mgmt_svr_loop_id;
  1769. break;
  1770. default:
  1771. DEBUG2(qla_printk(KERN_INFO, ha,
  1772. "Unknown loop id: %x\n", loop_id));
  1773. rval = -EINVAL;
  1774. goto done_unmap_sg;
  1775. }
  1776. /* Allocate a dummy fcport structure, since functions preparing the
  1777. * IOCB and mailbox command retrieves port specific information
  1778. * from fcport structure. For Host based ELS commands there will be
  1779. * no fcport structure allocated
  1780. */
  1781. fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
  1782. if (!fcport)
  1783. {
  1784. rval = -ENOMEM;
  1785. goto done_unmap_sg;
  1786. }
  1787. /* Initialize all required fields of fcport */
  1788. fcport->vha = vha;
  1789. fcport->vp_idx = vha->vp_idx;
  1790. fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
  1791. fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
  1792. fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
  1793. fcport->loop_id = loop_id;
  1794. /* Alloc SRB structure */
  1795. sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
  1796. if (!sp) {
  1797. rval = -ENOMEM;
  1798. goto done_free_fcport;
  1799. }
  1800. ct = sp->ctx;
  1801. ct->ctx.type = SRB_CT_CMD;
  1802. ct->bsg_job = bsg_job;
  1803. DEBUG2(qla_printk(KERN_INFO, ha,
  1804. "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
  1805. "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
  1806. (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
  1807. fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
  1808. fcport->d_id.b.al_pa));
  1809. rval = qla2x00_start_sp(sp);
  1810. if (rval != QLA_SUCCESS) {
  1811. kfree(sp->ctx);
  1812. mempool_free(sp, ha->srb_mempool);
  1813. rval = -EIO;
  1814. goto done_free_fcport;
  1815. }
  1816. return rval;
  1817. done_free_fcport:
  1818. kfree(fcport);
  1819. done_unmap_sg:
  1820. dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1821. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1822. dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1823. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1824. done:
  1825. return rval;
  1826. }
  1827. static int
  1828. qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
  1829. {
  1830. struct Scsi_Host *host = bsg_job->shost;
  1831. scsi_qla_host_t *vha = shost_priv(host);
  1832. struct qla_hw_data *ha = vha->hw;
  1833. int rval;
  1834. uint8_t command_sent;
  1835. uint32_t vendor_cmd;
  1836. char *type;
  1837. struct msg_echo_lb elreq;
  1838. uint16_t response[MAILBOX_REGISTER_COUNT];
  1839. uint8_t* fw_sts_ptr;
  1840. uint8_t *req_data;
  1841. dma_addr_t req_data_dma;
  1842. uint32_t req_data_len;
  1843. uint8_t *rsp_data;
  1844. dma_addr_t rsp_data_dma;
  1845. uint32_t rsp_data_len;
  1846. if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
  1847. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1848. test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
  1849. rval = -EBUSY;
  1850. goto done;
  1851. }
  1852. elreq.req_sg_cnt =
  1853. dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
  1854. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1855. if (!elreq.req_sg_cnt) {
  1856. rval = -ENOMEM;
  1857. goto done;
  1858. }
  1859. elreq.rsp_sg_cnt =
  1860. dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
  1861. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1862. if (!elreq.rsp_sg_cnt) {
  1863. rval = -ENOMEM;
  1864. goto done;
  1865. }
  1866. if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
  1867. (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
  1868. {
  1869. DEBUG2(printk(KERN_INFO
  1870. "dma mapping resulted in different sg counts \
  1871. [request_sg_cnt: %x dma_request_sg_cnt: %x\
  1872. reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
  1873. bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
  1874. bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
  1875. rval = -EAGAIN;
  1876. goto done_unmap_sg;
  1877. }
  1878. req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
  1879. req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
  1880. &req_data_dma, GFP_KERNEL);
  1881. rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
  1882. &rsp_data_dma, GFP_KERNEL);
  1883. /* Copy the request buffer in req_data now */
  1884. sg_copy_to_buffer(bsg_job->request_payload.sg_list,
  1885. bsg_job->request_payload.sg_cnt, req_data,
  1886. req_data_len);
  1887. elreq.send_dma = req_data_dma;
  1888. elreq.rcv_dma = rsp_data_dma;
  1889. elreq.transfer_size = req_data_len;
  1890. /* Vendor cmd : loopback or ECHO diagnostic
  1891. * Options:
  1892. * Loopback : Either internal or external loopback
  1893. * ECHO: ECHO ELS or Vendor specific FC4 link data
  1894. */
  1895. vendor_cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd[0];
  1896. elreq.options =
  1897. *(((uint32_t *)bsg_job->request->rqst_data.h_vendor.vendor_cmd)
  1898. + 1);
  1899. switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
  1900. case QL_VND_LOOPBACK:
  1901. if (ha->current_topology != ISP_CFG_F) {
  1902. type = "FC_BSG_HST_VENDOR_LOOPBACK";
  1903. if ((IS_QLA81XX(ha)) &&
  1904. ((elreq.options == 0) || (elreq.options == 2))) {
  1905. DEBUG2(qla_printk(KERN_INFO, ha, "scsi(%ld)"
  1906. "loopback option:0x%x not supported\n", vha->host_no, elreq.options));
  1907. rval = -EINVAL;
  1908. goto done_unmap_sg;
  1909. }
  1910. DEBUG2(qla_printk(KERN_INFO, ha,
  1911. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1912. vha->host_no, type, vendor_cmd, elreq.options));
  1913. DEBUG2(qla_printk(KERN_INFO, ha,
  1914. "scsi(%ld) tx_addr: 0x%llx rx_addr: 0x%llx tx_sg_cnt: %x rx_sg_cnt: %x\n",
  1915. vha->host_no, (unsigned long long)elreq.send_dma, (unsigned long long)elreq.rcv_dma, elreq.req_sg_cnt, elreq.rsp_sg_cnt));
  1916. command_sent = INT_DEF_LB_LOOPBACK_CMD;
  1917. rval = qla2x00_loopback_test(vha, &elreq, response);
  1918. if (IS_QLA81XX(ha)) {
  1919. if (response[0] == MBS_COMMAND_ERROR && response[1] == MBS_LB_RESET) {
  1920. DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
  1921. "ISP\n", __func__, vha->host_no));
  1922. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  1923. qla2xxx_wake_dpc(vha);
  1924. }
  1925. }
  1926. } else {
  1927. type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
  1928. DEBUG2(qla_printk(KERN_INFO, ha,
  1929. "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
  1930. vha->host_no, type, vendor_cmd, elreq.options));
  1931. DEBUG2(qla_printk(KERN_INFO, ha,
  1932. "scsi(%ld) tx_addr: 0x%llx rx_addr: 0x%llx tx_sg_cnt: %x rx_sg_cnt: %x\n",
  1933. vha->host_no, (unsigned long long)elreq.send_dma, (unsigned long long)elreq.rcv_dma, elreq.req_sg_cnt, elreq.rsp_sg_cnt));
  1934. command_sent = INT_DEF_LB_ECHO_CMD;
  1935. rval = qla2x00_echo_test(vha, &elreq, response);
  1936. }
  1937. break;
  1938. case QLA84_RESET:
  1939. if (!IS_QLA84XX(vha->hw)) {
  1940. rval = -EINVAL;
  1941. DEBUG16(printk(
  1942. "%s(%ld): 8xxx exiting.\n",
  1943. __func__, vha->host_no));
  1944. return rval;
  1945. }
  1946. rval = qla84xx_reset(vha, &elreq, bsg_job);
  1947. break;
  1948. case QLA84_MGMT_CMD:
  1949. if (!IS_QLA84XX(vha->hw)) {
  1950. rval = -EINVAL;
  1951. DEBUG16(printk(
  1952. "%s(%ld): 8xxx exiting.\n",
  1953. __func__, vha->host_no));
  1954. return rval;
  1955. }
  1956. rval = qla84xx_mgmt_cmd(vha, &elreq, bsg_job);
  1957. break;
  1958. default:
  1959. rval = -ENOSYS;
  1960. }
  1961. if (rval != QLA_SUCCESS) {
  1962. DEBUG2(qla_printk(KERN_WARNING, ha,
  1963. "scsi(%ld) Vendor request %s failed\n", vha->host_no, type));
  1964. rval = 0;
  1965. bsg_job->reply->result = (DID_ERROR << 16);
  1966. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1967. memcpy( fw_sts_ptr, response, sizeof(response));
  1968. fw_sts_ptr += sizeof(response);
  1969. *fw_sts_ptr = command_sent;
  1970. } else {
  1971. DEBUG2(qla_printk(KERN_WARNING, ha,
  1972. "scsi(%ld) Vendor request %s completed\n", vha->host_no, type));
  1973. rval = bsg_job->reply->result = 0;
  1974. bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(response) + sizeof(uint8_t);
  1975. bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
  1976. fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
  1977. memcpy(fw_sts_ptr, response, sizeof(response));
  1978. fw_sts_ptr += sizeof(response);
  1979. *fw_sts_ptr = command_sent;
  1980. sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
  1981. bsg_job->reply_payload.sg_cnt, rsp_data,
  1982. rsp_data_len);
  1983. }
  1984. bsg_job->job_done(bsg_job);
  1985. done_unmap_sg:
  1986. if(req_data)
  1987. dma_free_coherent(&ha->pdev->dev, req_data_len,
  1988. req_data, req_data_dma);
  1989. dma_unmap_sg(&ha->pdev->dev,
  1990. bsg_job->request_payload.sg_list,
  1991. bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
  1992. dma_unmap_sg(&ha->pdev->dev,
  1993. bsg_job->reply_payload.sg_list,
  1994. bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
  1995. done:
  1996. return rval;
  1997. }
  1998. static int
  1999. qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
  2000. {
  2001. int ret = -EINVAL;
  2002. switch (bsg_job->request->msgcode) {
  2003. case FC_BSG_RPT_ELS:
  2004. case FC_BSG_HST_ELS_NOLOGIN:
  2005. ret = qla2x00_process_els(bsg_job);
  2006. break;
  2007. case FC_BSG_HST_CT:
  2008. ret = qla2x00_process_ct(bsg_job);
  2009. break;
  2010. case FC_BSG_HST_VENDOR:
  2011. ret = qla2x00_process_vendor_specific(bsg_job);
  2012. break;
  2013. case FC_BSG_HST_ADD_RPORT:
  2014. case FC_BSG_HST_DEL_RPORT:
  2015. case FC_BSG_RPT_CT:
  2016. default:
  2017. DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
  2018. break;
  2019. }
  2020. return ret;
  2021. }
  2022. static int
  2023. qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
  2024. {
  2025. scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
  2026. struct qla_hw_data *ha = vha->hw;
  2027. srb_t *sp;
  2028. int i;
  2029. unsigned long flags;
  2030. uint16_t que_id;
  2031. struct req_que *req;
  2032. struct rsp_que *rsp;
  2033. int found = 0;
  2034. struct srb_bsg *sp_bsg;
  2035. /* find the bsg job from the active list of commands */
  2036. spin_lock_irqsave(&ha->hardware_lock, flags);
  2037. req = ha->req_q_map[0];
  2038. que_id = req->id;
  2039. if (req->rsp)
  2040. rsp = req->rsp;
  2041. else
  2042. rsp = ha->rsp_q_map[que_id];
  2043. for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++ ) {
  2044. sp = req->outstanding_cmds[i];
  2045. if (sp == NULL)
  2046. continue;
  2047. sp_bsg = (struct srb_bsg*)sp->ctx;
  2048. if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
  2049. (sp_bsg->ctx.type == SRB_ELS_CMD_RPT)
  2050. || ( sp_bsg->ctx.type == SRB_ELS_CMD_HST)) &&
  2051. (sp_bsg->bsg_job == bsg_job)) {
  2052. DEBUG2(qla_printk(KERN_INFO, ha,
  2053. "scsi(%ld) req_q: %p rsp_q: %p que_id: %x sp: %p\n",
  2054. vha->host_no, req, rsp, que_id, sp));
  2055. found = 1;
  2056. break;
  2057. }
  2058. }
  2059. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  2060. if (!found) {
  2061. DEBUG2(qla_printk(KERN_INFO, ha,
  2062. "scsi(%ld) SRB not found to abort\n", vha->host_no));
  2063. bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
  2064. return 0;
  2065. }
  2066. if (ha->isp_ops->abort_command(sp)) {
  2067. DEBUG2(qla_printk(KERN_INFO, ha,
  2068. "scsi(%ld): mbx abort_command failed\n", vha->host_no));
  2069. bsg_job->req->errors = bsg_job->reply->result = -EIO;
  2070. } else {
  2071. DEBUG2(qla_printk(KERN_INFO, ha,
  2072. "scsi(%ld): mbx abort_command success\n", vha->host_no));
  2073. bsg_job->req->errors = bsg_job->reply->result = 0;
  2074. }
  2075. if (bsg_job->request->msgcode == FC_BSG_HST_CT)
  2076. kfree(sp->fcport);
  2077. kfree(sp->ctx);
  2078. mempool_free(sp, ha->srb_mempool);
  2079. return 0;
  2080. }
  2081. struct fc_function_template qla2xxx_transport_functions = {
  2082. .show_host_node_name = 1,
  2083. .show_host_port_name = 1,
  2084. .show_host_supported_classes = 1,
  2085. .show_host_supported_speeds = 1,
  2086. .get_host_port_id = qla2x00_get_host_port_id,
  2087. .show_host_port_id = 1,
  2088. .get_host_speed = qla2x00_get_host_speed,
  2089. .show_host_speed = 1,
  2090. .get_host_port_type = qla2x00_get_host_port_type,
  2091. .show_host_port_type = 1,
  2092. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2093. .show_host_symbolic_name = 1,
  2094. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2095. .show_host_system_hostname = 1,
  2096. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2097. .show_host_fabric_name = 1,
  2098. .get_host_port_state = qla2x00_get_host_port_state,
  2099. .show_host_port_state = 1,
  2100. .dd_fcrport_size = sizeof(struct fc_port *),
  2101. .show_rport_supported_classes = 1,
  2102. .get_starget_node_name = qla2x00_get_starget_node_name,
  2103. .show_starget_node_name = 1,
  2104. .get_starget_port_name = qla2x00_get_starget_port_name,
  2105. .show_starget_port_name = 1,
  2106. .get_starget_port_id = qla2x00_get_starget_port_id,
  2107. .show_starget_port_id = 1,
  2108. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2109. .show_rport_dev_loss_tmo = 1,
  2110. .issue_fc_host_lip = qla2x00_issue_lip,
  2111. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2112. .terminate_rport_io = qla2x00_terminate_rport_io,
  2113. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2114. .vport_create = qla24xx_vport_create,
  2115. .vport_disable = qla24xx_vport_disable,
  2116. .vport_delete = qla24xx_vport_delete,
  2117. .bsg_request = qla24xx_bsg_request,
  2118. .bsg_timeout = qla24xx_bsg_timeout,
  2119. };
  2120. struct fc_function_template qla2xxx_transport_vport_functions = {
  2121. .show_host_node_name = 1,
  2122. .show_host_port_name = 1,
  2123. .show_host_supported_classes = 1,
  2124. .get_host_port_id = qla2x00_get_host_port_id,
  2125. .show_host_port_id = 1,
  2126. .get_host_speed = qla2x00_get_host_speed,
  2127. .show_host_speed = 1,
  2128. .get_host_port_type = qla2x00_get_host_port_type,
  2129. .show_host_port_type = 1,
  2130. .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
  2131. .show_host_symbolic_name = 1,
  2132. .set_host_system_hostname = qla2x00_set_host_system_hostname,
  2133. .show_host_system_hostname = 1,
  2134. .get_host_fabric_name = qla2x00_get_host_fabric_name,
  2135. .show_host_fabric_name = 1,
  2136. .get_host_port_state = qla2x00_get_host_port_state,
  2137. .show_host_port_state = 1,
  2138. .dd_fcrport_size = sizeof(struct fc_port *),
  2139. .show_rport_supported_classes = 1,
  2140. .get_starget_node_name = qla2x00_get_starget_node_name,
  2141. .show_starget_node_name = 1,
  2142. .get_starget_port_name = qla2x00_get_starget_port_name,
  2143. .show_starget_port_name = 1,
  2144. .get_starget_port_id = qla2x00_get_starget_port_id,
  2145. .show_starget_port_id = 1,
  2146. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  2147. .show_rport_dev_loss_tmo = 1,
  2148. .issue_fc_host_lip = qla2x00_issue_lip,
  2149. .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
  2150. .terminate_rport_io = qla2x00_terminate_rport_io,
  2151. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  2152. .bsg_request = qla24xx_bsg_request,
  2153. .bsg_timeout = qla24xx_bsg_timeout,
  2154. };
  2155. void
  2156. qla2x00_init_host_attr(scsi_qla_host_t *vha)
  2157. {
  2158. struct qla_hw_data *ha = vha->hw;
  2159. u32 speed = FC_PORTSPEED_UNKNOWN;
  2160. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  2161. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  2162. fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
  2163. fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
  2164. fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
  2165. if (IS_QLA81XX(ha))
  2166. speed = FC_PORTSPEED_10GBIT;
  2167. else if (IS_QLA25XX(ha))
  2168. speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
  2169. FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2170. else if (IS_QLA24XX_TYPE(ha))
  2171. speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
  2172. FC_PORTSPEED_1GBIT;
  2173. else if (IS_QLA23XX(ha))
  2174. speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
  2175. else
  2176. speed = FC_PORTSPEED_1GBIT;
  2177. fc_host_supported_speeds(vha->host) = speed;
  2178. }
  2179. static int
  2180. qla84xx_reset(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2181. {
  2182. int ret = 0;
  2183. int cmd;
  2184. uint16_t cmd_status;
  2185. DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
  2186. cmd = (*((bsg_job->request->rqst_data.h_vendor.vendor_cmd) + 2))
  2187. == A84_RESET_FLAG_ENABLE_DIAG_FW ?
  2188. A84_ISSUE_RESET_DIAG_FW : A84_ISSUE_RESET_OP_FW;
  2189. ret = qla84xx_reset_chip(ha, cmd == A84_ISSUE_RESET_DIAG_FW,
  2190. &cmd_status);
  2191. return ret;
  2192. }
  2193. static int
  2194. qla84xx_mgmt_cmd(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
  2195. {
  2196. struct access_chip_84xx *mn;
  2197. dma_addr_t mn_dma, mgmt_dma;
  2198. void *mgmt_b = NULL;
  2199. int ret = 0;
  2200. int rsp_hdr_len, len = 0;
  2201. struct qla84_msg_mgmt *ql84_mgmt;
  2202. ql84_mgmt = (struct qla84_msg_mgmt *) vmalloc(sizeof(struct qla84_msg_mgmt));
  2203. ql84_mgmt->cmd =
  2204. *((uint16_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 2));
  2205. ql84_mgmt->mgmtp.u.mem.start_addr =
  2206. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 3));
  2207. ql84_mgmt->len =
  2208. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 4));
  2209. ql84_mgmt->mgmtp.u.config.id =
  2210. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 5));
  2211. ql84_mgmt->mgmtp.u.config.param0 =
  2212. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 6));
  2213. ql84_mgmt->mgmtp.u.config.param1 =
  2214. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 7));
  2215. ql84_mgmt->mgmtp.u.info.type =
  2216. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 8));
  2217. ql84_mgmt->mgmtp.u.info.context =
  2218. *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 9));
  2219. rsp_hdr_len = bsg_job->request_payload.payload_len;
  2220. mn = dma_pool_alloc(ha->hw->s_dma_pool, GFP_KERNEL, &mn_dma);
  2221. if (mn == NULL) {
  2222. DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
  2223. "failed%lu\n", __func__, ha->host_no));
  2224. return -ENOMEM;
  2225. }
  2226. memset(mn, 0, sizeof (struct access_chip_84xx));
  2227. mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
  2228. mn->entry_count = 1;
  2229. switch (ql84_mgmt->cmd) {
  2230. case QLA84_MGMT_READ_MEM:
  2231. mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
  2232. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2233. break;
  2234. case QLA84_MGMT_WRITE_MEM:
  2235. mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
  2236. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
  2237. break;
  2238. case QLA84_MGMT_CHNG_CONFIG:
  2239. mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
  2240. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.id);
  2241. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param0);
  2242. mn->parameter3 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param1);
  2243. break;
  2244. case QLA84_MGMT_GET_INFO:
  2245. mn->options = cpu_to_le16(ACO_REQUEST_INFO);
  2246. mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.type);
  2247. mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.context);
  2248. break;
  2249. default:
  2250. ret = -EIO;
  2251. goto exit_mgmt0;
  2252. }
  2253. if ((len == ql84_mgmt->len) &&
  2254. ql84_mgmt->cmd != QLA84_MGMT_CHNG_CONFIG) {
  2255. mgmt_b = dma_alloc_coherent(&ha->hw->pdev->dev, len,
  2256. &mgmt_dma, GFP_KERNEL);
  2257. if (mgmt_b == NULL) {
  2258. DEBUG2(printk(KERN_ERR "%s: dma alloc mgmt_b "
  2259. "failed%lu\n", __func__, ha->host_no));
  2260. ret = -ENOMEM;
  2261. goto exit_mgmt0;
  2262. }
  2263. mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->len);
  2264. mn->dseg_count = cpu_to_le16(1);
  2265. mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
  2266. mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
  2267. mn->dseg_length = cpu_to_le32(len);
  2268. if (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM) {
  2269. memcpy(mgmt_b, ql84_mgmt->payload, len);
  2270. }
  2271. }
  2272. ret = qla2x00_issue_iocb(ha, mn, mn_dma, 0);
  2273. if ((ret != QLA_SUCCESS) || (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM)
  2274. || (ql84_mgmt->cmd == QLA84_MGMT_CHNG_CONFIG)) {
  2275. if (ret != QLA_SUCCESS)
  2276. DEBUG2(printk(KERN_ERR "%s(%lu): failed\n",
  2277. __func__, ha->host_no));
  2278. } else if ((ql84_mgmt->cmd == QLA84_MGMT_READ_MEM) ||
  2279. (ql84_mgmt->cmd == QLA84_MGMT_GET_INFO)) {
  2280. }
  2281. if (mgmt_b)
  2282. dma_free_coherent(&ha->hw->pdev->dev, len, mgmt_b, mgmt_dma);
  2283. exit_mgmt0:
  2284. dma_pool_free(ha->hw->s_dma_pool, mn, mn_dma);
  2285. return ret;
  2286. }