zfcp_fsf.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390
  1. /*
  2. * zfcp device driver
  3. *
  4. * Implementation of FSF commands.
  5. *
  6. * Copyright IBM Corp. 2002, 2013
  7. */
  8. #define KMSG_COMPONENT "zfcp"
  9. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  10. #include <linux/blktrace_api.h>
  11. #include <linux/slab.h>
  12. #include <scsi/fc/fc_els.h>
  13. #include "zfcp_ext.h"
  14. #include "zfcp_fc.h"
  15. #include "zfcp_dbf.h"
  16. #include "zfcp_qdio.h"
  17. #include "zfcp_reqlist.h"
  18. struct kmem_cache *zfcp_fsf_qtcb_cache;
  19. static void zfcp_fsf_request_timeout_handler(unsigned long data)
  20. {
  21. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  22. zfcp_qdio_siosl(adapter);
  23. zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
  24. "fsrth_1");
  25. }
  26. static void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req,
  27. unsigned long timeout)
  28. {
  29. fsf_req->timer.function = zfcp_fsf_request_timeout_handler;
  30. fsf_req->timer.data = (unsigned long) fsf_req->adapter;
  31. fsf_req->timer.expires = jiffies + timeout;
  32. add_timer(&fsf_req->timer);
  33. }
  34. static void zfcp_fsf_start_erp_timer(struct zfcp_fsf_req *fsf_req)
  35. {
  36. BUG_ON(!fsf_req->erp_action);
  37. fsf_req->timer.function = zfcp_erp_timeout_handler;
  38. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  39. fsf_req->timer.expires = jiffies + 30 * HZ;
  40. add_timer(&fsf_req->timer);
  41. }
  42. /* association between FSF command and FSF QTCB type */
  43. static u32 fsf_qtcb_type[] = {
  44. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  45. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  46. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  47. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  48. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  49. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  50. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  51. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  52. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  53. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  54. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  55. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  56. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  57. };
  58. static void zfcp_fsf_class_not_supp(struct zfcp_fsf_req *req)
  59. {
  60. dev_err(&req->adapter->ccw_device->dev, "FCP device not "
  61. "operational because of an unsupported FC class\n");
  62. zfcp_erp_adapter_shutdown(req->adapter, 0, "fscns_1");
  63. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  64. }
  65. /**
  66. * zfcp_fsf_req_free - free memory used by fsf request
  67. * @fsf_req: pointer to struct zfcp_fsf_req
  68. */
  69. void zfcp_fsf_req_free(struct zfcp_fsf_req *req)
  70. {
  71. if (likely(req->pool)) {
  72. if (likely(req->qtcb))
  73. mempool_free(req->qtcb, req->adapter->pool.qtcb_pool);
  74. mempool_free(req, req->pool);
  75. return;
  76. }
  77. if (likely(req->qtcb))
  78. kmem_cache_free(zfcp_fsf_qtcb_cache, req->qtcb);
  79. kfree(req);
  80. }
  81. static void zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *req)
  82. {
  83. unsigned long flags;
  84. struct fsf_status_read_buffer *sr_buf = req->data;
  85. struct zfcp_adapter *adapter = req->adapter;
  86. struct zfcp_port *port;
  87. int d_id = ntoh24(sr_buf->d_id);
  88. read_lock_irqsave(&adapter->port_list_lock, flags);
  89. list_for_each_entry(port, &adapter->port_list, list)
  90. if (port->d_id == d_id) {
  91. zfcp_erp_port_reopen(port, 0, "fssrpc1");
  92. break;
  93. }
  94. read_unlock_irqrestore(&adapter->port_list_lock, flags);
  95. }
  96. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *req,
  97. struct fsf_link_down_info *link_down)
  98. {
  99. struct zfcp_adapter *adapter = req->adapter;
  100. if (atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED)
  101. return;
  102. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  103. zfcp_scsi_schedule_rports_block(adapter);
  104. if (!link_down)
  105. goto out;
  106. switch (link_down->error_code) {
  107. case FSF_PSQ_LINK_NO_LIGHT:
  108. dev_warn(&req->adapter->ccw_device->dev,
  109. "There is no light signal from the local "
  110. "fibre channel cable\n");
  111. break;
  112. case FSF_PSQ_LINK_WRAP_PLUG:
  113. dev_warn(&req->adapter->ccw_device->dev,
  114. "There is a wrap plug instead of a fibre "
  115. "channel cable\n");
  116. break;
  117. case FSF_PSQ_LINK_NO_FCP:
  118. dev_warn(&req->adapter->ccw_device->dev,
  119. "The adjacent fibre channel node does not "
  120. "support FCP\n");
  121. break;
  122. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  123. dev_warn(&req->adapter->ccw_device->dev,
  124. "The FCP device is suspended because of a "
  125. "firmware update\n");
  126. break;
  127. case FSF_PSQ_LINK_INVALID_WWPN:
  128. dev_warn(&req->adapter->ccw_device->dev,
  129. "The FCP device detected a WWPN that is "
  130. "duplicate or not valid\n");
  131. break;
  132. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  133. dev_warn(&req->adapter->ccw_device->dev,
  134. "The fibre channel fabric does not support NPIV\n");
  135. break;
  136. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  137. dev_warn(&req->adapter->ccw_device->dev,
  138. "The FCP adapter cannot support more NPIV ports\n");
  139. break;
  140. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  141. dev_warn(&req->adapter->ccw_device->dev,
  142. "The adjacent switch cannot support "
  143. "more NPIV ports\n");
  144. break;
  145. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  146. dev_warn(&req->adapter->ccw_device->dev,
  147. "The FCP adapter could not log in to the "
  148. "fibre channel fabric\n");
  149. break;
  150. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  151. dev_warn(&req->adapter->ccw_device->dev,
  152. "The WWPN assignment file on the FCP adapter "
  153. "has been damaged\n");
  154. break;
  155. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  156. dev_warn(&req->adapter->ccw_device->dev,
  157. "The mode table on the FCP adapter "
  158. "has been damaged\n");
  159. break;
  160. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  161. dev_warn(&req->adapter->ccw_device->dev,
  162. "All NPIV ports on the FCP adapter have "
  163. "been assigned\n");
  164. break;
  165. default:
  166. dev_warn(&req->adapter->ccw_device->dev,
  167. "The link between the FCP adapter and "
  168. "the FC fabric is down\n");
  169. }
  170. out:
  171. zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  172. }
  173. static void zfcp_fsf_status_read_link_down(struct zfcp_fsf_req *req)
  174. {
  175. struct fsf_status_read_buffer *sr_buf = req->data;
  176. struct fsf_link_down_info *ldi =
  177. (struct fsf_link_down_info *) &sr_buf->payload;
  178. switch (sr_buf->status_subtype) {
  179. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  180. zfcp_fsf_link_down_info_eval(req, ldi);
  181. break;
  182. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  183. zfcp_fsf_link_down_info_eval(req, ldi);
  184. break;
  185. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  186. zfcp_fsf_link_down_info_eval(req, NULL);
  187. };
  188. }
  189. static void zfcp_fsf_status_read_handler(struct zfcp_fsf_req *req)
  190. {
  191. struct zfcp_adapter *adapter = req->adapter;
  192. struct fsf_status_read_buffer *sr_buf = req->data;
  193. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  194. zfcp_dbf_hba_fsf_uss("fssrh_1", req);
  195. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  196. zfcp_fsf_req_free(req);
  197. return;
  198. }
  199. zfcp_dbf_hba_fsf_uss("fssrh_4", req);
  200. switch (sr_buf->status_type) {
  201. case FSF_STATUS_READ_PORT_CLOSED:
  202. zfcp_fsf_status_read_port_closed(req);
  203. break;
  204. case FSF_STATUS_READ_INCOMING_ELS:
  205. zfcp_fc_incoming_els(req);
  206. break;
  207. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  208. break;
  209. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  210. dev_warn(&adapter->ccw_device->dev,
  211. "The error threshold for checksum statistics "
  212. "has been exceeded\n");
  213. zfcp_dbf_hba_bit_err("fssrh_3", req);
  214. break;
  215. case FSF_STATUS_READ_LINK_DOWN:
  216. zfcp_fsf_status_read_link_down(req);
  217. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKDOWN, 0);
  218. break;
  219. case FSF_STATUS_READ_LINK_UP:
  220. dev_info(&adapter->ccw_device->dev,
  221. "The local link has been restored\n");
  222. /* All ports should be marked as ready to run again */
  223. zfcp_erp_set_adapter_status(adapter,
  224. ZFCP_STATUS_COMMON_RUNNING);
  225. zfcp_erp_adapter_reopen(adapter,
  226. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  227. ZFCP_STATUS_COMMON_ERP_FAILED,
  228. "fssrh_2");
  229. zfcp_fc_enqueue_event(adapter, FCH_EVT_LINKUP, 0);
  230. break;
  231. case FSF_STATUS_READ_NOTIFICATION_LOST:
  232. if (sr_buf->status_subtype & FSF_STATUS_READ_SUB_INCOMING_ELS)
  233. zfcp_fc_conditional_port_scan(adapter);
  234. break;
  235. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  236. adapter->adapter_features = sr_buf->payload.word[0];
  237. break;
  238. }
  239. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  240. zfcp_fsf_req_free(req);
  241. atomic_inc(&adapter->stat_miss);
  242. queue_work(adapter->work_queue, &adapter->stat_work);
  243. }
  244. static void zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *req)
  245. {
  246. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  247. case FSF_SQ_FCP_RSP_AVAILABLE:
  248. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  249. case FSF_SQ_NO_RETRY_POSSIBLE:
  250. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  251. return;
  252. case FSF_SQ_COMMAND_ABORTED:
  253. break;
  254. case FSF_SQ_NO_RECOM:
  255. dev_err(&req->adapter->ccw_device->dev,
  256. "The FCP adapter reported a problem "
  257. "that cannot be recovered\n");
  258. zfcp_qdio_siosl(req->adapter);
  259. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfsqe1");
  260. break;
  261. }
  262. /* all non-return stats set FSFREQ_ERROR*/
  263. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  264. }
  265. static void zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *req)
  266. {
  267. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  268. return;
  269. switch (req->qtcb->header.fsf_status) {
  270. case FSF_UNKNOWN_COMMAND:
  271. dev_err(&req->adapter->ccw_device->dev,
  272. "The FCP adapter does not recognize the command 0x%x\n",
  273. req->qtcb->header.fsf_command);
  274. zfcp_erp_adapter_shutdown(req->adapter, 0, "fsfse_1");
  275. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  276. break;
  277. case FSF_ADAPTER_STATUS_AVAILABLE:
  278. zfcp_fsf_fsfstatus_qual_eval(req);
  279. break;
  280. }
  281. }
  282. static void zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *req)
  283. {
  284. struct zfcp_adapter *adapter = req->adapter;
  285. struct fsf_qtcb *qtcb = req->qtcb;
  286. union fsf_prot_status_qual *psq = &qtcb->prefix.prot_status_qual;
  287. zfcp_dbf_hba_fsf_response(req);
  288. if (req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  289. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  290. return;
  291. }
  292. switch (qtcb->prefix.prot_status) {
  293. case FSF_PROT_GOOD:
  294. case FSF_PROT_FSF_STATUS_PRESENTED:
  295. return;
  296. case FSF_PROT_QTCB_VERSION_ERROR:
  297. dev_err(&adapter->ccw_device->dev,
  298. "QTCB version 0x%x not supported by FCP adapter "
  299. "(0x%x to 0x%x)\n", FSF_QTCB_CURRENT_VERSION,
  300. psq->word[0], psq->word[1]);
  301. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_1");
  302. break;
  303. case FSF_PROT_ERROR_STATE:
  304. case FSF_PROT_SEQ_NUMB_ERROR:
  305. zfcp_erp_adapter_reopen(adapter, 0, "fspse_2");
  306. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  307. break;
  308. case FSF_PROT_UNSUPP_QTCB_TYPE:
  309. dev_err(&adapter->ccw_device->dev,
  310. "The QTCB type is not supported by the FCP adapter\n");
  311. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_3");
  312. break;
  313. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  314. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  315. &adapter->status);
  316. break;
  317. case FSF_PROT_DUPLICATE_REQUEST_ID:
  318. dev_err(&adapter->ccw_device->dev,
  319. "0x%Lx is an ambiguous request identifier\n",
  320. (unsigned long long)qtcb->bottom.support.req_handle);
  321. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_4");
  322. break;
  323. case FSF_PROT_LINK_DOWN:
  324. zfcp_fsf_link_down_info_eval(req, &psq->link_down_info);
  325. /* go through reopen to flush pending requests */
  326. zfcp_erp_adapter_reopen(adapter, 0, "fspse_6");
  327. break;
  328. case FSF_PROT_REEST_QUEUE:
  329. /* All ports should be marked as ready to run again */
  330. zfcp_erp_set_adapter_status(adapter,
  331. ZFCP_STATUS_COMMON_RUNNING);
  332. zfcp_erp_adapter_reopen(adapter,
  333. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  334. ZFCP_STATUS_COMMON_ERP_FAILED,
  335. "fspse_8");
  336. break;
  337. default:
  338. dev_err(&adapter->ccw_device->dev,
  339. "0x%x is not a valid transfer protocol status\n",
  340. qtcb->prefix.prot_status);
  341. zfcp_qdio_siosl(adapter);
  342. zfcp_erp_adapter_shutdown(adapter, 0, "fspse_9");
  343. }
  344. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  345. }
  346. /**
  347. * zfcp_fsf_req_complete - process completion of a FSF request
  348. * @fsf_req: The FSF request that has been completed.
  349. *
  350. * When a request has been completed either from the FCP adapter,
  351. * or it has been dismissed due to a queue shutdown, this function
  352. * is called to process the completion status and trigger further
  353. * events related to the FSF request.
  354. */
  355. static void zfcp_fsf_req_complete(struct zfcp_fsf_req *req)
  356. {
  357. if (unlikely(req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  358. zfcp_fsf_status_read_handler(req);
  359. return;
  360. }
  361. del_timer(&req->timer);
  362. zfcp_fsf_protstatus_eval(req);
  363. zfcp_fsf_fsfstatus_eval(req);
  364. req->handler(req);
  365. if (req->erp_action)
  366. zfcp_erp_notify(req->erp_action, 0);
  367. if (likely(req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  368. zfcp_fsf_req_free(req);
  369. else
  370. complete(&req->completion);
  371. }
  372. /**
  373. * zfcp_fsf_req_dismiss_all - dismiss all fsf requests
  374. * @adapter: pointer to struct zfcp_adapter
  375. *
  376. * Never ever call this without shutting down the adapter first.
  377. * Otherwise the adapter would continue using and corrupting s390 storage.
  378. * Included BUG_ON() call to ensure this is done.
  379. * ERP is supposed to be the only user of this function.
  380. */
  381. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  382. {
  383. struct zfcp_fsf_req *req, *tmp;
  384. LIST_HEAD(remove_queue);
  385. BUG_ON(atomic_read(&adapter->status) & ZFCP_STATUS_ADAPTER_QDIOUP);
  386. zfcp_reqlist_move(adapter->req_list, &remove_queue);
  387. list_for_each_entry_safe(req, tmp, &remove_queue, list) {
  388. list_del(&req->list);
  389. req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  390. zfcp_fsf_req_complete(req);
  391. }
  392. }
  393. #define ZFCP_FSF_PORTSPEED_1GBIT (1 << 0)
  394. #define ZFCP_FSF_PORTSPEED_2GBIT (1 << 1)
  395. #define ZFCP_FSF_PORTSPEED_4GBIT (1 << 2)
  396. #define ZFCP_FSF_PORTSPEED_10GBIT (1 << 3)
  397. #define ZFCP_FSF_PORTSPEED_8GBIT (1 << 4)
  398. #define ZFCP_FSF_PORTSPEED_16GBIT (1 << 5)
  399. #define ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED (1 << 15)
  400. static u32 zfcp_fsf_convert_portspeed(u32 fsf_speed)
  401. {
  402. u32 fdmi_speed = 0;
  403. if (fsf_speed & ZFCP_FSF_PORTSPEED_1GBIT)
  404. fdmi_speed |= FC_PORTSPEED_1GBIT;
  405. if (fsf_speed & ZFCP_FSF_PORTSPEED_2GBIT)
  406. fdmi_speed |= FC_PORTSPEED_2GBIT;
  407. if (fsf_speed & ZFCP_FSF_PORTSPEED_4GBIT)
  408. fdmi_speed |= FC_PORTSPEED_4GBIT;
  409. if (fsf_speed & ZFCP_FSF_PORTSPEED_10GBIT)
  410. fdmi_speed |= FC_PORTSPEED_10GBIT;
  411. if (fsf_speed & ZFCP_FSF_PORTSPEED_8GBIT)
  412. fdmi_speed |= FC_PORTSPEED_8GBIT;
  413. if (fsf_speed & ZFCP_FSF_PORTSPEED_16GBIT)
  414. fdmi_speed |= FC_PORTSPEED_16GBIT;
  415. if (fsf_speed & ZFCP_FSF_PORTSPEED_NOT_NEGOTIATED)
  416. fdmi_speed |= FC_PORTSPEED_NOT_NEGOTIATED;
  417. return fdmi_speed;
  418. }
  419. static int zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *req)
  420. {
  421. struct fsf_qtcb_bottom_config *bottom = &req->qtcb->bottom.config;
  422. struct zfcp_adapter *adapter = req->adapter;
  423. struct Scsi_Host *shost = adapter->scsi_host;
  424. struct fc_els_flogi *nsp, *plogi;
  425. /* adjust pointers for missing command code */
  426. nsp = (struct fc_els_flogi *) ((u8 *)&bottom->nport_serv_param
  427. - sizeof(u32));
  428. plogi = (struct fc_els_flogi *) ((u8 *)&bottom->plogi_payload
  429. - sizeof(u32));
  430. if (req->data)
  431. memcpy(req->data, bottom, sizeof(*bottom));
  432. fc_host_port_name(shost) = nsp->fl_wwpn;
  433. fc_host_node_name(shost) = nsp->fl_wwnn;
  434. fc_host_supported_classes(shost) = FC_COS_CLASS2 | FC_COS_CLASS3;
  435. adapter->timer_ticks = bottom->timer_interval & ZFCP_FSF_TIMER_INT_MASK;
  436. adapter->stat_read_buf_num = max(bottom->status_read_buf_num,
  437. (u16)FSF_STATUS_READS_RECOM);
  438. if (fc_host_permanent_port_name(shost) == -1)
  439. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  440. zfcp_scsi_set_prot(adapter);
  441. /* no error return above here, otherwise must fix call chains */
  442. /* do not evaluate invalid fields */
  443. if (req->qtcb->header.fsf_status == FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE)
  444. return 0;
  445. fc_host_port_id(shost) = ntoh24(bottom->s_id);
  446. fc_host_speed(shost) =
  447. zfcp_fsf_convert_portspeed(bottom->fc_link_speed);
  448. adapter->hydra_version = bottom->adapter_type;
  449. switch (bottom->fc_topology) {
  450. case FSF_TOPO_P2P:
  451. adapter->peer_d_id = ntoh24(bottom->peer_d_id);
  452. adapter->peer_wwpn = plogi->fl_wwpn;
  453. adapter->peer_wwnn = plogi->fl_wwnn;
  454. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  455. break;
  456. case FSF_TOPO_FABRIC:
  457. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  458. break;
  459. case FSF_TOPO_AL:
  460. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  461. /* fall through */
  462. default:
  463. dev_err(&adapter->ccw_device->dev,
  464. "Unknown or unsupported arbitrated loop "
  465. "fibre channel topology detected\n");
  466. zfcp_erp_adapter_shutdown(adapter, 0, "fsece_1");
  467. return -EIO;
  468. }
  469. return 0;
  470. }
  471. static void zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *req)
  472. {
  473. struct zfcp_adapter *adapter = req->adapter;
  474. struct fsf_qtcb *qtcb = req->qtcb;
  475. struct fsf_qtcb_bottom_config *bottom = &qtcb->bottom.config;
  476. struct Scsi_Host *shost = adapter->scsi_host;
  477. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  478. return;
  479. adapter->fsf_lic_version = bottom->lic_version;
  480. adapter->adapter_features = bottom->adapter_features;
  481. adapter->connection_features = bottom->connection_features;
  482. adapter->peer_wwpn = 0;
  483. adapter->peer_wwnn = 0;
  484. adapter->peer_d_id = 0;
  485. switch (qtcb->header.fsf_status) {
  486. case FSF_GOOD:
  487. if (zfcp_fsf_exchange_config_evaluate(req))
  488. return;
  489. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  490. dev_err(&adapter->ccw_device->dev,
  491. "FCP adapter maximum QTCB size (%d bytes) "
  492. "is too small\n",
  493. bottom->max_qtcb_size);
  494. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh1");
  495. return;
  496. }
  497. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  498. &adapter->status);
  499. break;
  500. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  501. fc_host_node_name(shost) = 0;
  502. fc_host_port_name(shost) = 0;
  503. fc_host_port_id(shost) = 0;
  504. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  505. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  506. adapter->hydra_version = 0;
  507. /* avoids adapter shutdown to be able to recognize
  508. * events such as LINK UP */
  509. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  510. &adapter->status);
  511. zfcp_fsf_link_down_info_eval(req,
  512. &qtcb->header.fsf_status_qual.link_down_info);
  513. if (zfcp_fsf_exchange_config_evaluate(req))
  514. return;
  515. break;
  516. default:
  517. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh3");
  518. return;
  519. }
  520. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  521. adapter->hardware_version = bottom->hardware_version;
  522. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  523. min(FC_SERIAL_NUMBER_SIZE, 17));
  524. EBCASC(fc_host_serial_number(shost),
  525. min(FC_SERIAL_NUMBER_SIZE, 17));
  526. }
  527. if (FSF_QTCB_CURRENT_VERSION < bottom->low_qtcb_version) {
  528. dev_err(&adapter->ccw_device->dev,
  529. "The FCP adapter only supports newer "
  530. "control block versions\n");
  531. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh4");
  532. return;
  533. }
  534. if (FSF_QTCB_CURRENT_VERSION > bottom->high_qtcb_version) {
  535. dev_err(&adapter->ccw_device->dev,
  536. "The FCP adapter only supports older "
  537. "control block versions\n");
  538. zfcp_erp_adapter_shutdown(adapter, 0, "fsecdh5");
  539. }
  540. }
  541. static void zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *req)
  542. {
  543. struct zfcp_adapter *adapter = req->adapter;
  544. struct fsf_qtcb_bottom_port *bottom = &req->qtcb->bottom.port;
  545. struct Scsi_Host *shost = adapter->scsi_host;
  546. if (req->data)
  547. memcpy(req->data, bottom, sizeof(*bottom));
  548. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE) {
  549. fc_host_permanent_port_name(shost) = bottom->wwpn;
  550. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  551. } else
  552. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  553. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  554. fc_host_supported_speeds(shost) =
  555. zfcp_fsf_convert_portspeed(bottom->supported_speed);
  556. memcpy(fc_host_supported_fc4s(shost), bottom->supported_fc4_types,
  557. FC_FC4_LIST_SIZE);
  558. memcpy(fc_host_active_fc4s(shost), bottom->active_fc4_types,
  559. FC_FC4_LIST_SIZE);
  560. }
  561. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *req)
  562. {
  563. struct fsf_qtcb *qtcb = req->qtcb;
  564. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  565. return;
  566. switch (qtcb->header.fsf_status) {
  567. case FSF_GOOD:
  568. zfcp_fsf_exchange_port_evaluate(req);
  569. break;
  570. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  571. zfcp_fsf_exchange_port_evaluate(req);
  572. zfcp_fsf_link_down_info_eval(req,
  573. &qtcb->header.fsf_status_qual.link_down_info);
  574. break;
  575. }
  576. }
  577. static struct zfcp_fsf_req *zfcp_fsf_alloc(mempool_t *pool)
  578. {
  579. struct zfcp_fsf_req *req;
  580. if (likely(pool))
  581. req = mempool_alloc(pool, GFP_ATOMIC);
  582. else
  583. req = kmalloc(sizeof(*req), GFP_ATOMIC);
  584. if (unlikely(!req))
  585. return NULL;
  586. memset(req, 0, sizeof(*req));
  587. req->pool = pool;
  588. return req;
  589. }
  590. static struct fsf_qtcb *zfcp_qtcb_alloc(mempool_t *pool)
  591. {
  592. struct fsf_qtcb *qtcb;
  593. if (likely(pool))
  594. qtcb = mempool_alloc(pool, GFP_ATOMIC);
  595. else
  596. qtcb = kmem_cache_alloc(zfcp_fsf_qtcb_cache, GFP_ATOMIC);
  597. if (unlikely(!qtcb))
  598. return NULL;
  599. memset(qtcb, 0, sizeof(*qtcb));
  600. return qtcb;
  601. }
  602. static struct zfcp_fsf_req *zfcp_fsf_req_create(struct zfcp_qdio *qdio,
  603. u32 fsf_cmd, u8 sbtype,
  604. mempool_t *pool)
  605. {
  606. struct zfcp_adapter *adapter = qdio->adapter;
  607. struct zfcp_fsf_req *req = zfcp_fsf_alloc(pool);
  608. if (unlikely(!req))
  609. return ERR_PTR(-ENOMEM);
  610. if (adapter->req_no == 0)
  611. adapter->req_no++;
  612. INIT_LIST_HEAD(&req->list);
  613. init_timer(&req->timer);
  614. init_completion(&req->completion);
  615. req->adapter = adapter;
  616. req->fsf_command = fsf_cmd;
  617. req->req_id = adapter->req_no;
  618. if (likely(fsf_cmd != FSF_QTCB_UNSOLICITED_STATUS)) {
  619. if (likely(pool))
  620. req->qtcb = zfcp_qtcb_alloc(adapter->pool.qtcb_pool);
  621. else
  622. req->qtcb = zfcp_qtcb_alloc(NULL);
  623. if (unlikely(!req->qtcb)) {
  624. zfcp_fsf_req_free(req);
  625. return ERR_PTR(-ENOMEM);
  626. }
  627. req->seq_no = adapter->fsf_req_seq_no;
  628. req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  629. req->qtcb->prefix.req_id = req->req_id;
  630. req->qtcb->prefix.ulp_info = 26;
  631. req->qtcb->prefix.qtcb_type = fsf_qtcb_type[req->fsf_command];
  632. req->qtcb->prefix.qtcb_version = FSF_QTCB_CURRENT_VERSION;
  633. req->qtcb->header.req_handle = req->req_id;
  634. req->qtcb->header.fsf_command = req->fsf_command;
  635. }
  636. zfcp_qdio_req_init(adapter->qdio, &req->qdio_req, req->req_id, sbtype,
  637. req->qtcb, sizeof(struct fsf_qtcb));
  638. return req;
  639. }
  640. static int zfcp_fsf_req_send(struct zfcp_fsf_req *req)
  641. {
  642. struct zfcp_adapter *adapter = req->adapter;
  643. struct zfcp_qdio *qdio = adapter->qdio;
  644. int with_qtcb = (req->qtcb != NULL);
  645. int req_id = req->req_id;
  646. zfcp_reqlist_add(adapter->req_list, req);
  647. req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free);
  648. req->issued = get_tod_clock();
  649. if (zfcp_qdio_send(qdio, &req->qdio_req)) {
  650. del_timer(&req->timer);
  651. /* lookup request again, list might have changed */
  652. zfcp_reqlist_find_rm(adapter->req_list, req_id);
  653. zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");
  654. return -EIO;
  655. }
  656. /* Don't increase for unsolicited status */
  657. if (with_qtcb)
  658. adapter->fsf_req_seq_no++;
  659. adapter->req_no++;
  660. return 0;
  661. }
  662. /**
  663. * zfcp_fsf_status_read - send status read request
  664. * @adapter: pointer to struct zfcp_adapter
  665. * @req_flags: request flags
  666. * Returns: 0 on success, ERROR otherwise
  667. */
  668. int zfcp_fsf_status_read(struct zfcp_qdio *qdio)
  669. {
  670. struct zfcp_adapter *adapter = qdio->adapter;
  671. struct zfcp_fsf_req *req;
  672. struct fsf_status_read_buffer *sr_buf;
  673. struct page *page;
  674. int retval = -EIO;
  675. spin_lock_irq(&qdio->req_q_lock);
  676. if (zfcp_qdio_sbal_get(qdio))
  677. goto out;
  678. req = zfcp_fsf_req_create(qdio, FSF_QTCB_UNSOLICITED_STATUS,
  679. SBAL_SFLAGS0_TYPE_STATUS,
  680. adapter->pool.status_read_req);
  681. if (IS_ERR(req)) {
  682. retval = PTR_ERR(req);
  683. goto out;
  684. }
  685. page = mempool_alloc(adapter->pool.sr_data, GFP_ATOMIC);
  686. if (!page) {
  687. retval = -ENOMEM;
  688. goto failed_buf;
  689. }
  690. sr_buf = page_address(page);
  691. memset(sr_buf, 0, sizeof(*sr_buf));
  692. req->data = sr_buf;
  693. zfcp_qdio_fill_next(qdio, &req->qdio_req, sr_buf, sizeof(*sr_buf));
  694. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  695. retval = zfcp_fsf_req_send(req);
  696. if (retval)
  697. goto failed_req_send;
  698. goto out;
  699. failed_req_send:
  700. req->data = NULL;
  701. mempool_free(virt_to_page(sr_buf), adapter->pool.sr_data);
  702. failed_buf:
  703. zfcp_dbf_hba_fsf_uss("fssr__1", req);
  704. zfcp_fsf_req_free(req);
  705. out:
  706. spin_unlock_irq(&qdio->req_q_lock);
  707. return retval;
  708. }
  709. static void zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *req)
  710. {
  711. struct scsi_device *sdev = req->data;
  712. struct zfcp_scsi_dev *zfcp_sdev;
  713. union fsf_status_qual *fsq = &req->qtcb->header.fsf_status_qual;
  714. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  715. return;
  716. zfcp_sdev = sdev_to_zfcp(sdev);
  717. switch (req->qtcb->header.fsf_status) {
  718. case FSF_PORT_HANDLE_NOT_VALID:
  719. if (fsq->word[0] == fsq->word[1]) {
  720. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0,
  721. "fsafch1");
  722. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  723. }
  724. break;
  725. case FSF_LUN_HANDLE_NOT_VALID:
  726. if (fsq->word[0] == fsq->word[1]) {
  727. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fsafch2");
  728. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  729. }
  730. break;
  731. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  732. req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  733. break;
  734. case FSF_PORT_BOXED:
  735. zfcp_erp_set_port_status(zfcp_sdev->port,
  736. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  737. zfcp_erp_port_reopen(zfcp_sdev->port,
  738. ZFCP_STATUS_COMMON_ERP_FAILED, "fsafch3");
  739. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  740. break;
  741. case FSF_LUN_BOXED:
  742. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  743. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  744. "fsafch4");
  745. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  746. break;
  747. case FSF_ADAPTER_STATUS_AVAILABLE:
  748. switch (fsq->word[0]) {
  749. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  750. zfcp_fc_test_link(zfcp_sdev->port);
  751. /* fall through */
  752. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  753. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  754. break;
  755. }
  756. break;
  757. case FSF_GOOD:
  758. req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  759. break;
  760. }
  761. }
  762. /**
  763. * zfcp_fsf_abort_fcp_cmnd - abort running SCSI command
  764. * @scmnd: The SCSI command to abort
  765. * Returns: pointer to struct zfcp_fsf_req
  766. */
  767. struct zfcp_fsf_req *zfcp_fsf_abort_fcp_cmnd(struct scsi_cmnd *scmnd)
  768. {
  769. struct zfcp_fsf_req *req = NULL;
  770. struct scsi_device *sdev = scmnd->device;
  771. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  772. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  773. unsigned long old_req_id = (unsigned long) scmnd->host_scribble;
  774. spin_lock_irq(&qdio->req_q_lock);
  775. if (zfcp_qdio_sbal_get(qdio))
  776. goto out;
  777. req = zfcp_fsf_req_create(qdio, FSF_QTCB_ABORT_FCP_CMND,
  778. SBAL_SFLAGS0_TYPE_READ,
  779. qdio->adapter->pool.scsi_abort);
  780. if (IS_ERR(req)) {
  781. req = NULL;
  782. goto out;
  783. }
  784. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  785. ZFCP_STATUS_COMMON_UNBLOCKED)))
  786. goto out_error_free;
  787. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  788. req->data = sdev;
  789. req->handler = zfcp_fsf_abort_fcp_command_handler;
  790. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  791. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  792. req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  793. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  794. if (!zfcp_fsf_req_send(req))
  795. goto out;
  796. out_error_free:
  797. zfcp_fsf_req_free(req);
  798. req = NULL;
  799. out:
  800. spin_unlock_irq(&qdio->req_q_lock);
  801. return req;
  802. }
  803. static void zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *req)
  804. {
  805. struct zfcp_adapter *adapter = req->adapter;
  806. struct zfcp_fsf_ct_els *ct = req->data;
  807. struct fsf_qtcb_header *header = &req->qtcb->header;
  808. ct->status = -EINVAL;
  809. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  810. goto skip_fsfstatus;
  811. switch (header->fsf_status) {
  812. case FSF_GOOD:
  813. zfcp_dbf_san_res("fsscth2", req);
  814. ct->status = 0;
  815. break;
  816. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  817. zfcp_fsf_class_not_supp(req);
  818. break;
  819. case FSF_ADAPTER_STATUS_AVAILABLE:
  820. switch (header->fsf_status_qual.word[0]){
  821. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  822. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  823. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  824. break;
  825. }
  826. break;
  827. case FSF_PORT_BOXED:
  828. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  829. break;
  830. case FSF_PORT_HANDLE_NOT_VALID:
  831. zfcp_erp_adapter_reopen(adapter, 0, "fsscth1");
  832. /* fall through */
  833. case FSF_GENERIC_COMMAND_REJECTED:
  834. case FSF_PAYLOAD_SIZE_MISMATCH:
  835. case FSF_REQUEST_SIZE_TOO_LARGE:
  836. case FSF_RESPONSE_SIZE_TOO_LARGE:
  837. case FSF_SBAL_MISMATCH:
  838. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  839. break;
  840. }
  841. skip_fsfstatus:
  842. if (ct->handler)
  843. ct->handler(ct->handler_data);
  844. }
  845. static void zfcp_fsf_setup_ct_els_unchained(struct zfcp_qdio *qdio,
  846. struct zfcp_qdio_req *q_req,
  847. struct scatterlist *sg_req,
  848. struct scatterlist *sg_resp)
  849. {
  850. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_req), sg_req->length);
  851. zfcp_qdio_fill_next(qdio, q_req, sg_virt(sg_resp), sg_resp->length);
  852. zfcp_qdio_set_sbale_last(qdio, q_req);
  853. }
  854. static int zfcp_fsf_setup_ct_els_sbals(struct zfcp_fsf_req *req,
  855. struct scatterlist *sg_req,
  856. struct scatterlist *sg_resp)
  857. {
  858. struct zfcp_adapter *adapter = req->adapter;
  859. struct zfcp_qdio *qdio = adapter->qdio;
  860. struct fsf_qtcb *qtcb = req->qtcb;
  861. u32 feat = adapter->adapter_features;
  862. if (zfcp_adapter_multi_buffer_active(adapter)) {
  863. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  864. return -EIO;
  865. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  866. return -EIO;
  867. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  868. zfcp_qdio_sbale_count(sg_req));
  869. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  870. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  871. return 0;
  872. }
  873. /* use single, unchained SBAL if it can hold the request */
  874. if (zfcp_qdio_sg_one_sbale(sg_req) && zfcp_qdio_sg_one_sbale(sg_resp)) {
  875. zfcp_fsf_setup_ct_els_unchained(qdio, &req->qdio_req,
  876. sg_req, sg_resp);
  877. return 0;
  878. }
  879. if (!(feat & FSF_FEATURE_ELS_CT_CHAINED_SBALS))
  880. return -EOPNOTSUPP;
  881. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_req))
  882. return -EIO;
  883. qtcb->bottom.support.req_buf_length = zfcp_qdio_real_bytes(sg_req);
  884. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  885. zfcp_qdio_skip_to_last_sbale(qdio, &req->qdio_req);
  886. if (zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req, sg_resp))
  887. return -EIO;
  888. qtcb->bottom.support.resp_buf_length = zfcp_qdio_real_bytes(sg_resp);
  889. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  890. return 0;
  891. }
  892. static int zfcp_fsf_setup_ct_els(struct zfcp_fsf_req *req,
  893. struct scatterlist *sg_req,
  894. struct scatterlist *sg_resp,
  895. unsigned int timeout)
  896. {
  897. int ret;
  898. ret = zfcp_fsf_setup_ct_els_sbals(req, sg_req, sg_resp);
  899. if (ret)
  900. return ret;
  901. /* common settings for ct/gs and els requests */
  902. if (timeout > 255)
  903. timeout = 255; /* max value accepted by hardware */
  904. req->qtcb->bottom.support.service_class = FSF_CLASS_3;
  905. req->qtcb->bottom.support.timeout = timeout;
  906. zfcp_fsf_start_timer(req, (timeout + 10) * HZ);
  907. return 0;
  908. }
  909. /**
  910. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  911. * @ct: pointer to struct zfcp_send_ct with data for request
  912. * @pool: if non-null this mempool is used to allocate struct zfcp_fsf_req
  913. */
  914. int zfcp_fsf_send_ct(struct zfcp_fc_wka_port *wka_port,
  915. struct zfcp_fsf_ct_els *ct, mempool_t *pool,
  916. unsigned int timeout)
  917. {
  918. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  919. struct zfcp_fsf_req *req;
  920. int ret = -EIO;
  921. spin_lock_irq(&qdio->req_q_lock);
  922. if (zfcp_qdio_sbal_get(qdio))
  923. goto out;
  924. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_GENERIC,
  925. SBAL_SFLAGS0_TYPE_WRITE_READ, pool);
  926. if (IS_ERR(req)) {
  927. ret = PTR_ERR(req);
  928. goto out;
  929. }
  930. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  931. ret = zfcp_fsf_setup_ct_els(req, ct->req, ct->resp, timeout);
  932. if (ret)
  933. goto failed_send;
  934. req->handler = zfcp_fsf_send_ct_handler;
  935. req->qtcb->header.port_handle = wka_port->handle;
  936. req->data = ct;
  937. zfcp_dbf_san_req("fssct_1", req, wka_port->d_id);
  938. ret = zfcp_fsf_req_send(req);
  939. if (ret)
  940. goto failed_send;
  941. goto out;
  942. failed_send:
  943. zfcp_fsf_req_free(req);
  944. out:
  945. spin_unlock_irq(&qdio->req_q_lock);
  946. return ret;
  947. }
  948. static void zfcp_fsf_send_els_handler(struct zfcp_fsf_req *req)
  949. {
  950. struct zfcp_fsf_ct_els *send_els = req->data;
  951. struct fsf_qtcb_header *header = &req->qtcb->header;
  952. send_els->status = -EINVAL;
  953. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  954. goto skip_fsfstatus;
  955. switch (header->fsf_status) {
  956. case FSF_GOOD:
  957. zfcp_dbf_san_res("fsselh1", req);
  958. send_els->status = 0;
  959. break;
  960. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  961. zfcp_fsf_class_not_supp(req);
  962. break;
  963. case FSF_ADAPTER_STATUS_AVAILABLE:
  964. switch (header->fsf_status_qual.word[0]){
  965. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  966. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  967. case FSF_SQ_RETRY_IF_POSSIBLE:
  968. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  969. break;
  970. }
  971. break;
  972. case FSF_ELS_COMMAND_REJECTED:
  973. case FSF_PAYLOAD_SIZE_MISMATCH:
  974. case FSF_REQUEST_SIZE_TOO_LARGE:
  975. case FSF_RESPONSE_SIZE_TOO_LARGE:
  976. break;
  977. case FSF_SBAL_MISMATCH:
  978. /* should never occur, avoided in zfcp_fsf_send_els */
  979. /* fall through */
  980. default:
  981. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  982. break;
  983. }
  984. skip_fsfstatus:
  985. if (send_els->handler)
  986. send_els->handler(send_els->handler_data);
  987. }
  988. /**
  989. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  990. * @els: pointer to struct zfcp_send_els with data for the command
  991. */
  992. int zfcp_fsf_send_els(struct zfcp_adapter *adapter, u32 d_id,
  993. struct zfcp_fsf_ct_els *els, unsigned int timeout)
  994. {
  995. struct zfcp_fsf_req *req;
  996. struct zfcp_qdio *qdio = adapter->qdio;
  997. int ret = -EIO;
  998. spin_lock_irq(&qdio->req_q_lock);
  999. if (zfcp_qdio_sbal_get(qdio))
  1000. goto out;
  1001. req = zfcp_fsf_req_create(qdio, FSF_QTCB_SEND_ELS,
  1002. SBAL_SFLAGS0_TYPE_WRITE_READ, NULL);
  1003. if (IS_ERR(req)) {
  1004. ret = PTR_ERR(req);
  1005. goto out;
  1006. }
  1007. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1008. if (!zfcp_adapter_multi_buffer_active(adapter))
  1009. zfcp_qdio_sbal_limit(qdio, &req->qdio_req, 2);
  1010. ret = zfcp_fsf_setup_ct_els(req, els->req, els->resp, timeout);
  1011. if (ret)
  1012. goto failed_send;
  1013. hton24(req->qtcb->bottom.support.d_id, d_id);
  1014. req->handler = zfcp_fsf_send_els_handler;
  1015. req->data = els;
  1016. zfcp_dbf_san_req("fssels1", req, d_id);
  1017. ret = zfcp_fsf_req_send(req);
  1018. if (ret)
  1019. goto failed_send;
  1020. goto out;
  1021. failed_send:
  1022. zfcp_fsf_req_free(req);
  1023. out:
  1024. spin_unlock_irq(&qdio->req_q_lock);
  1025. return ret;
  1026. }
  1027. int zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1028. {
  1029. struct zfcp_fsf_req *req;
  1030. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1031. int retval = -EIO;
  1032. spin_lock_irq(&qdio->req_q_lock);
  1033. if (zfcp_qdio_sbal_get(qdio))
  1034. goto out;
  1035. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1036. SBAL_SFLAGS0_TYPE_READ,
  1037. qdio->adapter->pool.erp_req);
  1038. if (IS_ERR(req)) {
  1039. retval = PTR_ERR(req);
  1040. goto out;
  1041. }
  1042. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1043. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1044. req->qtcb->bottom.config.feature_selection =
  1045. FSF_FEATURE_NOTIFICATION_LOST |
  1046. FSF_FEATURE_UPDATE_ALERT;
  1047. req->erp_action = erp_action;
  1048. req->handler = zfcp_fsf_exchange_config_data_handler;
  1049. erp_action->fsf_req_id = req->req_id;
  1050. zfcp_fsf_start_erp_timer(req);
  1051. retval = zfcp_fsf_req_send(req);
  1052. if (retval) {
  1053. zfcp_fsf_req_free(req);
  1054. erp_action->fsf_req_id = 0;
  1055. }
  1056. out:
  1057. spin_unlock_irq(&qdio->req_q_lock);
  1058. return retval;
  1059. }
  1060. int zfcp_fsf_exchange_config_data_sync(struct zfcp_qdio *qdio,
  1061. struct fsf_qtcb_bottom_config *data)
  1062. {
  1063. struct zfcp_fsf_req *req = NULL;
  1064. int retval = -EIO;
  1065. spin_lock_irq(&qdio->req_q_lock);
  1066. if (zfcp_qdio_sbal_get(qdio))
  1067. goto out_unlock;
  1068. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1069. SBAL_SFLAGS0_TYPE_READ, NULL);
  1070. if (IS_ERR(req)) {
  1071. retval = PTR_ERR(req);
  1072. goto out_unlock;
  1073. }
  1074. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1075. req->handler = zfcp_fsf_exchange_config_data_handler;
  1076. req->qtcb->bottom.config.feature_selection =
  1077. FSF_FEATURE_NOTIFICATION_LOST |
  1078. FSF_FEATURE_UPDATE_ALERT;
  1079. if (data)
  1080. req->data = data;
  1081. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1082. retval = zfcp_fsf_req_send(req);
  1083. spin_unlock_irq(&qdio->req_q_lock);
  1084. if (!retval)
  1085. wait_for_completion(&req->completion);
  1086. zfcp_fsf_req_free(req);
  1087. return retval;
  1088. out_unlock:
  1089. spin_unlock_irq(&qdio->req_q_lock);
  1090. return retval;
  1091. }
  1092. /**
  1093. * zfcp_fsf_exchange_port_data - request information about local port
  1094. * @erp_action: ERP action for the adapter for which port data is requested
  1095. * Returns: 0 on success, error otherwise
  1096. */
  1097. int zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1098. {
  1099. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1100. struct zfcp_fsf_req *req;
  1101. int retval = -EIO;
  1102. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1103. return -EOPNOTSUPP;
  1104. spin_lock_irq(&qdio->req_q_lock);
  1105. if (zfcp_qdio_sbal_get(qdio))
  1106. goto out;
  1107. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1108. SBAL_SFLAGS0_TYPE_READ,
  1109. qdio->adapter->pool.erp_req);
  1110. if (IS_ERR(req)) {
  1111. retval = PTR_ERR(req);
  1112. goto out;
  1113. }
  1114. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1115. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1116. req->handler = zfcp_fsf_exchange_port_data_handler;
  1117. req->erp_action = erp_action;
  1118. erp_action->fsf_req_id = req->req_id;
  1119. zfcp_fsf_start_erp_timer(req);
  1120. retval = zfcp_fsf_req_send(req);
  1121. if (retval) {
  1122. zfcp_fsf_req_free(req);
  1123. erp_action->fsf_req_id = 0;
  1124. }
  1125. out:
  1126. spin_unlock_irq(&qdio->req_q_lock);
  1127. return retval;
  1128. }
  1129. /**
  1130. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1131. * @qdio: pointer to struct zfcp_qdio
  1132. * @data: pointer to struct fsf_qtcb_bottom_port
  1133. * Returns: 0 on success, error otherwise
  1134. */
  1135. int zfcp_fsf_exchange_port_data_sync(struct zfcp_qdio *qdio,
  1136. struct fsf_qtcb_bottom_port *data)
  1137. {
  1138. struct zfcp_fsf_req *req = NULL;
  1139. int retval = -EIO;
  1140. if (!(qdio->adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT))
  1141. return -EOPNOTSUPP;
  1142. spin_lock_irq(&qdio->req_q_lock);
  1143. if (zfcp_qdio_sbal_get(qdio))
  1144. goto out_unlock;
  1145. req = zfcp_fsf_req_create(qdio, FSF_QTCB_EXCHANGE_PORT_DATA,
  1146. SBAL_SFLAGS0_TYPE_READ, NULL);
  1147. if (IS_ERR(req)) {
  1148. retval = PTR_ERR(req);
  1149. goto out_unlock;
  1150. }
  1151. if (data)
  1152. req->data = data;
  1153. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1154. req->handler = zfcp_fsf_exchange_port_data_handler;
  1155. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1156. retval = zfcp_fsf_req_send(req);
  1157. spin_unlock_irq(&qdio->req_q_lock);
  1158. if (!retval)
  1159. wait_for_completion(&req->completion);
  1160. zfcp_fsf_req_free(req);
  1161. return retval;
  1162. out_unlock:
  1163. spin_unlock_irq(&qdio->req_q_lock);
  1164. return retval;
  1165. }
  1166. static void zfcp_fsf_open_port_handler(struct zfcp_fsf_req *req)
  1167. {
  1168. struct zfcp_port *port = req->data;
  1169. struct fsf_qtcb_header *header = &req->qtcb->header;
  1170. struct fc_els_flogi *plogi;
  1171. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1172. goto out;
  1173. switch (header->fsf_status) {
  1174. case FSF_PORT_ALREADY_OPEN:
  1175. break;
  1176. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1177. dev_warn(&req->adapter->ccw_device->dev,
  1178. "Not enough FCP adapter resources to open "
  1179. "remote port 0x%016Lx\n",
  1180. (unsigned long long)port->wwpn);
  1181. zfcp_erp_set_port_status(port,
  1182. ZFCP_STATUS_COMMON_ERP_FAILED);
  1183. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1184. break;
  1185. case FSF_ADAPTER_STATUS_AVAILABLE:
  1186. switch (header->fsf_status_qual.word[0]) {
  1187. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1188. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1189. case FSF_SQ_NO_RETRY_POSSIBLE:
  1190. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1191. break;
  1192. }
  1193. break;
  1194. case FSF_GOOD:
  1195. port->handle = header->port_handle;
  1196. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  1197. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1198. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1199. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1200. &port->status);
  1201. /* check whether D_ID has changed during open */
  1202. /*
  1203. * FIXME: This check is not airtight, as the FCP channel does
  1204. * not monitor closures of target port connections caused on
  1205. * the remote side. Thus, they might miss out on invalidating
  1206. * locally cached WWPNs (and other N_Port parameters) of gone
  1207. * target ports. So, our heroic attempt to make things safe
  1208. * could be undermined by 'open port' response data tagged with
  1209. * obsolete WWPNs. Another reason to monitor potential
  1210. * connection closures ourself at least (by interpreting
  1211. * incoming ELS' and unsolicited status). It just crosses my
  1212. * mind that one should be able to cross-check by means of
  1213. * another GID_PN straight after a port has been opened.
  1214. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  1215. */
  1216. plogi = (struct fc_els_flogi *) req->qtcb->bottom.support.els;
  1217. if (req->qtcb->bottom.support.els1_length >=
  1218. FSF_PLOGI_MIN_LEN)
  1219. zfcp_fc_plogi_evaluate(port, plogi);
  1220. break;
  1221. case FSF_UNKNOWN_OP_SUBTYPE:
  1222. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1223. break;
  1224. }
  1225. out:
  1226. put_device(&port->dev);
  1227. }
  1228. /**
  1229. * zfcp_fsf_open_port - create and send open port request
  1230. * @erp_action: pointer to struct zfcp_erp_action
  1231. * Returns: 0 on success, error otherwise
  1232. */
  1233. int zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  1234. {
  1235. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1236. struct zfcp_port *port = erp_action->port;
  1237. struct zfcp_fsf_req *req;
  1238. int retval = -EIO;
  1239. spin_lock_irq(&qdio->req_q_lock);
  1240. if (zfcp_qdio_sbal_get(qdio))
  1241. goto out;
  1242. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1243. SBAL_SFLAGS0_TYPE_READ,
  1244. qdio->adapter->pool.erp_req);
  1245. if (IS_ERR(req)) {
  1246. retval = PTR_ERR(req);
  1247. goto out;
  1248. }
  1249. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1250. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1251. req->handler = zfcp_fsf_open_port_handler;
  1252. hton24(req->qtcb->bottom.support.d_id, port->d_id);
  1253. req->data = port;
  1254. req->erp_action = erp_action;
  1255. erp_action->fsf_req_id = req->req_id;
  1256. get_device(&port->dev);
  1257. zfcp_fsf_start_erp_timer(req);
  1258. retval = zfcp_fsf_req_send(req);
  1259. if (retval) {
  1260. zfcp_fsf_req_free(req);
  1261. erp_action->fsf_req_id = 0;
  1262. put_device(&port->dev);
  1263. }
  1264. out:
  1265. spin_unlock_irq(&qdio->req_q_lock);
  1266. return retval;
  1267. }
  1268. static void zfcp_fsf_close_port_handler(struct zfcp_fsf_req *req)
  1269. {
  1270. struct zfcp_port *port = req->data;
  1271. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1272. return;
  1273. switch (req->qtcb->header.fsf_status) {
  1274. case FSF_PORT_HANDLE_NOT_VALID:
  1275. zfcp_erp_adapter_reopen(port->adapter, 0, "fscph_1");
  1276. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1277. break;
  1278. case FSF_ADAPTER_STATUS_AVAILABLE:
  1279. break;
  1280. case FSF_GOOD:
  1281. zfcp_erp_clear_port_status(port, ZFCP_STATUS_COMMON_OPEN);
  1282. break;
  1283. }
  1284. }
  1285. /**
  1286. * zfcp_fsf_close_port - create and send close port request
  1287. * @erp_action: pointer to struct zfcp_erp_action
  1288. * Returns: 0 on success, error otherwise
  1289. */
  1290. int zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  1291. {
  1292. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1293. struct zfcp_fsf_req *req;
  1294. int retval = -EIO;
  1295. spin_lock_irq(&qdio->req_q_lock);
  1296. if (zfcp_qdio_sbal_get(qdio))
  1297. goto out;
  1298. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1299. SBAL_SFLAGS0_TYPE_READ,
  1300. qdio->adapter->pool.erp_req);
  1301. if (IS_ERR(req)) {
  1302. retval = PTR_ERR(req);
  1303. goto out;
  1304. }
  1305. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1306. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1307. req->handler = zfcp_fsf_close_port_handler;
  1308. req->data = erp_action->port;
  1309. req->erp_action = erp_action;
  1310. req->qtcb->header.port_handle = erp_action->port->handle;
  1311. erp_action->fsf_req_id = req->req_id;
  1312. zfcp_fsf_start_erp_timer(req);
  1313. retval = zfcp_fsf_req_send(req);
  1314. if (retval) {
  1315. zfcp_fsf_req_free(req);
  1316. erp_action->fsf_req_id = 0;
  1317. }
  1318. out:
  1319. spin_unlock_irq(&qdio->req_q_lock);
  1320. return retval;
  1321. }
  1322. static void zfcp_fsf_open_wka_port_handler(struct zfcp_fsf_req *req)
  1323. {
  1324. struct zfcp_fc_wka_port *wka_port = req->data;
  1325. struct fsf_qtcb_header *header = &req->qtcb->header;
  1326. if (req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1327. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1328. goto out;
  1329. }
  1330. switch (header->fsf_status) {
  1331. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  1332. dev_warn(&req->adapter->ccw_device->dev,
  1333. "Opening WKA port 0x%x failed\n", wka_port->d_id);
  1334. /* fall through */
  1335. case FSF_ADAPTER_STATUS_AVAILABLE:
  1336. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1337. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1338. break;
  1339. case FSF_GOOD:
  1340. wka_port->handle = header->port_handle;
  1341. /* fall through */
  1342. case FSF_PORT_ALREADY_OPEN:
  1343. wka_port->status = ZFCP_FC_WKA_PORT_ONLINE;
  1344. }
  1345. out:
  1346. wake_up(&wka_port->completion_wq);
  1347. }
  1348. /**
  1349. * zfcp_fsf_open_wka_port - create and send open wka-port request
  1350. * @wka_port: pointer to struct zfcp_fc_wka_port
  1351. * Returns: 0 on success, error otherwise
  1352. */
  1353. int zfcp_fsf_open_wka_port(struct zfcp_fc_wka_port *wka_port)
  1354. {
  1355. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1356. struct zfcp_fsf_req *req;
  1357. int retval = -EIO;
  1358. spin_lock_irq(&qdio->req_q_lock);
  1359. if (zfcp_qdio_sbal_get(qdio))
  1360. goto out;
  1361. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_PORT_WITH_DID,
  1362. SBAL_SFLAGS0_TYPE_READ,
  1363. qdio->adapter->pool.erp_req);
  1364. if (IS_ERR(req)) {
  1365. retval = PTR_ERR(req);
  1366. goto out;
  1367. }
  1368. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1369. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1370. req->handler = zfcp_fsf_open_wka_port_handler;
  1371. hton24(req->qtcb->bottom.support.d_id, wka_port->d_id);
  1372. req->data = wka_port;
  1373. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1374. retval = zfcp_fsf_req_send(req);
  1375. if (retval)
  1376. zfcp_fsf_req_free(req);
  1377. out:
  1378. spin_unlock_irq(&qdio->req_q_lock);
  1379. return retval;
  1380. }
  1381. static void zfcp_fsf_close_wka_port_handler(struct zfcp_fsf_req *req)
  1382. {
  1383. struct zfcp_fc_wka_port *wka_port = req->data;
  1384. if (req->qtcb->header.fsf_status == FSF_PORT_HANDLE_NOT_VALID) {
  1385. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1386. zfcp_erp_adapter_reopen(wka_port->adapter, 0, "fscwph1");
  1387. }
  1388. wka_port->status = ZFCP_FC_WKA_PORT_OFFLINE;
  1389. wake_up(&wka_port->completion_wq);
  1390. }
  1391. /**
  1392. * zfcp_fsf_close_wka_port - create and send close wka port request
  1393. * @wka_port: WKA port to open
  1394. * Returns: 0 on success, error otherwise
  1395. */
  1396. int zfcp_fsf_close_wka_port(struct zfcp_fc_wka_port *wka_port)
  1397. {
  1398. struct zfcp_qdio *qdio = wka_port->adapter->qdio;
  1399. struct zfcp_fsf_req *req;
  1400. int retval = -EIO;
  1401. spin_lock_irq(&qdio->req_q_lock);
  1402. if (zfcp_qdio_sbal_get(qdio))
  1403. goto out;
  1404. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PORT,
  1405. SBAL_SFLAGS0_TYPE_READ,
  1406. qdio->adapter->pool.erp_req);
  1407. if (IS_ERR(req)) {
  1408. retval = PTR_ERR(req);
  1409. goto out;
  1410. }
  1411. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1412. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1413. req->handler = zfcp_fsf_close_wka_port_handler;
  1414. req->data = wka_port;
  1415. req->qtcb->header.port_handle = wka_port->handle;
  1416. zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT);
  1417. retval = zfcp_fsf_req_send(req);
  1418. if (retval)
  1419. zfcp_fsf_req_free(req);
  1420. out:
  1421. spin_unlock_irq(&qdio->req_q_lock);
  1422. return retval;
  1423. }
  1424. static void zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *req)
  1425. {
  1426. struct zfcp_port *port = req->data;
  1427. struct fsf_qtcb_header *header = &req->qtcb->header;
  1428. struct scsi_device *sdev;
  1429. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1430. return;
  1431. switch (header->fsf_status) {
  1432. case FSF_PORT_HANDLE_NOT_VALID:
  1433. zfcp_erp_adapter_reopen(port->adapter, 0, "fscpph1");
  1434. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1435. break;
  1436. case FSF_PORT_BOXED:
  1437. /* can't use generic zfcp_erp_modify_port_status because
  1438. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  1439. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1440. shost_for_each_device(sdev, port->adapter->scsi_host)
  1441. if (sdev_to_zfcp(sdev)->port == port)
  1442. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1443. &sdev_to_zfcp(sdev)->status);
  1444. zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1445. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED,
  1446. "fscpph2");
  1447. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1448. break;
  1449. case FSF_ADAPTER_STATUS_AVAILABLE:
  1450. switch (header->fsf_status_qual.word[0]) {
  1451. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1452. /* fall through */
  1453. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1454. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1455. break;
  1456. }
  1457. break;
  1458. case FSF_GOOD:
  1459. /* can't use generic zfcp_erp_modify_port_status because
  1460. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  1461. */
  1462. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  1463. shost_for_each_device(sdev, port->adapter->scsi_host)
  1464. if (sdev_to_zfcp(sdev)->port == port)
  1465. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1466. &sdev_to_zfcp(sdev)->status);
  1467. break;
  1468. }
  1469. }
  1470. /**
  1471. * zfcp_fsf_close_physical_port - close physical port
  1472. * @erp_action: pointer to struct zfcp_erp_action
  1473. * Returns: 0 on success
  1474. */
  1475. int zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  1476. {
  1477. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1478. struct zfcp_fsf_req *req;
  1479. int retval = -EIO;
  1480. spin_lock_irq(&qdio->req_q_lock);
  1481. if (zfcp_qdio_sbal_get(qdio))
  1482. goto out;
  1483. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_PHYSICAL_PORT,
  1484. SBAL_SFLAGS0_TYPE_READ,
  1485. qdio->adapter->pool.erp_req);
  1486. if (IS_ERR(req)) {
  1487. retval = PTR_ERR(req);
  1488. goto out;
  1489. }
  1490. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1491. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1492. req->data = erp_action->port;
  1493. req->qtcb->header.port_handle = erp_action->port->handle;
  1494. req->erp_action = erp_action;
  1495. req->handler = zfcp_fsf_close_physical_port_handler;
  1496. erp_action->fsf_req_id = req->req_id;
  1497. zfcp_fsf_start_erp_timer(req);
  1498. retval = zfcp_fsf_req_send(req);
  1499. if (retval) {
  1500. zfcp_fsf_req_free(req);
  1501. erp_action->fsf_req_id = 0;
  1502. }
  1503. out:
  1504. spin_unlock_irq(&qdio->req_q_lock);
  1505. return retval;
  1506. }
  1507. static void zfcp_fsf_open_lun_handler(struct zfcp_fsf_req *req)
  1508. {
  1509. struct zfcp_adapter *adapter = req->adapter;
  1510. struct scsi_device *sdev = req->data;
  1511. struct zfcp_scsi_dev *zfcp_sdev;
  1512. struct fsf_qtcb_header *header = &req->qtcb->header;
  1513. union fsf_status_qual *qual = &header->fsf_status_qual;
  1514. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1515. return;
  1516. zfcp_sdev = sdev_to_zfcp(sdev);
  1517. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  1518. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  1519. &zfcp_sdev->status);
  1520. switch (header->fsf_status) {
  1521. case FSF_PORT_HANDLE_NOT_VALID:
  1522. zfcp_erp_adapter_reopen(adapter, 0, "fsouh_1");
  1523. /* fall through */
  1524. case FSF_LUN_ALREADY_OPEN:
  1525. break;
  1526. case FSF_PORT_BOXED:
  1527. zfcp_erp_set_port_status(zfcp_sdev->port,
  1528. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1529. zfcp_erp_port_reopen(zfcp_sdev->port,
  1530. ZFCP_STATUS_COMMON_ERP_FAILED, "fsouh_2");
  1531. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1532. break;
  1533. case FSF_LUN_SHARING_VIOLATION:
  1534. if (qual->word[0])
  1535. dev_warn(&zfcp_sdev->port->adapter->ccw_device->dev,
  1536. "LUN 0x%Lx on port 0x%Lx is already in "
  1537. "use by CSS%d, MIF Image ID %x\n",
  1538. zfcp_scsi_dev_lun(sdev),
  1539. (unsigned long long)zfcp_sdev->port->wwpn,
  1540. qual->fsf_queue_designator.cssid,
  1541. qual->fsf_queue_designator.hla);
  1542. zfcp_erp_set_lun_status(sdev,
  1543. ZFCP_STATUS_COMMON_ERP_FAILED |
  1544. ZFCP_STATUS_COMMON_ACCESS_DENIED);
  1545. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1546. break;
  1547. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  1548. dev_warn(&adapter->ccw_device->dev,
  1549. "No handle is available for LUN "
  1550. "0x%016Lx on port 0x%016Lx\n",
  1551. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1552. (unsigned long long)zfcp_sdev->port->wwpn);
  1553. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ERP_FAILED);
  1554. /* fall through */
  1555. case FSF_INVALID_COMMAND_OPTION:
  1556. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1557. break;
  1558. case FSF_ADAPTER_STATUS_AVAILABLE:
  1559. switch (header->fsf_status_qual.word[0]) {
  1560. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1561. zfcp_fc_test_link(zfcp_sdev->port);
  1562. /* fall through */
  1563. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1564. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1565. break;
  1566. }
  1567. break;
  1568. case FSF_GOOD:
  1569. zfcp_sdev->lun_handle = header->lun_handle;
  1570. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1571. break;
  1572. }
  1573. }
  1574. /**
  1575. * zfcp_fsf_open_lun - open LUN
  1576. * @erp_action: pointer to struct zfcp_erp_action
  1577. * Returns: 0 on success, error otherwise
  1578. */
  1579. int zfcp_fsf_open_lun(struct zfcp_erp_action *erp_action)
  1580. {
  1581. struct zfcp_adapter *adapter = erp_action->adapter;
  1582. struct zfcp_qdio *qdio = adapter->qdio;
  1583. struct zfcp_fsf_req *req;
  1584. int retval = -EIO;
  1585. spin_lock_irq(&qdio->req_q_lock);
  1586. if (zfcp_qdio_sbal_get(qdio))
  1587. goto out;
  1588. req = zfcp_fsf_req_create(qdio, FSF_QTCB_OPEN_LUN,
  1589. SBAL_SFLAGS0_TYPE_READ,
  1590. adapter->pool.erp_req);
  1591. if (IS_ERR(req)) {
  1592. retval = PTR_ERR(req);
  1593. goto out;
  1594. }
  1595. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1596. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1597. req->qtcb->header.port_handle = erp_action->port->handle;
  1598. req->qtcb->bottom.support.fcp_lun = zfcp_scsi_dev_lun(erp_action->sdev);
  1599. req->handler = zfcp_fsf_open_lun_handler;
  1600. req->data = erp_action->sdev;
  1601. req->erp_action = erp_action;
  1602. erp_action->fsf_req_id = req->req_id;
  1603. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  1604. req->qtcb->bottom.support.option = FSF_OPEN_LUN_SUPPRESS_BOXING;
  1605. zfcp_fsf_start_erp_timer(req);
  1606. retval = zfcp_fsf_req_send(req);
  1607. if (retval) {
  1608. zfcp_fsf_req_free(req);
  1609. erp_action->fsf_req_id = 0;
  1610. }
  1611. out:
  1612. spin_unlock_irq(&qdio->req_q_lock);
  1613. return retval;
  1614. }
  1615. static void zfcp_fsf_close_lun_handler(struct zfcp_fsf_req *req)
  1616. {
  1617. struct scsi_device *sdev = req->data;
  1618. struct zfcp_scsi_dev *zfcp_sdev;
  1619. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1620. return;
  1621. zfcp_sdev = sdev_to_zfcp(sdev);
  1622. switch (req->qtcb->header.fsf_status) {
  1623. case FSF_PORT_HANDLE_NOT_VALID:
  1624. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fscuh_1");
  1625. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1626. break;
  1627. case FSF_LUN_HANDLE_NOT_VALID:
  1628. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fscuh_2");
  1629. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1630. break;
  1631. case FSF_PORT_BOXED:
  1632. zfcp_erp_set_port_status(zfcp_sdev->port,
  1633. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1634. zfcp_erp_port_reopen(zfcp_sdev->port,
  1635. ZFCP_STATUS_COMMON_ERP_FAILED, "fscuh_3");
  1636. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1637. break;
  1638. case FSF_ADAPTER_STATUS_AVAILABLE:
  1639. switch (req->qtcb->header.fsf_status_qual.word[0]) {
  1640. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1641. zfcp_fc_test_link(zfcp_sdev->port);
  1642. /* fall through */
  1643. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1644. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1645. break;
  1646. }
  1647. break;
  1648. case FSF_GOOD:
  1649. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &zfcp_sdev->status);
  1650. break;
  1651. }
  1652. }
  1653. /**
  1654. * zfcp_fsf_close_LUN - close LUN
  1655. * @erp_action: pointer to erp_action triggering the "close LUN"
  1656. * Returns: 0 on success, error otherwise
  1657. */
  1658. int zfcp_fsf_close_lun(struct zfcp_erp_action *erp_action)
  1659. {
  1660. struct zfcp_qdio *qdio = erp_action->adapter->qdio;
  1661. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(erp_action->sdev);
  1662. struct zfcp_fsf_req *req;
  1663. int retval = -EIO;
  1664. spin_lock_irq(&qdio->req_q_lock);
  1665. if (zfcp_qdio_sbal_get(qdio))
  1666. goto out;
  1667. req = zfcp_fsf_req_create(qdio, FSF_QTCB_CLOSE_LUN,
  1668. SBAL_SFLAGS0_TYPE_READ,
  1669. qdio->adapter->pool.erp_req);
  1670. if (IS_ERR(req)) {
  1671. retval = PTR_ERR(req);
  1672. goto out;
  1673. }
  1674. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1675. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  1676. req->qtcb->header.port_handle = erp_action->port->handle;
  1677. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1678. req->handler = zfcp_fsf_close_lun_handler;
  1679. req->data = erp_action->sdev;
  1680. req->erp_action = erp_action;
  1681. erp_action->fsf_req_id = req->req_id;
  1682. zfcp_fsf_start_erp_timer(req);
  1683. retval = zfcp_fsf_req_send(req);
  1684. if (retval) {
  1685. zfcp_fsf_req_free(req);
  1686. erp_action->fsf_req_id = 0;
  1687. }
  1688. out:
  1689. spin_unlock_irq(&qdio->req_q_lock);
  1690. return retval;
  1691. }
  1692. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  1693. {
  1694. lat_rec->sum += lat;
  1695. lat_rec->min = min(lat_rec->min, lat);
  1696. lat_rec->max = max(lat_rec->max, lat);
  1697. }
  1698. static void zfcp_fsf_req_trace(struct zfcp_fsf_req *req, struct scsi_cmnd *scsi)
  1699. {
  1700. struct fsf_qual_latency_info *lat_in;
  1701. struct latency_cont *lat = NULL;
  1702. struct zfcp_scsi_dev *zfcp_sdev;
  1703. struct zfcp_blk_drv_data blktrc;
  1704. int ticks = req->adapter->timer_ticks;
  1705. lat_in = &req->qtcb->prefix.prot_status_qual.latency_info;
  1706. blktrc.flags = 0;
  1707. blktrc.magic = ZFCP_BLK_DRV_DATA_MAGIC;
  1708. if (req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1709. blktrc.flags |= ZFCP_BLK_REQ_ERROR;
  1710. blktrc.inb_usage = 0;
  1711. blktrc.outb_usage = req->qdio_req.qdio_outb_usage;
  1712. if (req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA &&
  1713. !(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1714. zfcp_sdev = sdev_to_zfcp(scsi->device);
  1715. blktrc.flags |= ZFCP_BLK_LAT_VALID;
  1716. blktrc.channel_lat = lat_in->channel_lat * ticks;
  1717. blktrc.fabric_lat = lat_in->fabric_lat * ticks;
  1718. switch (req->qtcb->bottom.io.data_direction) {
  1719. case FSF_DATADIR_DIF_READ_STRIP:
  1720. case FSF_DATADIR_DIF_READ_CONVERT:
  1721. case FSF_DATADIR_READ:
  1722. lat = &zfcp_sdev->latencies.read;
  1723. break;
  1724. case FSF_DATADIR_DIF_WRITE_INSERT:
  1725. case FSF_DATADIR_DIF_WRITE_CONVERT:
  1726. case FSF_DATADIR_WRITE:
  1727. lat = &zfcp_sdev->latencies.write;
  1728. break;
  1729. case FSF_DATADIR_CMND:
  1730. lat = &zfcp_sdev->latencies.cmd;
  1731. break;
  1732. }
  1733. if (lat) {
  1734. spin_lock(&zfcp_sdev->latencies.lock);
  1735. zfcp_fsf_update_lat(&lat->channel, lat_in->channel_lat);
  1736. zfcp_fsf_update_lat(&lat->fabric, lat_in->fabric_lat);
  1737. lat->counter++;
  1738. spin_unlock(&zfcp_sdev->latencies.lock);
  1739. }
  1740. }
  1741. blk_add_driver_data(scsi->request->q, scsi->request, &blktrc,
  1742. sizeof(blktrc));
  1743. }
  1744. static void zfcp_fsf_fcp_handler_common(struct zfcp_fsf_req *req)
  1745. {
  1746. struct scsi_cmnd *scmnd = req->data;
  1747. struct scsi_device *sdev = scmnd->device;
  1748. struct zfcp_scsi_dev *zfcp_sdev;
  1749. struct fsf_qtcb_header *header = &req->qtcb->header;
  1750. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1751. return;
  1752. zfcp_sdev = sdev_to_zfcp(sdev);
  1753. switch (header->fsf_status) {
  1754. case FSF_HANDLE_MISMATCH:
  1755. case FSF_PORT_HANDLE_NOT_VALID:
  1756. zfcp_erp_adapter_reopen(zfcp_sdev->port->adapter, 0, "fssfch1");
  1757. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1758. break;
  1759. case FSF_FCPLUN_NOT_VALID:
  1760. case FSF_LUN_HANDLE_NOT_VALID:
  1761. zfcp_erp_port_reopen(zfcp_sdev->port, 0, "fssfch2");
  1762. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1763. break;
  1764. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1765. zfcp_fsf_class_not_supp(req);
  1766. break;
  1767. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  1768. dev_err(&req->adapter->ccw_device->dev,
  1769. "Incorrect direction %d, LUN 0x%016Lx on port "
  1770. "0x%016Lx closed\n",
  1771. req->qtcb->bottom.io.data_direction,
  1772. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1773. (unsigned long long)zfcp_sdev->port->wwpn);
  1774. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1775. "fssfch3");
  1776. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1777. break;
  1778. case FSF_CMND_LENGTH_NOT_VALID:
  1779. dev_err(&req->adapter->ccw_device->dev,
  1780. "Incorrect CDB length %d, LUN 0x%016Lx on "
  1781. "port 0x%016Lx closed\n",
  1782. req->qtcb->bottom.io.fcp_cmnd_length,
  1783. (unsigned long long)zfcp_scsi_dev_lun(sdev),
  1784. (unsigned long long)zfcp_sdev->port->wwpn);
  1785. zfcp_erp_adapter_shutdown(zfcp_sdev->port->adapter, 0,
  1786. "fssfch4");
  1787. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1788. break;
  1789. case FSF_PORT_BOXED:
  1790. zfcp_erp_set_port_status(zfcp_sdev->port,
  1791. ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1792. zfcp_erp_port_reopen(zfcp_sdev->port,
  1793. ZFCP_STATUS_COMMON_ERP_FAILED, "fssfch5");
  1794. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1795. break;
  1796. case FSF_LUN_BOXED:
  1797. zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_ACCESS_BOXED);
  1798. zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
  1799. "fssfch6");
  1800. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1801. break;
  1802. case FSF_ADAPTER_STATUS_AVAILABLE:
  1803. if (header->fsf_status_qual.word[0] ==
  1804. FSF_SQ_INVOKE_LINK_TEST_PROCEDURE)
  1805. zfcp_fc_test_link(zfcp_sdev->port);
  1806. req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1807. break;
  1808. }
  1809. }
  1810. static void zfcp_fsf_fcp_cmnd_handler(struct zfcp_fsf_req *req)
  1811. {
  1812. struct scsi_cmnd *scpnt;
  1813. struct fcp_resp_with_ext *fcp_rsp;
  1814. unsigned long flags;
  1815. read_lock_irqsave(&req->adapter->abort_lock, flags);
  1816. scpnt = req->data;
  1817. if (unlikely(!scpnt)) {
  1818. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1819. return;
  1820. }
  1821. zfcp_fsf_fcp_handler_common(req);
  1822. if (unlikely(req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  1823. set_host_byte(scpnt, DID_TRANSPORT_DISRUPTED);
  1824. goto skip_fsfstatus;
  1825. }
  1826. switch (req->qtcb->header.fsf_status) {
  1827. case FSF_INCONSISTENT_PROT_DATA:
  1828. case FSF_INVALID_PROT_PARM:
  1829. set_host_byte(scpnt, DID_ERROR);
  1830. goto skip_fsfstatus;
  1831. case FSF_BLOCK_GUARD_CHECK_FAILURE:
  1832. zfcp_scsi_dif_sense_error(scpnt, 0x1);
  1833. goto skip_fsfstatus;
  1834. case FSF_APP_TAG_CHECK_FAILURE:
  1835. zfcp_scsi_dif_sense_error(scpnt, 0x2);
  1836. goto skip_fsfstatus;
  1837. case FSF_REF_TAG_CHECK_FAILURE:
  1838. zfcp_scsi_dif_sense_error(scpnt, 0x3);
  1839. goto skip_fsfstatus;
  1840. }
  1841. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1842. zfcp_fc_eval_fcp_rsp(fcp_rsp, scpnt);
  1843. skip_fsfstatus:
  1844. zfcp_fsf_req_trace(req, scpnt);
  1845. zfcp_dbf_scsi_result(scpnt, req);
  1846. scpnt->host_scribble = NULL;
  1847. (scpnt->scsi_done) (scpnt);
  1848. /*
  1849. * We must hold this lock until scsi_done has been called.
  1850. * Otherwise we may call scsi_done after abort regarding this
  1851. * command has completed.
  1852. * Note: scsi_done must not block!
  1853. */
  1854. read_unlock_irqrestore(&req->adapter->abort_lock, flags);
  1855. }
  1856. static int zfcp_fsf_set_data_dir(struct scsi_cmnd *scsi_cmnd, u32 *data_dir)
  1857. {
  1858. switch (scsi_get_prot_op(scsi_cmnd)) {
  1859. case SCSI_PROT_NORMAL:
  1860. switch (scsi_cmnd->sc_data_direction) {
  1861. case DMA_NONE:
  1862. *data_dir = FSF_DATADIR_CMND;
  1863. break;
  1864. case DMA_FROM_DEVICE:
  1865. *data_dir = FSF_DATADIR_READ;
  1866. break;
  1867. case DMA_TO_DEVICE:
  1868. *data_dir = FSF_DATADIR_WRITE;
  1869. break;
  1870. case DMA_BIDIRECTIONAL:
  1871. return -EINVAL;
  1872. }
  1873. break;
  1874. case SCSI_PROT_READ_STRIP:
  1875. *data_dir = FSF_DATADIR_DIF_READ_STRIP;
  1876. break;
  1877. case SCSI_PROT_WRITE_INSERT:
  1878. *data_dir = FSF_DATADIR_DIF_WRITE_INSERT;
  1879. break;
  1880. case SCSI_PROT_READ_PASS:
  1881. *data_dir = FSF_DATADIR_DIF_READ_CONVERT;
  1882. break;
  1883. case SCSI_PROT_WRITE_PASS:
  1884. *data_dir = FSF_DATADIR_DIF_WRITE_CONVERT;
  1885. break;
  1886. default:
  1887. return -EINVAL;
  1888. }
  1889. return 0;
  1890. }
  1891. /**
  1892. * zfcp_fsf_fcp_cmnd - initiate an FCP command (for a SCSI command)
  1893. * @scsi_cmnd: scsi command to be sent
  1894. */
  1895. int zfcp_fsf_fcp_cmnd(struct scsi_cmnd *scsi_cmnd)
  1896. {
  1897. struct zfcp_fsf_req *req;
  1898. struct fcp_cmnd *fcp_cmnd;
  1899. u8 sbtype = SBAL_SFLAGS0_TYPE_READ;
  1900. int retval = -EIO;
  1901. struct scsi_device *sdev = scsi_cmnd->device;
  1902. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev);
  1903. struct zfcp_adapter *adapter = zfcp_sdev->port->adapter;
  1904. struct zfcp_qdio *qdio = adapter->qdio;
  1905. struct fsf_qtcb_bottom_io *io;
  1906. unsigned long flags;
  1907. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1908. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1909. return -EBUSY;
  1910. spin_lock_irqsave(&qdio->req_q_lock, flags);
  1911. if (atomic_read(&qdio->req_q_free) <= 0) {
  1912. atomic_inc(&qdio->req_q_full);
  1913. goto out;
  1914. }
  1915. if (scsi_cmnd->sc_data_direction == DMA_TO_DEVICE)
  1916. sbtype = SBAL_SFLAGS0_TYPE_WRITE;
  1917. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1918. sbtype, adapter->pool.scsi_req);
  1919. if (IS_ERR(req)) {
  1920. retval = PTR_ERR(req);
  1921. goto out;
  1922. }
  1923. scsi_cmnd->host_scribble = (unsigned char *) req->req_id;
  1924. io = &req->qtcb->bottom.io;
  1925. req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  1926. req->data = scsi_cmnd;
  1927. req->handler = zfcp_fsf_fcp_cmnd_handler;
  1928. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  1929. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  1930. io->service_class = FSF_CLASS_3;
  1931. io->fcp_cmnd_length = FCP_CMND_LEN;
  1932. if (scsi_get_prot_op(scsi_cmnd) != SCSI_PROT_NORMAL) {
  1933. io->data_block_length = scsi_cmnd->device->sector_size;
  1934. io->ref_tag_value = scsi_get_lba(scsi_cmnd) & 0xFFFFFFFF;
  1935. }
  1936. if (zfcp_fsf_set_data_dir(scsi_cmnd, &io->data_direction))
  1937. goto failed_scsi_cmnd;
  1938. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  1939. zfcp_fc_scsi_to_fcp(fcp_cmnd, scsi_cmnd, 0);
  1940. if (scsi_prot_sg_count(scsi_cmnd)) {
  1941. zfcp_qdio_set_data_div(qdio, &req->qdio_req,
  1942. scsi_prot_sg_count(scsi_cmnd));
  1943. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1944. scsi_prot_sglist(scsi_cmnd));
  1945. if (retval)
  1946. goto failed_scsi_cmnd;
  1947. io->prot_data_length = zfcp_qdio_real_bytes(
  1948. scsi_prot_sglist(scsi_cmnd));
  1949. }
  1950. retval = zfcp_qdio_sbals_from_sg(qdio, &req->qdio_req,
  1951. scsi_sglist(scsi_cmnd));
  1952. if (unlikely(retval))
  1953. goto failed_scsi_cmnd;
  1954. zfcp_qdio_set_sbale_last(adapter->qdio, &req->qdio_req);
  1955. if (zfcp_adapter_multi_buffer_active(adapter))
  1956. zfcp_qdio_set_scount(qdio, &req->qdio_req);
  1957. retval = zfcp_fsf_req_send(req);
  1958. if (unlikely(retval))
  1959. goto failed_scsi_cmnd;
  1960. goto out;
  1961. failed_scsi_cmnd:
  1962. zfcp_fsf_req_free(req);
  1963. scsi_cmnd->host_scribble = NULL;
  1964. out:
  1965. spin_unlock_irqrestore(&qdio->req_q_lock, flags);
  1966. return retval;
  1967. }
  1968. static void zfcp_fsf_fcp_task_mgmt_handler(struct zfcp_fsf_req *req)
  1969. {
  1970. struct fcp_resp_with_ext *fcp_rsp;
  1971. struct fcp_resp_rsp_info *rsp_info;
  1972. zfcp_fsf_fcp_handler_common(req);
  1973. fcp_rsp = (struct fcp_resp_with_ext *) &req->qtcb->bottom.io.fcp_rsp;
  1974. rsp_info = (struct fcp_resp_rsp_info *) &fcp_rsp[1];
  1975. if ((rsp_info->rsp_code != FCP_TMF_CMPL) ||
  1976. (req->status & ZFCP_STATUS_FSFREQ_ERROR))
  1977. req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  1978. }
  1979. /**
  1980. * zfcp_fsf_fcp_task_mgmt - send SCSI task management command
  1981. * @scmnd: SCSI command to send the task management command for
  1982. * @tm_flags: unsigned byte for task management flags
  1983. * Returns: on success pointer to struct fsf_req, NULL otherwise
  1984. */
  1985. struct zfcp_fsf_req *zfcp_fsf_fcp_task_mgmt(struct scsi_cmnd *scmnd,
  1986. u8 tm_flags)
  1987. {
  1988. struct zfcp_fsf_req *req = NULL;
  1989. struct fcp_cmnd *fcp_cmnd;
  1990. struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(scmnd->device);
  1991. struct zfcp_qdio *qdio = zfcp_sdev->port->adapter->qdio;
  1992. if (unlikely(!(atomic_read(&zfcp_sdev->status) &
  1993. ZFCP_STATUS_COMMON_UNBLOCKED)))
  1994. return NULL;
  1995. spin_lock_irq(&qdio->req_q_lock);
  1996. if (zfcp_qdio_sbal_get(qdio))
  1997. goto out;
  1998. req = zfcp_fsf_req_create(qdio, FSF_QTCB_FCP_CMND,
  1999. SBAL_SFLAGS0_TYPE_WRITE,
  2000. qdio->adapter->pool.scsi_req);
  2001. if (IS_ERR(req)) {
  2002. req = NULL;
  2003. goto out;
  2004. }
  2005. req->data = scmnd;
  2006. req->handler = zfcp_fsf_fcp_task_mgmt_handler;
  2007. req->qtcb->header.lun_handle = zfcp_sdev->lun_handle;
  2008. req->qtcb->header.port_handle = zfcp_sdev->port->handle;
  2009. req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  2010. req->qtcb->bottom.io.service_class = FSF_CLASS_3;
  2011. req->qtcb->bottom.io.fcp_cmnd_length = FCP_CMND_LEN;
  2012. zfcp_qdio_set_sbale_last(qdio, &req->qdio_req);
  2013. fcp_cmnd = (struct fcp_cmnd *) &req->qtcb->bottom.io.fcp_cmnd;
  2014. zfcp_fc_scsi_to_fcp(fcp_cmnd, scmnd, tm_flags);
  2015. zfcp_fsf_start_timer(req, ZFCP_SCSI_ER_TIMEOUT);
  2016. if (!zfcp_fsf_req_send(req))
  2017. goto out;
  2018. zfcp_fsf_req_free(req);
  2019. req = NULL;
  2020. out:
  2021. spin_unlock_irq(&qdio->req_q_lock);
  2022. return req;
  2023. }
  2024. /**
  2025. * zfcp_fsf_reqid_check - validate req_id contained in SBAL returned by QDIO
  2026. * @adapter: pointer to struct zfcp_adapter
  2027. * @sbal_idx: response queue index of SBAL to be processed
  2028. */
  2029. void zfcp_fsf_reqid_check(struct zfcp_qdio *qdio, int sbal_idx)
  2030. {
  2031. struct zfcp_adapter *adapter = qdio->adapter;
  2032. struct qdio_buffer *sbal = qdio->res_q[sbal_idx];
  2033. struct qdio_buffer_element *sbale;
  2034. struct zfcp_fsf_req *fsf_req;
  2035. unsigned long req_id;
  2036. int idx;
  2037. for (idx = 0; idx < QDIO_MAX_ELEMENTS_PER_BUFFER; idx++) {
  2038. sbale = &sbal->element[idx];
  2039. req_id = (unsigned long) sbale->addr;
  2040. fsf_req = zfcp_reqlist_find_rm(adapter->req_list, req_id);
  2041. if (!fsf_req) {
  2042. /*
  2043. * Unknown request means that we have potentially memory
  2044. * corruption and must stop the machine immediately.
  2045. */
  2046. zfcp_qdio_siosl(adapter);
  2047. panic("error: unknown req_id (%lx) on adapter %s.\n",
  2048. req_id, dev_name(&adapter->ccw_device->dev));
  2049. }
  2050. fsf_req->qdio_req.sbal_response = sbal_idx;
  2051. zfcp_fsf_req_complete(fsf_req);
  2052. if (likely(sbale->eflags & SBAL_EFLAGS_LAST_ENTRY))
  2053. break;
  2054. }
  2055. }