zfcp_fsf.c 70 KB

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